Exemplo n.º 1
0
 public function testDoChangeDateUpdate()
 {
     $date = (new \DateTime())->modify('+100 seconds');
     $this->item->setDateUpdate($date);
     $this->item->doChangeDateUpdate();
     $this->assertInstanceOf('\\DateTime', $this->item->getDateUpdate());
     $this->assertNotEquals($date, $this->item->getDateUpdate());
 }
 /**
  * New items
  *
  * @param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function indexAction(Item $item, Request $request)
 {
     /* @var $response \Symfony\Component\HttpFoundation\Response */
     $response = $this->get('cache_time_keeper')->getResponse($item->getDateUpdate(), self::CACHE_LIFETIME);
     /* @var $widget \AnimeDb\Bundle\ShikimoriWidgetBundle\Service\Widget */
     $widget = $this->get('anime_db.shikimori.widget');
     // get shikimori item id
     if (!($item_id = $widget->getItemId($item))) {
         return $response;
     }
     $list = $this->get('anime_db.shikimori.browser')->get(str_replace('#ID#', $item_id, self::PATH_RELATED_ITEMS));
     $list = $this->filter($list);
     $response->setEtag($this->hash($list));
     // response was not modified for this request
     if ($response->isNotModified($request) || !$list) {
         return $response;
     }
     // build list item entities
     foreach ($list as $key => $item) {
         $list[$key] = $widget->getWidgetItem($widget->getItem($item['anime']['id']));
         // add relation
         if (substr($this->container->getParameter('locale'), 0, 2) == 'ru') {
             $list[$key]->setName($list[$key]->getName() . ' (' . $item['relation_russian'] . ')');
         } else {
             $list[$key]->setName($list[$key]->getName() . ' (' . $item['relation'] . ')');
         }
     }
     return $this->render('AnimeDbShikimoriRelatedItemsWidgetBundle:Widget:index.html.twig', ['items' => $list], $response);
 }
 /**
  * New items
  *
  * @param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function indexAction(Item $item, Request $request)
 {
     /* @var $response \Symfony\Component\HttpFoundation\Response */
     $response = $this->get('cache_time_keeper')->getResponse($item->getDateUpdate(), self::CACHE_LIFETIME);
     /* @var $widget \AnimeDb\Bundle\ShikimoriWidgetBundle\Service\Widget */
     $widget = $this->get('anime_db.shikimori.widget');
     // get shikimori item id
     if (!($item_id = $widget->getItemId($item))) {
         return $response;
     }
     $list = $this->get('anime_db.shikimori.browser')->get(str_replace('#ID#', $item_id, self::PATH_SIMILAR_ITEMS));
     // add Etag by list items
     $response->setEtag($widget->hash($list));
     // response was not modified for this request
     if ($response->isNotModified($request) || !$list) {
         return $response;
     }
     // build list item entities
     foreach ($list as $key => $item) {
         $list[$key] = $widget->getWidgetItem($widget->getItem($item['id']));
     }
     return $this->render('AnimeDbShikimoriSimilarItemsWidgetBundle:Widget:index.html.twig', ['items' => $list], $response);
 }
Exemplo n.º 4
0
 /**
  * @param Item $item
  * @param Request $request
  *
  * @return Response
  */
 public function showAction(Item $item, Request $request)
 {
     $date = [$item->getDateUpdate()];
     // use storage update date
     if ($item->getStorage() instanceof Storage) {
         $date[] = $item->getStorage()->getDateUpdate();
     }
     $response = $this->getCacheTimeKeeper()->getResponse($date);
     // response was not modified for this request
     if ($response->isNotModified($request)) {
         return $response;
     }
     return $this->render('AnimeDbCatalogBundle:Item:show.html.twig', ['item' => $item, 'widget_bottom' => self::WIDGET_PALCE_BOTTOM, 'widget_in_content' => self::WIDGET_PALCE_IN_CONTENT, 'widget_right' => self::WIDGET_PALCE_RIGHT], $response);
 }