Example #1
0
 /**
  * Fill item from source.
  *
  * @param array $data
  *
  * @return Item|null
  */
 public function fill(array $data)
 {
     if (empty($data['url']) || !is_string($data['url']) || strpos($data['url'], $this->browser->getHost()) !== 0 || !preg_match(self::REG_ITEM_ID, $data['url'], $match)) {
         return null;
     }
     $body = $this->browser->get('anime', ['aid' => $match['id']]);
     $item = new Item();
     $item->setEpisodesNumber($body->filter('episodecount')->text());
     $item->setDatePremiere(new \DateTime($body->filter('startdate')->text()));
     $item->setDateEnd(new \DateTime($body->filter('enddate')->text()));
     $item->setSummary($this->cleaner->clean($body->filter('description')->text()));
     // set main source
     $source = new Source();
     $source->setUrl($data['url']);
     $item->addSource($source);
     // add url to offsite
     $source = new Source();
     $source->setUrl($body->filter('url')->text());
     $item->addSource($source);
     // set complex data
     $this->setCover($item, $body, $match['id']);
     $this->setNames($item, $body);
     $this->setEpisodes($item, $body);
     $this->setType($item, $body);
     $this->setGenres($item, $body);
     return $item;
 }
 /**
  * @param Item $item
  * @param array $body
  *
  * @return Item
  */
 public function setSources(Item $item, $body)
 {
     $sources = ['ani_db_id' => self::ANI_DB_URL, 'world_art_id' => self::WORLD_ART_URL, 'myanimelist_id' => self::MY_ANIME_LIST_URL];
     foreach ($sources as $key => $url) {
         if (!empty($body[$key])) {
             $source = new Source();
             $source->setUrl(str_replace('#ID#', $body[$key], $url));
             $item->addSource($source);
         }
     }
     return $item;
 }
 /**
  * Refill item field from search result.
  *
  * @param Item $item
  * @param string $field
  * @param array $data
  *
  * @return Item
  */
 public function refillFromSearchResult(Item $item, $field, array $data)
 {
     if (!empty($data['url'])) {
         $source = new Source();
         $source->setUrl($data['url']);
         $item->addSource($source);
         $item = $this->refill($item, $field);
     }
     return $item;
 }
Example #4
0
 /**
  * @param Source $source
  *
  * @return Item
  */
 public function addSource(Source $source)
 {
     $sources = array_map('strval', $this->sources->toArray());
     if (!in_array($source->getUrl(), $sources)) {
         $this->sources->add($source);
         $source->setItem($this);
     }
     return $this;
 }