Пример #1
0
 /**
  * @param Item $item
  *
  * @return string
  */
 public function getSourceForFill(Item $item)
 {
     /* @var $source Source */
     foreach ($item->getSources() as $source) {
         if (strpos($source->getUrl(), $this->browser->getHost()) === 0) {
             return $source->getUrl();
         }
     }
     return '';
 }
Пример #2
0
 /**
  * Get source for fill
  *
  * @param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item
  *
  * @return string
  */
 public function getSourceForFill(Item $item)
 {
     /* @var $source \AnimeDb\Bundle\CatalogBundle\Entity\Source */
     foreach ($item->getSources() as $source) {
         if (strpos($source->getUrl(), $this->browser->getHost()) === 0) {
             return $source->getUrl();
         }
     }
     return '';
 }
 /**
  * Get MyAnimeList id for item
  *
  * @param ItemCatalog $entity
  * @param EntityManagerInterface $em
  *
  * @return int
  */
 protected function getId(ItemCatalog $entity, EntityManagerInterface $em)
 {
     // search in sources
     /* @var $source Source */
     foreach ($entity->getSources() as $source) {
         if (strpos($source->getUrl(), $this->host) === 0) {
             if (preg_match('#/(\\d+)/#', $source->getUrl(), $mat)) {
                 return $mat[1];
             }
             break;
         }
     }
     /* @var $rep ItemRepository */
     $rep = $em->getRepository('AnimeDbMyAnimeListSyncBundle:Item');
     // get MyAnimeList item link
     $mal_item = $rep->findByCatalogItem($entity);
     if ($mal_item instanceof ItemMal) {
         return $mal_item->getId();
     }
     return 0;
 }
Пример #4
0
 /**
  * Get form for field.
  *
  * @param string $field
  * @param Item $item_origin
  * @param Item $item_fill
  *
  * @return Form
  */
 protected function getForm($field, Item $item_origin, Item $item_fill)
 {
     switch ($field) {
         case RefillerInterface::FIELD_DATE_END:
             $form = new DateEndForm();
             $data = ['date_end' => $item_fill->getDateEnd()];
             break;
         case RefillerInterface::FIELD_DATE_PREMIERE:
             $form = new DatePremiereForm();
             $data = ['date_premiere' => $item_fill->getDatePremiere()];
             break;
         case RefillerInterface::FIELD_DURATION:
             $form = new DurationForm();
             $data = ['duration' => $item_fill->getDuration()];
             break;
         case RefillerInterface::FIELD_EPISODES:
             $form = new EpisodesForm();
             $data = ['episodes' => $item_fill->getEpisodes()];
             break;
         case RefillerInterface::FIELD_EPISODES_NUMBER:
             $form = new EpisodesNumberForm();
             $data = ['episodes_number' => $item_fill->getEpisodesNumber()];
             break;
         case RefillerInterface::FIELD_FILE_INFO:
             $form = new FileInfoForm();
             $data = ['file_info' => $item_fill->getFileInfo()];
             break;
         case RefillerInterface::FIELD_GENRES:
             $form = $this->get('anime_db.form.type.refill.gengres');
             $data = ['genres' => $item_fill->getGenres()];
             break;
         case RefillerInterface::FIELD_IMAGES:
             $form = new ImagesForm();
             $data = ['images' => $item_fill->getImages()];
             break;
         case RefillerInterface::FIELD_COUNTRY:
             $form = $this->get('anime_db.form.type.refill.country');
             $data = ['country' => $item_fill->getCountry()];
             break;
         case RefillerInterface::FIELD_NAMES:
             $form = new NamesForm();
             $data = ['names' => $item_fill->getNames()];
             break;
         case RefillerInterface::FIELD_SOURCES:
             $form = new SourcesForm();
             $data = ['sources' => $item_fill->getSources()];
             break;
         case RefillerInterface::FIELD_SUMMARY:
             $form = new SummaryForm();
             $data = ['summary' => $item_fill->getSummary()];
             break;
         case RefillerInterface::FIELD_TRANSLATE:
             $form = new TranslateForm();
             $data = ['translate' => $item_fill->getTranslate()];
             break;
         case RefillerInterface::FIELD_STUDIO:
             $form = $this->get('anime_db.form.type.refill.studio');
             $data = ['studio' => $item_fill->getStudio()];
             break;
         default:
             throw $this->createNotFoundException('Field \'' . $field . '\' is not supported');
     }
     // search new source link
     /* @var $sources_origin Source[] */
     $sources_origin = array_reverse($item_origin->getSources()->toArray());
     /* @var $sources_fill Source[] */
     $sources_fill = array_reverse($item_fill->getSources()->toArray());
     foreach ($sources_fill as $source_fill) {
         // sources is already added
         foreach ($sources_origin as $source_origin) {
             if ($source_fill->getUrl() == $source_origin->getUrl()) {
                 continue 2;
             }
         }
         $data['source'] = $source_fill->getUrl();
         break;
     }
     return $this->createForm($form, $data);
 }
Пример #5
0
 /**
  * Get Shikimori item id from sources
  *
  * @param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item
  *
  * @return integer
  */
 public function getItemId(Item $item)
 {
     /* @var $source \AnimeDb\Bundle\CatalogBundle\Entity\Source */
     foreach ($item->getSources() as $source) {
         if (strpos($source->getUrl(), $this->browser->getHost()) === 0 && preg_match(self::REG_ITEM_ID, $source->getUrl(), $match)) {
             return (int) $match['id'];
         }
     }
     return 0;
 }