public getLocation ( ) : eZ\Publish\API\Repository\Values\Content\Location | ||
return | eZ\Publish\API\Repository\Values\Content\Location |
/** * Displays the list of article. * * @param \Symfony\Component\HttpFoundation\Request $request request object * @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view * * @return \Symfony\Component\HttpFoundation\Response $location is flagged as invisible */ public function showFolderListAction(Request $request, ContentView $view) { $languages = $this->getConfigResolver()->getParameter('languages'); // Using the criteria helper (a demobundle custom service) to generate our query's criteria. // This is a good practice in order to have less code in your controller. $criteria = $this->get('ezdemo.criteria_helper')->generateListFolderCriterion($view->getLocation(), $this->container->getParameter('ezdemo.folder.folder_view.excluded_content_types'), $languages); // Generating query $query = new LocationQuery(); $query->query = $criteria; $query->sortClauses = array(new SortClause\DatePublished()); // Initialize pagination. $pager = new Pagerfanta(new ContentSearchAdapter($query, $this->getRepository()->getSearchService())); $pager->setMaxPerPage($this->container->getParameter('ezdemo.folder.folder_list.limit')); $pager->setCurrentPage($request->get('page', 1)); $includedContentTypeIdentifiers = $this->container->getParameter('ezdemo.folder.folder_tree.included_content_types'); // Get sub folder structure $subContentCriteria = $this->get('ezdemo.criteria_helper')->generateSubContentCriterion($view->getLocation(), $includedContentTypeIdentifiers, $languages); $subContentQuery = new LocationQuery(); $subContentQuery->query = $subContentCriteria; $subContentQuery->sortClauses = array(new SortClause\ContentName()); $searchService = $this->getRepository()->getSearchService(); $subContent = $searchService->findLocations($subContentQuery); $treeItems = array(); foreach ($subContent->searchHits as $hit) { $treeItems[] = $hit->valueObject; } $view->addParameters(['pagerFolder' => $pager, 'treeItems' => $treeItems]); return $view; }
/** * Displays the gallery. * * @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view * @param \Symfony\Component\HttpFoundation\Request $request * * @return \Symfony\Component\HttpFoundation\Response */ public function displayGalleryAction(ContentView $view, Request $request) { $languages = $this->configResolver->getParameter('languages'); $location = $view->getLocation(); $query = new Query(); $query->query = $this->childrenCriteria->generateChildCriterion($location, $languages); $pager = new Pagerfanta(new ContentSearchAdapter($query, $this->searchService)); $pager->setMaxPerPage($this->galleryImagesLimit); $pager->setCurrentPage($request->get('page', 1)); $view->addParameters(['location' => $location, 'content' => $this->contentService->loadContentByContentInfo($view->getLocation()->getContentInfo()), 'images' => $pager]); return $view; }
/** * @param ContentView $contentView * @param string $queryParameterValue * * @return mixed */ private function evaluateExpression(ContentView $contentView, $queryParameterValue) { if (substr($queryParameterValue, 0, 2) === '@=') { $language = new ExpressionLanguage(); return $language->evaluate(substr($queryParameterValue, 2), ['view' => $contentView, 'location' => $contentView->getLocation(), 'content' => $contentView->getContent()]); } else { return $queryParameterValue; } }
/** * Displays blog post content with random selected blog posts. * * @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view * * @return \eZ\Publish\Core\MVC\Symfony\View\ContentView */ public function showBlogPostAction(ContentView $view) { $languages = $this->configResolver->getParameter('languages'); $location = $this->locationService->loadLocation($view->getLocation()->parentLocationId); $query = new Query(); $query->query = $this->childrenCriteria->generateChildCriterion($location, $languages); $query->performCount = false; $query->sortClauses = [new SortClause\DatePublished(Query::SORT_DESC)]; $results = $this->searchService->findContent($query); $randomPosts = []; foreach ($results->searchHits as $item) { $randomPosts[] = $item->valueObject; } shuffle($randomPosts); $view->addParameters(['location' => $location, 'content' => $this->contentService->loadContentByContentInfo($view->getLocation()->getContentInfo()), 'randomPosts' => array_slice($randomPosts, 0, $this->randomPostsLimit, true)]); return $view; }
/** * Displays the feedback form, and processes posted data. * The signature of this method follows the one from the default view controller, and adds the Request, since * we use to handle form data. * * @param \Symfony\Component\HttpFoundation\Request $request * @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view * * @return View */ public function showFeedbackFormAction(Request $request, ContentView $view) { // Creating a form using Symfony's form component $feedback = new Feedback(); $form = $this->createForm($this->get('ezdemo.form.type.feedback'), $feedback); if ($request->isMethod('POST')) { $form->handleRequest($request); if ($form->isValid()) { /** @var EmailHelper $emailHelper */ $emailHelper = $this->get('ezdemo.email_helper'); $emailHelper->sendFeebackMessage($feedback, $this->container->getParameter('ezdemo.feedback_form.email_from'), $this->container->getParameter('ezdemo.feedback_form.email_to')); // Adding the confirmation flash message to the session $this->get('session')->getFlashBag()->add('notice', $this->get('translator')->trans('Thank you for your message, we will get back to you as soon as possible.')); return $this->redirect($this->generateUrl($view->getLocation())); } } $view->addParameters(['form' => $form->createView()]); return $view; }
/** * Displays the list of blog_post * Note: This is a fully customized controller action, it will generate the response and call * the view. Since it is not calling the ViewControler we don't need to match a specific * method signature. * * @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view * @param \Symfony\Component\HttpFoundation\Request $request * * @return \Symfony\Component\HttpFoundation\Response */ public function listBlogPostsAction(ContentView $view, Request $request) { $viewParameters = $request->attributes->get('viewParameters'); // This could be changed to use dynamic parameters injection $languages = $this->getConfigResolver()->getParameter('languages'); // Using the criteria helper (a demobundle custom service) to generate our query's criteria. // This is a good practice in order to have less code in your controller. $criteria = $this->get('ezdemo.criteria_helper')->generateListBlogPostCriterion($view->getLocation(), $viewParameters, $languages); // Generating query $query = new Query(); $query->query = $criteria; $query->sortClauses = array(new SortClause\Field('blog_post', 'publication_date', Query::SORT_DESC, $languages[0])); // Initialize pagination. $pager = new Pagerfanta(new ContentSearchAdapter($query, $this->getRepository()->getSearchService())); $pager->setMaxPerPage($this->container->getParameter('ezdemo.blog.blog_post_list.limit')); $pager->setCurrentPage($request->get('page', 1)); $view->addParameters(['pagerBlog' => $pager]); // The template identifier can be set from the controller action $view->setTemplateIdentifier('eZDemoBundle:full:blog.html.twig'); return $view; }
/** * Displays blog posts and gallery images on home page. * * @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view * * @return \eZ\Publish\Core\MVC\Symfony\View\ContentView */ public function showAction(ContentView $view) { $view->addParameters(['content' => $this->contentService->loadContentByContentInfo($view->getLocation()->getContentInfo()), 'blogPosts' => $this->fetchItems($this->blogLocationId, $this->blogPostLimit), 'galleryImages' => $this->fetchItems($this->galleryLocationId, $this->galleryImageLimit), 'galleryLocationId' => $this->galleryLocationId]); return $view; }