/** * @Method({"GET"}) * @Route( * "/stories/{page}", * name="stories", * host="{_locale}.{domain}", * defaults={"_locale" = "%locale%", "domain" = "%domain%", "page" = 1}, * requirements={"_locale" = "%locale%", "domain" = "%domain%", "page" = "\d+"} * ) * @Route( * "/stories/{page}", * name="stories_default", * host="{domain}", * defaults={"_locale" = "%locale%", "domain" = "%domain%", "page" = 1}, * requirements={"domain" = "%domain%", "page" = "\d+"} * ) */ public function storiesAction(Request $request, $page) { if ($request->query->has('sorting_parameter')) { $sortingParameter = $request->query->get('sorting_parameter'); if (!in_array($sortingParameter, Story::getSortingParameters(), TRUE)) { throw $this->createNotFoundException(); } } else { $sortingParameter = NULL; } if ($request->query->has('filter_parameter')) { $filterParameter = $request->query->get('filter_parameter'); if (!in_array($filterParameter, StoryCategory::getFilterParameters(), TRUE)) { throw $this->createNotFoundException(); } } else { $filterParameter = NULL; } $_manager = $this->getDoctrine()->getManager(); $storiesCategories = $_manager->getRepository('AppBundle:StoryCategory')->findAll(); if (!$storiesCategories) { throw $this->createNotFoundException(); } $_metadata = $this->get('app.metadata'); $results_per_page = 6; $pages_step = 10; $stories = $_manager->getRepository('AppBundle:Story')->findAllByPageSortedFiltered($page, $results_per_page, $sortingParameter, $filterParameter); $storiesReviews = $_manager->getRepository('AppBundle:Story')->findAllIndexedById(); $transform = function ($inputArray) { $outputArray = []; foreach ($inputArray as $key => $value) { if (count($value->getReviews())) { foreach ($value->getReviews() as $review) { $outputArray[$value->getId()][] = $review; } } else { $outputArray[$value->getId()] = NULL; } } return $outputArray; }; $storiesReviews = $transform($storiesReviews); $paginationBarSet = $this->get('app.pagination_bar')->setParameters(count($stories), $results_per_page, $page, $pages_step); if ($paginationBarSet) { $this->get('app.pagination_bar')->setPaginationBar(); } else { throw $this->createNotFoundException(); } $metadata = $_metadata->getCurrentMetadata(); if ($page > 1 || $sortingParameter || $filterParameter) { $metadata->setRobots('noindex, nofollow'); } // KLUDGE: set sorting and filter parameters $_session = $this->get('session'); $_session->set('page', $page); $_session->set('sorting_parameter', $sortingParameter); $_session->set('filter_parameter', $filterParameter); return $this->render('AppBundle:State:stories.html.twig', ['metadata' => $metadata, 'stories' => $stories, 'storiesReviews' => $storiesReviews, 'sortingParameter' => $sortingParameter, 'filterParameter' => $filterParameter, 'storiesCategories' => $storiesCategories]); }
/** * Add story * * @param \AppBundle\Entity\Story $story * @return StoryCategory */ public function addStory(\AppBundle\Entity\Story $story) { $story->addStoryCategory($this); $this->stories[] = $story; return $this; }