Exemplo n.º 1
0
 /**
  * @param FormBuilderInterface $builder
  * @param array $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     parent::buildForm($builder, $options);
     $builder->get('name')->setRequired(false);
     // get genres
     $list = $this->browser->get('/genres');
     $genres = [];
     while ($genre = array_shift($list)) {
         if ($this->locale == 'ru') {
             $genres[$genre['id']] = $genre['russian'];
         } else {
             $genres[$genre['id']] = $genre['name'];
         }
     }
     $builder->add('genre', 'choice', ['choices' => $genres, 'required' => false])->add('type', 'choice', ['choices' => array_combine($this->types, $this->types), 'required' => false])->add('season', 'text', ['required' => false, 'label' => 'Year of the premier', 'help' => 'You can select the period of the years indicated by a dash: 2002-2004']);
 }
Exemplo n.º 2
0
 /**
  * @param AddNewItem $event
  */
 public function onAddNewItem(AddNewItem $event)
 {
     $item = $event->getItem();
     if (!$event->getFillers()->contains($this->filler) && ($url = $this->refiller->getSourceForFill($item))) {
         // get data
         preg_match(Filler::REG_ITEM_ID, $url, $match);
         $path = str_replace('#ID#', $match['id'], Filler::FILL_URL);
         $body = $this->browser->get($path);
         // fill item
         if (!$item->getDateEnd() && $body['released_on']) {
             $item->setDateEnd(new \DateTime($body['released_on']));
         }
         if (!$item->getDatePremiere()) {
             $item->setDatePremiere(new \DateTime($body['aired_on']));
         }
         if (!$item->getDuration()) {
             $item->setDuration($body['duration']);
         }
         if (!$item->getEpisodesNumber()) {
             $ep_num = $body['episodes_aired'] ? $body['episodes_aired'] : $body['episodes'];
             $item->setEpisodesNumber($ep_num . ($body['ongoing'] ? '+' : ''));
         }
         if (!$item->getSummary()) {
             $item->setSummary($body['description']);
         }
         // set complex data
         if (!$item->getStudio()) {
             $this->filler->setStudio($item, $body);
         }
         if (!$item->getType()) {
             $this->filler->setType($item, $body);
         }
         if (!$item->getCover()) {
             $this->filler->setCover($item, $body);
         }
         $this->filler->setGenres($item, $body);
         $this->filler->setSources($item, $body);
         $this->filler->setNames($item, $body);
         $event->addFiller($this->filler);
         // resend event
         $this->dispatcher->dispatch(StoreEvents::ADD_NEW_ITEM, clone $event);
         $event->stopPropagation();
     }
 }
Exemplo n.º 3
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 '';
 }
Exemplo n.º 4
0
 /**
  * @param array $data
  *
  * @return ItemSearch[]
  */
 public function search(array $data)
 {
     $path = str_replace('#NAME#', urlencode($data['name']), self::SEARH_URL);
     $path = str_replace('#LIMIT#', self::DEFAULT_LIMIT, $path);
     $path = str_replace('#GENRE#', isset($data['genre']) ? $data['genre'] : '', $path);
     $path = str_replace('#TYPE#', isset($data['type']) ? $data['type'] : '', $path);
     $path = str_replace('#SEASON#', isset($data['season']) ? str_replace('-', '_', $data['season']) : '', $path);
     $body = (array) $this->browser->get($path);
     // build list
     foreach ($body as $key => $item) {
         // set a name based on the locale
         if ($this->locale == 'ru' && $item['russian']) {
             $name = $item['russian'];
             $description = $item['name'];
         } else {
             $name = $item['name'];
             $description = $item['russian'];
         }
         $body[$key] = new ItemSearch($name, $this->getLinkForFill($this->browser->getHost() . $item['url']), $this->browser->getHost() . $item['image']['original'], $description, $this->browser->getHost() . $item['url']);
     }
     return $body;
 }
Exemplo n.º 5
0
 /**
  * @param string $url
  *
  * @return bool
  */
 public function isSupportedUrl($url)
 {
     return strpos($url, $this->browser->getHost()) === 0;
 }
 public function testGet()
 {
     $data = ['test' => 123];
     $this->buildDialogue('baz', false, $data);
     $this->assertEquals($data, $this->browser->get('baz'));
 }
Exemplo n.º 7
0
 /**
  * Get item info by id
  *
  * @param integer $id
  *
  * @return array
  */
 public function getItem($id)
 {
     return $this->browser->get(str_replace('#ID#', $id, self::PATH_ITEM_INFO));
 }