diff --git a/Controller/DemoController.php b/Controller/DemoController.php index e4af5da..eb4e6b2 100644 --- a/Controller/DemoController.php +++ b/Controller/DemoController.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Controller; use eZ\Bundle\EzPublishCoreBundle\Controller; @@ -22,25 +21,25 @@ class DemoController extends Controller { /** - * Renders page header links with cache control + * Renders page header links with cache control. * * @return \Symfony\Component\HttpFoundation\Response */ public function userLinksAction() { $response = new Response(); - $response->setSharedMaxAge( 3600 ); - $response->setVary( 'Cookie' ); + $response->setSharedMaxAge(3600); + $response->setVary('Cookie'); return $this->render( - "eZDemoBundle::page_header_links.html.twig", + 'eZDemoBundle::page_header_links.html.twig', array(), $response ); } /** - * Renders article with extra parameters that controls page elements visibility such as image and summary + * Renders article with extra parameters that controls page elements visibility such as image and summary. * * @param $locationId * @param $viewType @@ -48,15 +47,15 @@ public function userLinksAction() * @param array $params * @return \Symfony\Component\HttpFoundation\Response */ - public function showArticleAction( $locationId, $viewType, $layout = false, array $params = array() ) + public function showArticleAction($locationId, $viewType, $layout = false, array $params = array()) { - return $this->get( 'ez_content' )->viewLocation( + return $this->get('ez_content')->viewLocation( $locationId, $viewType, $layout, array( - 'showSummary' => $this->container->getParameter( 'ezdemo.article.full_view.show_summary' ), - 'showImage' => $this->container->getParameter( 'ezdemo.article.full_view.show_image' ) + 'showSummary' => $this->container->getParameter('ezdemo.article.full_view.show_summary'), + 'showImage' => $this->container->getParameter('ezdemo.article.full_view.show_image'), ) + $params ); } @@ -70,36 +69,35 @@ public function showArticleAction( $locationId, $viewType, $layout = false, arra * @param \eZ\Publish\API\Repository\Values\Content\Location $location containing blog posts * @return \Symfony\Component\HttpFoundation\Response */ - public function listBlogPostsAction( Location $location, Request $request ) + public function listBlogPostsAction(Location $location, Request $request) { $response = new Response(); // Setting default cache configuration (you can override it in you siteaccess config) - $response->setSharedMaxAge( $this->getConfigResolver()->getParameter( 'content.default_ttl' ) ); + $response->setSharedMaxAge($this->getConfigResolver()->getParameter('content.default_ttl')); // Make the response location cache aware for the reverse proxy - $response->headers->set( 'X-Location-Id', $location->id ); - $response->setVary( 'X-User-Hash' ); + $response->headers->set('X-Location-Id', $location->id); + $response->setVary('X-User-Hash'); - $viewParameters = $request->attributes->get( 'viewParameters' ); + $viewParameters = $request->attributes->get('viewParameters'); // Getting location and content from ezpublish dedicated services $repository = $this->getRepository(); - if ( $location->invisible ) - { - throw new NotFoundHttpException( "Location #$location->id cannot be displayed as it is flagged as invisible." ); + if ($location->invisible) { + throw new NotFoundHttpException("Location #$location->id cannot be displayed as it is flagged as invisible."); } $content = $repository ->getContentService() - ->loadContentByContentInfo( $location->getContentInfo() ); + ->loadContentByContentInfo($location->getContentInfo()); // Getting language for the current siteaccess - $languages = $this->getConfigResolver()->getParameter( 'languages' ); + $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( + $criteria = $this->get('ezdemo.criteria_helper')->generateListBlogPostCriterion( $location, $viewParameters, $languages ); @@ -107,22 +105,22 @@ public function listBlogPostsAction( Location $location, Request $request ) $query = new Query(); $query->query = $criteria; $query->sortClauses = array( - new SortClause\Field( 'blog_post', 'publication_date', Query::SORT_DESC, $languages[0] ) + new SortClause\Field('blog_post', 'publication_date', Query::SORT_DESC, $languages[0]), ); // Initialize pagination. $pager = new Pagerfanta( - new ContentSearchAdapter( $query, $this->getRepository()->getSearchService() ) + new ContentSearchAdapter($query, $this->getRepository()->getSearchService()) ); - $pager->setMaxPerPage( $this->container->getParameter( 'ezdemo.blog.blog_post_list.limit' ) ); - $pager->setCurrentPage( $request->get( 'page', 1 ) ); + $pager->setMaxPerPage($this->container->getParameter('ezdemo.blog.blog_post_list.limit')); + $pager->setCurrentPage($request->get('page', 1)); return $this->render( 'eZDemoBundle:full:blog.html.twig', array( 'location' => $location, 'content' => $content, - 'pagerBlog' => $pager + 'pagerBlog' => $pager, ), $response ); @@ -141,162 +139,158 @@ public function listBlogPostsAction( Location $location, Request $request ) * @param array $params * @return \Symfony\Component\HttpFoundation\Response */ - public function showBlogPostAction( Location $location, $viewType, $layout = false, array $params = array() ) + public function showBlogPostAction(Location $location, $viewType, $layout = false, array $params = array()) { // We need the author, whatever the view type is. $repository = $this->getRepository(); - $author = $repository->getUserService()->loadUser( $location->getContentInfo()->ownerId ); + $author = $repository->getUserService()->loadUser($location->getContentInfo()->ownerId); // TODO once the keyword service is available, load the number of keyword for each keyword // Delegate view rendering to the original ViewController // (makes it possible to continue using defined template rules) // We just add "author" to the list of variables exposed to the final template - return $this->get( 'ez_content' )->viewLocation( + return $this->get('ez_content')->viewLocation( $location->id, $viewType, $layout, - array( 'author' => $author ) + $params + array('author' => $author) + $params ); } /** - * Displays content having similar tags as the given location + * Displays content having similar tags as the given location. * * @param \eZ\Publish\API\Repository\Values\Content\Location $location * @return \Symfony\Component\HttpFoundation\Response */ - public function viewTagRelatedContentAction( Location $location ) + public function viewTagRelatedContentAction(Location $location) { // TODO once the keyword service is available replace this subrequest by a full symfony one return $this->render( 'eZDemoBundle:parts:related_content.html.twig', - array( 'location' => $location ) + array('location' => $location) ); } /** * Displays description, tagcloud, tags, ezarchive and calendar - * of the parent's of a given location + * of the parent's of a given location. * * @param \eZ\Publish\API\Repository\Values\Content\Location $location * @return \Symfony\Component\HttpFoundation\Response */ - public function viewParentExtraInfoAction( Location $location ) + public function viewParentExtraInfoAction(Location $location) { $repository = $this->getRepository(); - $parentLocation = $repository->getLocationService()->loadLocation( $location->parentLocationId ); + $parentLocation = $repository->getLocationService()->loadLocation($location->parentLocationId); // TODO once the keyword service is available replace part this subrequest by a full symfony one return $this->render( 'eZDemoBundle:parts/blog:extra_info.html.twig', - array( 'location' => $parentLocation ) + array('location' => $parentLocation) ); } /** - * Displays description, tagcloud, tags, ezarchive and calendar for a given location + * Displays description, tagcloud, tags, ezarchive and calendar for a given location. * * @param \eZ\Publish\API\Repository\Values\Content\Location $location * @return \Symfony\Component\HttpFoundation\Response */ - public function viewExtraInfoAction( Location $location ) + public function viewExtraInfoAction(Location $location) { // TODO once the keyword service is available replace part this subrequest by a full symfony one return $this->render( 'eZDemoBundle:parts/blog:extra_info.html.twig', - array( 'location' => $location ) + array('location' => $location) ); } /** - * Displays "tip a friend" link for a given location + * Displays "tip a friend" link for a given location. * * @param \eZ\Publish\API\Repository\Values\Content\Location $location * @return \Symfony\Component\HttpFoundation\Response */ - public function viewTipAFriendAction( Location $location ) + public function viewTipAFriendAction(Location $location) { return $this->render( 'eZDemoBundle:parts/article:tip_a_friend.html.twig', - array( 'location' => $location ) + array('location' => $location) ); } /** - * Displays star rating attribute for a given location + * Displays star rating attribute for a given location. * * @param \eZ\Publish\API\Repository\Values\Content\Location $location * @return \Symfony\Component\HttpFoundation\Response */ - public function viewStarRatingAction( Location $location ) + public function viewStarRatingAction(Location $location) { return $this->render( 'eZDemoBundle:parts/article:star_rating.html.twig', - array( 'location' => $location ) + array('location' => $location) ); } /** - * Displays breadcrumb for a given $locationId + * Displays breadcrumb for a given $locationId. * * @param \eZ\Publish\API\Repository\Values\Content\Location $location * @return \Symfony\Component\HttpFoundation\Response */ - public function viewBreadcrumbAction( Location $location ) + public function viewBreadcrumbAction(Location $location) { /** @var WhiteOctober\BreadcrumbsBundle\Templating\Helper\BreadcrumbsHelper $breadcrumbs */ - $breadcrumbs = $this->get( "white_october_breadcrumbs" ); + $breadcrumbs = $this->get('white_october_breadcrumbs'); $locationService = $this->getRepository()->getLocationService(); $path = $location->path; // The root location can be defined at site access level - $rootLocationId = $this->getConfigResolver()->getParameter( 'content.tree_root.location_id' ); + $rootLocationId = $this->getConfigResolver()->getParameter('content.tree_root.location_id'); /** @var eZ\Publish\Core\Helper\TranslationHelper $translationHelper */ - $translationHelper = $this->get( 'ezpublish.translation_helper' ); + $translationHelper = $this->get('ezpublish.translation_helper'); $isRootLocation = false; // Shift of location "1" from path as it is not a fully valid location and not readable by most users - array_shift( $path ); + array_shift($path); - for ( $i = 0; $i < count( $path ); $i++ ) - { - $location = $locationService->loadLocation( $path[$i] ); + for ($i = 0; $i < count($path); ++$i) { + $location = $locationService->loadLocation($path[$i]); // if root location hasn't been found yet - if ( !$isRootLocation ) - { + if (!$isRootLocation) { // If we reach the root location We begin to add item to the breadcrumb from it - if ( $location->id == $rootLocationId ) - { + if ($location->id == $rootLocationId) { $isRootLocation = true; $breadcrumbs->addItem( - $translationHelper->getTranslatedContentNameByContentInfo( $location->contentInfo ), - $this->generateUrl( $location ) + $translationHelper->getTranslatedContentNameByContentInfo($location->contentInfo), + $this->generateUrl($location) ); } } // The root location has already been reached, so we can add items to the breadcrumb - else - { + else { $breadcrumbs->addItem( - $translationHelper->getTranslatedContentNameByContentInfo( $location->contentInfo ), - $this->generateUrl( $location ) + $translationHelper->getTranslatedContentNameByContentInfo($location->contentInfo), + $this->generateUrl($location) ); } } // We don't want the breadcrumb to be displayed if we are on the frontpage // which means we display it only if we have several items in it - if ( count( $breadcrumbs ) <= 1 ) - { + if (count($breadcrumbs) <= 1) { return new Response(); } + return $this->render( 'eZDemoBundle::breadcrumb.html.twig' ); diff --git a/Controller/FeedbackFormController.php b/Controller/FeedbackFormController.php index 8955781..7115d4b 100644 --- a/Controller/FeedbackFormController.php +++ b/Controller/FeedbackFormController.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Controller; use eZ\Bundle\EzPublishCoreBundle\Controller; @@ -28,41 +27,39 @@ class FeedbackFormController extends Controller * * @return mixed */ - public function showFeedbackFormAction( Request $request, Location $location, $viewType, $layout = false, array $params = array() ) + public function showFeedbackFormAction(Request $request, Location $location, $viewType, $layout = false, array $params = array()) { // Creating a form using Symfony's form component $feedback = new Feedback(); - $form = $this->createForm( $this->get( 'ezdemo.form.type.feedback' ), $feedback ); + $form = $this->createForm($this->get('ezdemo.form.type.feedback'), $feedback); - if ( $request->isMethod( 'POST' ) ) - { - $form->handleRequest( $request ); + if ($request->isMethod('POST')) { + $form->handleRequest($request); - if ( $form->isValid() ) - { + if ($form->isValid()) { /** @var EmailHelper $emailHelper */ - $emailHelper = $this->get( 'ezdemo.email_helper' ); + $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' ) + $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( + $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.' ) + $this->get('translator')->trans('Thank you for your message, we will get back to you as soon as possible.') ); - return $this->redirect( $this->generateUrl( $location ) ); + return $this->redirect($this->generateUrl($location)); } } - return $this->get( 'ez_content' )->viewLocation( + return $this->get('ez_content')->viewLocation( $location->id, $viewType, $layout, - array( 'form' => $form->createView() ) + $params + array('form' => $form->createView()) + $params ); } } diff --git a/Controller/FolderController.php b/Controller/FolderController.php index 7ce3b00..bc974f8 100644 --- a/Controller/FolderController.php +++ b/Controller/FolderController.php @@ -1,12 +1,11 @@ invisible ) - { - throw new NotFoundHttpException( "Location #$location->id cannot be displayed as it is flagged as invisible." ); + if ($location->invisible) { + throw new NotFoundHttpException("Location #$location->id cannot be displayed as it is flagged as invisible."); } - $response->setSharedMaxAge( $this->getConfigResolver()->getParameter( 'content.default_ttl' ) ); - $response->headers->set( 'X-Location-Id', $location->id ); - $response->setVary( 'X-User-Hash' ); + $response->setSharedMaxAge($this->getConfigResolver()->getParameter('content.default_ttl')); + $response->headers->set('X-Location-Id', $location->id); + $response->setVary('X-User-Hash'); - $languages = $this->getConfigResolver()->getParameter( 'languages' ); + $languages = $this->getConfigResolver()->getParameter('languages'); - $includedContentTypeIdentifiers = $this->container->getParameter( 'ezdemo.folder.folder_tree.included_content_types' ); + $includedContentTypeIdentifiers = $this->container->getParameter('ezdemo.folder.folder_tree.included_content_types'); - $subContentCriteria = $this->get( 'ezdemo.criteria_helper' )->generateSubContentCriterion( + $subContentCriteria = $this->get('ezdemo.criteria_helper')->generateSubContentCriterion( $location, $includedContentTypeIdentifiers, $languages ); $subContentQuery = new LocationQuery(); $subContentQuery->query = $subContentCriteria; $subContentQuery->sortClauses = array( - new SortClause\ContentName() + new SortClause\ContentName(), ); $subContentQuery->performCount = false; $searchService = $this->getRepository()->getSearchService(); - $subContent = $searchService->findLocations( $subContentQuery ); + $subContent = $searchService->findLocations($subContentQuery); $treeChildItems = array(); - foreach ( $subContent->searchHits as $hit ) - { + foreach ($subContent->searchHits as $hit) { $treeChildItems[] = $hit->valueObject; } - return $this->get( 'ez_content' )->viewLocation( + return $this->get('ez_content')->viewLocation( $location->id, 'aside_sub', true, @@ -75,38 +72,37 @@ public function showFolderListAsideViewAction( Location $location ) } /** - * Displays the list of article + * Displays the list of article. * * @param \eZ\Publish\API\Repository\Values\Content\Location $location of a folder * @param \Symfony\Component\HttpFoundation\Request $request request object * @throws NotFoundHttpException $location is flagged as invisible * @return \Symfony\Component\HttpFoundation\Response */ - public function showFolderListAction( Request $request, Location $location ) + public function showFolderListAction(Request $request, Location $location) { $response = new Response(); - if ( $location->invisible ) - { - throw new NotFoundHttpException( "Location #$location->id cannot be displayed as it is flagged as invisible." ); + if ($location->invisible) { + throw new NotFoundHttpException("Location #$location->id cannot be displayed as it is flagged as invisible."); } - $response->setSharedMaxAge( $this->getConfigResolver()->getParameter( 'content.default_ttl' ) ); - $response->headers->set( 'X-Location-Id', $location->id ); - $response->setVary( 'X-User-Hash' ); + $response->setSharedMaxAge($this->getConfigResolver()->getParameter('content.default_ttl')); + $response->headers->set('X-Location-Id', $location->id); + $response->setVary('X-User-Hash'); $content = $this->getRepository() ->getContentService() - ->loadContentByContentInfo( $location->getContentInfo() ); + ->loadContentByContentInfo($location->getContentInfo()); // Getting language for the current siteaccess - $languages = $this->getConfigResolver()->getParameter( 'languages' ); + $languages = $this->getConfigResolver()->getParameter('languages'); - $excludedContentTypes = $this->container->getParameter( 'ezdemo.folder.folder_view.excluded_content_types' ); + $excludedContentTypes = $this->container->getParameter('ezdemo.folder.folder_view.excluded_content_types'); // 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( + $criteria = $this->get('ezdemo.criteria_helper')->generateListFolderCriterion( $location, $excludedContentTypes, $languages ); @@ -114,40 +110,39 @@ public function showFolderListAction( Request $request, Location $location ) $query = new LocationQuery(); $query->query = $criteria; $query->sortClauses = array( - new SortClause\DatePublished() + new SortClause\DatePublished(), ); // Initialize pagination. $pager = new Pagerfanta( - new ContentSearchAdapter( $query, $this->getRepository()->getSearchService() ) + new ContentSearchAdapter($query, $this->getRepository()->getSearchService()) ); - $pager->setMaxPerPage( $this->container->getParameter( 'ezdemo.folder.folder_list.limit' ) ); - $pager->setCurrentPage( $request->get( 'page', 1 ) ); + $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' ); + $includedContentTypeIdentifiers = $this->container->getParameter('ezdemo.folder.folder_tree.included_content_types'); // Get sub folder structure - $subContentCriteria = $this->get( 'ezdemo.criteria_helper' )->generateSubContentCriterion( + $subContentCriteria = $this->get('ezdemo.criteria_helper')->generateSubContentCriterion( $location, $includedContentTypeIdentifiers, $languages ); $subContentQuery = new LocationQuery(); $subContentQuery->query = $subContentCriteria; $subContentQuery->sortClauses = array( - new SortClause\ContentName() + new SortClause\ContentName(), ); $searchService = $this->getRepository()->getSearchService(); - $subContent = $searchService->findLocations( $subContentQuery ); + $subContent = $searchService->findLocations($subContentQuery); $treeItems = array(); - foreach ( $subContent->searchHits as $hit ) - { + foreach ($subContent->searchHits as $hit) { $treeItems[] = $hit->valueObject; } - return $this->get( 'ez_content' )->viewLocation( + return $this->get('ez_content')->viewLocation( $location->id, 'full', true, diff --git a/Controller/FooterController.php b/Controller/FooterController.php index d506d5b..c807567 100644 --- a/Controller/FooterController.php +++ b/Controller/FooterController.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Controller; use eZ\Bundle\EzPublishCoreBundle\Controller; @@ -53,7 +52,7 @@ public function latestContentAction($currentContentId) $rootLocationId = $this->getConfigResolver()->getParameter('content.tree_root.location_id'); $rootLocation = $locationService->loadLocation($rootLocationId); - $response = new Response; + $response = new Response(); $response->setPublic(); $response->setSharedMaxAge(86400); $response->headers->set('X-Location-Id', $rootLocationId); diff --git a/Controller/FrontpageController.php b/Controller/FrontpageController.php index ca147be..94bfd6e 100644 --- a/Controller/FrontpageController.php +++ b/Controller/FrontpageController.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Controller; use eZ\Bundle\EzPublishCoreBundle\Controller; @@ -28,27 +27,27 @@ class FrontpageController extends Controller * * @return Response */ - public function renderFeedBlockAction( $feedUrl, $offset = 0, $limit = 5 ) + public function renderFeedBlockAction($feedUrl, $offset = 0, $limit = 5) { $response = new Response(); - try - { + try { // Keep response in cache. TTL is configured in default_settings.yml - $response->setSharedMaxAge( $this->container->getParameter( 'ezdemo.cache.feed_reader_ttl' ) ); + $response->setSharedMaxAge($this->container->getParameter('ezdemo.cache.feed_reader_ttl')); + return $this->render( 'eZDemoBundle:frontpage:feed_block.html.twig', array( - 'feed' => ezcFeed::parse( $feedUrl ), + 'feed' => ezcFeed::parse($feedUrl), 'offset' => $offset, - 'limit' => $limit + 'limit' => $limit, ), $response ); } // In the case of exception raised in ezcFeed, return the empty response to fail nicely. - catch ( Exception $e ) - { - $this->get( 'logger' )->error( "An exception has been raised when fetching RSS feed: {$e->getMessage()}" ); + catch (Exception $e) { + $this->get('logger')->error("An exception has been raised when fetching RSS feed: {$e->getMessage()}"); + return $response; } } diff --git a/Controller/LanguageSwitcherController.php b/Controller/LanguageSwitcherController.php index 1590aec..42e000f 100644 --- a/Controller/LanguageSwitcherController.php +++ b/Controller/LanguageSwitcherController.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Controller; use eZ\Bundle\EzPublishCoreBundle\Controller; @@ -23,24 +22,22 @@ class LanguageSwitcherController extends Controller * * @return \Symfony\Component\HttpFoundation\Response */ - public function showSwitcherAction( Request $request, RouteReference $routeReference ) + public function showSwitcherAction(Request $request, RouteReference $routeReference) { /** @var \eZ\Publish\Core\Helper\TranslationHelper $translationHelper */ - $translationHelper = $this->container->get( 'ezpublish.translation_helper' ); + $translationHelper = $this->container->get('ezpublish.translation_helper'); /** @var \eZ\Publish\Core\MVC\Symfony\Locale\LocaleConverterInterface $localeConverter */ - $localeConverter = $this->container->get( 'ezpublish.locale.converter' ); + $localeConverter = $this->container->get('ezpublish.locale.converter'); // get current eZ language - $currentEzLanguage = $localeConverter->convertToEz( $request->get( '_locale' ) ); + $currentEzLanguage = $localeConverter->convertToEz($request->get('_locale')); $siteaccess = []; $availableLanguages = []; // create an array for corresponding siteaccesses names depending on the lang - foreach ( $translationHelper->getAvailableLanguages() as $lang ) - { - if ( $lang != null ) - { - $siteaccess[$lang] = $translationHelper->getTranslationSiteAccess( $lang ); + foreach ($translationHelper->getAvailableLanguages() as $lang) { + if ($lang != null) { + $siteaccess[$lang] = $translationHelper->getTranslationSiteAccess($lang); $availableLanguages[] = $lang; } } @@ -51,7 +48,7 @@ public function showSwitcherAction( Request $request, RouteReference $routeRefer 'routeRef' => $routeReference, 'siteaccess' => $siteaccess, 'currentLanguage' => $currentEzLanguage, - 'availableLanguages' => $availableLanguages + 'availableLanguages' => $availableLanguages, ) ); } diff --git a/Controller/MenuController.php b/Controller/MenuController.php index c737590..14b4a7e 100644 --- a/Controller/MenuController.php +++ b/Controller/MenuController.php @@ -1,6 +1,6 @@ getLocationService()->loadLocation( $currentLocationId ); - if ( isset( $location->path[2] ) ) - { + if ($currentLocationId !== null) { + $location = $this->getLocationService()->loadLocation($currentLocationId); + if (isset($location->path[2])) { $secondLevelLocationId = $location->path[2]; } } - $response = new Response; + $response = new Response(); - $menu = $this->getMenu( 'top' ); - $parameters = array( 'menu' => $menu ); - if ( isset( $secondLevelLocationId ) && isset( $menu[$secondLevelLocationId] ) ) - { + $menu = $this->getMenu('top'); + $parameters = array('menu' => $menu); + if (isset($secondLevelLocationId) && isset($menu[$secondLevelLocationId])) { $parameters['submenu'] = $menu[$secondLevelLocationId]; } - return $this->render( 'eZDemoBundle::page_topmenu.html.twig', $parameters, $response ); + return $this->render('eZDemoBundle::page_topmenu.html.twig', $parameters, $response); } /** * @param string $identifier * @return \Knp\Menu\MenuItem */ - private function getMenu( $identifier ) + private function getMenu($identifier) { - return $this->container->get( "ezdemo.menu.$identifier" ); + return $this->container->get("ezdemo.menu.$identifier"); } /** @@ -55,6 +51,6 @@ private function getMenu( $identifier ) */ private function getLocationService() { - return $this->container->get( 'ezpublish.api.service.location' ); + return $this->container->get('ezpublish.api.service.location'); } } diff --git a/Controller/PlaceController.php b/Controller/PlaceController.php index de79052..19e6428 100644 --- a/Controller/PlaceController.php +++ b/Controller/PlaceController.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Controller; use eZ\Bundle\EzPublishCoreBundle\Controller; @@ -17,32 +16,32 @@ class PlaceController extends Controller { /** - * Displays all the places contained in a place list + * Displays all the places contained in a place list. * * @param \eZ\Publish\API\Repository\Values\Content\Location $location of a place_list * * @return \Symfony\Component\HttpFoundation\Response */ - public function listPlaceListAction( Location $location ) + public function listPlaceListAction(Location $location) { /** @var \EzSystems\DemoBundle\Helper\PlaceHelper $placeHelper */ - $placeHelper = $this->get( 'ezdemo.place_helper' ); + $placeHelper = $this->get('ezdemo.place_helper'); $places = $placeHelper->getPlaceList( $location, - $this->container->getParameter( 'ezdemo.places.place_list.content_types' ), - $this->getConfigResolver()->getParameter( 'languages' ) + $this->container->getParameter('ezdemo.places.place_list.content_types'), + $this->getConfigResolver()->getParameter('languages') ); return $this->render( 'eZDemoBundle:parts/place:place_list.html.twig', - array( 'places' => $places ) + array('places' => $places) ); } /** * Displays all the places sorted by proximity contained in a place list - * The max distance of the places displayed can be modified in the default config + * The max distance of the places displayed can be modified in the default config. * * @param \eZ\Publish\API\Repository\Values\Content\Location $location of a place_list * @param float $latitude @@ -53,37 +52,36 @@ public function listPlaceListAction( Location $location ) * * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ - public function listPlaceListSortedAction( Location $location, $latitude, $longitude, $maxDist ) + public function listPlaceListSortedAction(Location $location, $latitude, $longitude, $maxDist) { // The Symfony router is configured (routing.yml) not to check for keys needed to generate URL // template from twig (without calling the controller). // We need to make sure those keys can't be used here. - if ( $latitude == "key_lat" || $longitude == "key_lon" || $maxDist == "key_dist" ) - { - throw $this->createNotFoundException( "Invalid parameters" ); + if ($latitude == 'key_lat' || $longitude == 'key_lon' || $maxDist == 'key_dist') { + throw $this->createNotFoundException('Invalid parameters'); } /** @var \EzSystems\DemoBundle\Helper\PlaceHelper $placeHelper */ - $placeHelper = $this->get( 'ezdemo.place_helper' ); + $placeHelper = $this->get('ezdemo.place_helper'); - $languages = $this->getConfigResolver()->getParameter( 'languages' ); - $language = ( !empty( $languages ) ) ? $languages[0] : null; + $languages = $this->getConfigResolver()->getParameter('languages'); + $language = (!empty($languages)) ? $languages[0] : null; $sortClauses = array( new SortClause\MapLocationDistance( - "place", - "location", + 'place', + 'location', $latitude, $longitude, Query::SORT_ASC, $language - ) + ), ); $places = $placeHelper->getPlaceListSorted( $location, $latitude, $longitude, - $this->container->getParameter( 'ezdemo.places.place_list.content_types' ), + $this->container->getParameter('ezdemo.places.place_list.content_types'), $maxDist, $sortClauses, $languages @@ -91,7 +89,7 @@ public function listPlaceListSortedAction( Location $location, $latitude, $longi return $this->render( 'eZDemoBundle:parts/place:place_list.html.twig', - array( 'places' => $places ) + array('places' => $places) ); } } diff --git a/Controller/SearchController.php b/Controller/SearchController.php index 24023dd..cdffcd4 100644 --- a/Controller/SearchController.php +++ b/Controller/SearchController.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Controller; use eZ\Bundle\EzPublishCoreBundle\Controller; @@ -14,44 +13,40 @@ use EzSystems\DemoBundle\Helper\SearchHelper; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use eZ\Publish\API\Repository\Values\Content\Query; -use eZ\Publish\API\Repository\Values\Content\Query\Criterion; class SearchController extends Controller { /** - * Displays the simple search page + * Displays the simple search page. * * @param Request $request * * @return Response */ - public function showSearchResultsAction( Request $request ) + public function showSearchResultsAction(Request $request) { $response = new Response(); - $searchText = ""; + $searchText = ''; $searchCount = 0; // Creating a form using Symfony's form component $simpleSearch = new SimpleSearch(); - $form = $this->createForm( $this->get( 'ezdemo.form.type.simple_search' ), $simpleSearch ); - $form->handleRequest( $request ); + $form = $this->createForm($this->get('ezdemo.form.type.simple_search'), $simpleSearch); + $form->handleRequest($request); $pager = null; - if ( $form->isValid() ) - { + if ($form->isValid()) { /** @var SearchHelper $searchHelper */ - $searchHelper = $this->get( 'ezdemo.search_helper' ); + $searchHelper = $this->get('ezdemo.search_helper'); - if ( !empty( $simpleSearch->searchText ) ) - { + if (!empty($simpleSearch->searchText)) { $searchText = $simpleSearch->searchText; $pager = $searchHelper->searchForPaginatedContent( $searchText, - $request->get( 'page', 1 ), - $this->getConfigResolver()->getParameter( 'languages' ) + $request->get('page', 1), + $this->getConfigResolver()->getParameter('languages') ); $searchCount = $pager->getNbResults(); @@ -64,14 +59,14 @@ public function showSearchResultsAction( Request $request ) 'searchText' => $searchText, 'searchCount' => $searchCount, 'pagerSearch' => $pager, - 'form' => $form->createView() + 'form' => $form->createView(), ), $response ); } /** - * Displays the search box for the page header + * Displays the search box for the page header. * * @return Response HTML code of the page */ @@ -80,12 +75,12 @@ public function searchBoxAction() $response = new Response(); $simpleSearch = new SimpleSearch(); - $form = $this->createForm( $this->get( 'ezdemo.form.type.simple_search' ), $simpleSearch ); + $form = $this->createForm($this->get('ezdemo.form.type.simple_search'), $simpleSearch); return $this->render( 'eZDemoBundle::page_header_searchbox.html.twig', array( - 'form' => $form->createView() + 'form' => $form->createView(), ), $response ); diff --git a/DependencyInjection/eZDemoExtension.php b/DependencyInjection/eZDemoExtension.php index dda912d..d9b1216 100644 --- a/DependencyInjection/eZDemoExtension.php +++ b/DependencyInjection/eZDemoExtension.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\DependencyInjection; use Symfony\Component\Config\Resource\FileResource; @@ -25,17 +24,17 @@ class eZDemoExtension extends Extension implements PrependExtensionInterface * @param array $config An array of configuration values * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container */ - public function load( array $config, ContainerBuilder $container ) + public function load(array $config, ContainerBuilder $container) { $loader = new YamlFileLoader( $container, - new FileLocator( __DIR__ . '/../Resources/config' ) + new FileLocator(__DIR__ . '/../Resources/config') ); // Base services override - $loader->load( 'services.yml' ); + $loader->load('services.yml'); // Default settings - $loader->load( 'default_settings.yml' ); + $loader->load('default_settings.yml'); } /** @@ -43,35 +42,34 @@ public function load( array $config, ContainerBuilder $container ) * * @param ContainerBuilder $container */ - public function prepend( ContainerBuilder $container ) + public function prepend(ContainerBuilder $container) { // Add legacy bundle settings only if it's present. - if ( $container->hasExtension( 'ez_publish_legacy' ) ) - { + if ($container->hasExtension('ez_publish_legacy')) { $legacyConfigFile = __DIR__ . '/../Resources/config/legacy_settings.yml'; - $config = Yaml::parse( file_get_contents( $legacyConfigFile ) ); - $container->prependExtensionConfig( 'ez_publish_legacy', $config ); - $container->addResource( new FileResource( $legacyConfigFile ) ); + $config = Yaml::parse(file_get_contents($legacyConfigFile)); + $container->prependExtensionConfig('ez_publish_legacy', $config); + $container->addResource(new FileResource($legacyConfigFile)); } $configFile = __DIR__ . '/../Resources/config/ezdemo.yml'; - $config = Yaml::parse( file_get_contents( $configFile ) ); - $container->prependExtensionConfig( 'ezpublish', $config ); - $container->addResource( new FileResource( $configFile ) ); + $config = Yaml::parse(file_get_contents($configFile)); + $container->prependExtensionConfig('ezpublish', $config); + $container->addResource(new FileResource($configFile)); $configFile = __DIR__ . '/../Resources/config/image_variations.yml'; - $config = Yaml::parse( file_get_contents( $configFile ) ); - $container->prependExtensionConfig( 'ezpublish', $config ); - $container->addResource( new FileResource( $configFile ) ); + $config = Yaml::parse(file_get_contents($configFile)); + $container->prependExtensionConfig('ezpublish', $config); + $container->addResource(new FileResource($configFile)); $ezpageConfigFile = __DIR__ . '/../Resources/config/ezpage.yml'; - $ezpageConfig = Yaml::parse( file_get_contents( $ezpageConfigFile ) ); - $container->prependExtensionConfig( 'ezpublish', $ezpageConfig ); - $container->addResource( new FileResource( $ezpageConfigFile ) ); + $ezpageConfig = Yaml::parse(file_get_contents($ezpageConfigFile)); + $container->prependExtensionConfig('ezpublish', $ezpageConfig); + $container->addResource(new FileResource($ezpageConfigFile)); $ezCommentsConfigFile = __DIR__ . '/../Resources/config/ezcomments.yml'; - $ezCommentsConfig = Yaml::parse( file_get_contents( $ezCommentsConfigFile ) ); - $container->prependExtensionConfig( 'ez_comments', $ezCommentsConfig ); - $container->addResource( new FileResource( $ezCommentsConfigFile ) ); + $ezCommentsConfig = Yaml::parse(file_get_contents($ezCommentsConfigFile)); + $container->prependExtensionConfig('ez_comments', $ezCommentsConfig); + $container->addResource(new FileResource($ezCommentsConfigFile)); } } diff --git a/Entity/Feedback.php b/Entity/Feedback.php index 204327b..2303f07 100644 --- a/Entity/Feedback.php +++ b/Entity/Feedback.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Entity; use Symfony\Component\Validator\Constraints as Assert; @@ -49,5 +48,4 @@ class Feedback * @Assert\Length( min = 1, max = 2000, maxMessage = "feedback.max_size.2000" ) */ public $message; - } diff --git a/Entity/SimpleSearch.php b/Entity/SimpleSearch.php index fe437ff..bd054c2 100644 --- a/Entity/SimpleSearch.php +++ b/Entity/SimpleSearch.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Entity; use Symfony\Component\Validator\Constraints as Assert; diff --git a/EventListener/PreContentViewListener.php b/EventListener/PreContentViewListener.php index c507192..d6f6d64 100644 --- a/EventListener/PreContentViewListener.php +++ b/EventListener/PreContentViewListener.php @@ -6,20 +6,19 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\EventListener; use eZ\Publish\Core\MVC\Symfony\Event\PreContentViewEvent; class PreContentViewListener { - public function onPreContentView( PreContentViewEvent $event ) + public function onPreContentView(PreContentViewEvent $event) { $contentView = $event->getContentView(); $contentView->addParameters( array( 'foo' => 'bar', - 'osTypes' => array( 'osx', 'linux', 'win' ) + 'osTypes' => array('osx', 'linux', 'win'), ) ); } diff --git a/EzSystemsDemoBundle.php b/EzSystemsDemoBundle.php index f856af3..5ba2ca5 100644 --- a/EzSystemsDemoBundle.php +++ b/EzSystemsDemoBundle.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; diff --git a/Features/Context/Content/Context.php b/Features/Context/Content/Context.php index 01422d1..799844a 100644 --- a/Features/Context/Content/Context.php +++ b/Features/Context/Content/Context.php @@ -6,44 +6,41 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Features\Context\Content; use EzSystems\DemoBundle\Features\Context\Demo; -use EzSystems\BehatBundle\Helper\EzAssertion; -use Behat\Behat\Context\Step; use Behat\Gherkin\Node\TableNode; use PHPUnit_Framework_Assert as Assertion; /** - * Base context for Demo content assertion + * Base context for Demo content assertion. */ class Context extends Demo { /** - * Set initial definitions + * Set initial definitions. */ public function __construct() { parent::__construct(); $this->pageIdentifierMap += array( - "search" => "/content/search", - "site map" => "/content/view/sitemap/2", - "tag cloud" => "/content/view/tagcloud/2", + 'search' => '/content/search', + 'site map' => '/content/view/sitemap/2', + 'tag cloud' => '/content/view/tagcloud/2', ); // specify the tags for specific content $this->mainAttributes += array( - "ez logo" => array( "class" => "logo", "href" => "/" ), - "main content" => array( "class" => "main-content" ), - "main navigation" => array( "class" => "main-navi" ), + 'ez logo' => array('class' => 'logo', 'href' => '/'), + 'main content' => array('class' => 'main-content'), + 'main navigation' => array('class' => 'main-navi'), ); } /** * This is an helper to retrieve the id of a Content object so that it can - * be used on links for locations + * be used on links for locations. * * @param string $text Text identifier for a location * @@ -51,53 +48,52 @@ public function __construct() * * @throws PendingException When location is not defined */ - protected function getDemoObjectLocationByText( $text ) + protected function getDemoObjectLocationByText($text) { - switch ( strtolower( $text ) ) - { + switch (strtolower($text)) { case 'shopping': return 74; case 'getting started': return 61; } - throw new PendingException( "Location for '$text' not defined." ); + throw new PendingException("Location for '$text' not defined."); } /** * @When I check site map for Location :location */ - public function iCheckSiteMapForLocation( $location ) + public function iCheckSiteMapForLocation($location) { - $id = $this->getDemoObjectLocationByText( $location ); - $this->visit( '/content/view/sitemap/' . $id ); + $id = $this->getDemoObjectLocationByText($location); + $this->visit('/content/view/sitemap/' . $id); } /** * @Given I am on tag page for :tag */ - public function iAmOnTagPageFor( $tag ) + public function iAmOnTagPageFor($tag) { - $this->visit( "/content/keyword/$tag" ); + $this->visit("/content/keyword/$tag"); } /** * @When /^I go to tag cloud for "(?P[^"]*)"$/ */ - public function iCheckTagCloudFor( $tag ) + public function iCheckTagCloudFor($tag) { - $id = $this->getDemoObjectLocationByText( $tag ); - $this->visit( "/content/view/tagcloud/$id" ); + $id = $this->getDemoObjectLocationByText($tag); + $this->visit("/content/view/tagcloud/$id"); } /** * @Then I (should) see tag page for :tag */ - public function iSeeTagPageFor( $tag ) + public function iSeeTagPageFor($tag) { - $currentUrl = $this->getUrlWithoutQueryString( $this->getSession()->getCurrentUrl() ); + $currentUrl = $this->getUrlWithoutQueryString($this->getSession()->getCurrentUrl()); - $expectedUrl = $this->locatePath( "/content/keyword/$tag" ); + $expectedUrl = $this->locatePath("/content/keyword/$tag"); Assertion::assertEquals( $expectedUrl, @@ -107,40 +103,36 @@ public function iSeeTagPageFor( $tag ) } /** - * Tests that the page contains a specific link with a specific text (the text must be within a span) + * Tests that the page contains a specific link with a specific text (the text must be within a span). * @Then It has the text :text in a span linked to :link * @Then I see the text :text in a span linked to :link */ - public function itHasATextSpanLinkedTo( $text, $link ) + public function itHasATextSpanLinkedTo($text, $link) { - $this->assertSession()->pageTextContains( $text ); + $this->assertSession()->pageTextContains($text); Assertion::assertCount( 1, - $this->getXpath()->findXpath( sprintf( '//a[@href="%s"]/span[text()="%s"]', $link, $text ) ) + $this->getXpath()->findXpath(sprintf('//a[@href="%s"]/span[text()="%s"]', $link, $text)) ); } /** - * Tests if a link is present in the breadcrumbs + * Tests if a link is present in the breadcrumbs. * @Then the breadcrumb has the following links: */ - public function breadcrumbHasTheFollowingLinks( TableNode $table ) + public function breadcrumbHasTheFollowingLinks(TableNode $table) { - foreach ( $table->getTable() as $breadcrumbItem ) - { + foreach ($table->getTable() as $breadcrumbItem) { $text = $breadcrumbItem[0]; $url = $breadcrumbItem[1]; // this is not a link (the current page) - if ( $url === "null" ) - { + if ($url === 'null') { $query = sprintf( '//ul[@id="wo-breadcrumbs"]/li/span[text()="%s"]', $text ); - } - else - { + } else { $query = sprintf( '//ul[@id="wo-breadcrumbs"]/li/a[@href="%s"]/span[text()="%s"]', $url, @@ -149,28 +141,27 @@ public function breadcrumbHasTheFollowingLinks( TableNode $table ) } Assertion::assertCount( - 1, $this->getXpath()->findXpath( $query ) + 1, $this->getXpath()->findXpath($query) ); } } /** - * Test if image is present on page and is downloadable (`img` tag must contain `alt` attribute) + * Test if image is present on page and is downloadable (`img` tag must contain `alt` attribute). * @Then I (should) see a valid thumbnail for image with alternative text :imageAlternativeText */ - public function iShouldSeeAVailidThumbnailForImageWithAlternativeText( $imageAlternativeText ) + public function iShouldSeeAVailidThumbnailForImageWithAlternativeText($imageAlternativeText) { - $image = $this->getXpath()->findXpath( "//img[contains(@alt, '" . $imageAlternativeText . "')]" ); + $image = $this->getXpath()->findXpath("//img[contains(@alt, '" . $imageAlternativeText . "')]"); - if ( count( $image ) == 0 ) - { - throw new \Exception( sprintf( 'Image with an alternative text `%s` was not found', $imageAlternativeText ) ); + if (count($image) == 0) { + throw new \Exception(sprintf('Image with an alternative text `%s` was not found', $imageAlternativeText)); } - $file = $image[0]->getAttribute( 'src' ); + $file = $image[0]->getAttribute('src'); $client = new \Guzzle\Http\Client(); - $request = $client->get( $this->locatePath( $file ) ); + $request = $client->get($this->locatePath($file)); $response = $request->send(); Assertion::equalTo( @@ -178,7 +169,7 @@ public function iShouldSeeAVailidThumbnailForImageWithAlternativeText( $imageAlt ); Assertion::assertRegexp( - '/image\/(.*)/', $response->getHeader( 'content-type' )->__toString() + '/image\/(.*)/', $response->getHeader('content-type')->__toString() ); } } diff --git a/Features/Context/Demo.php b/Features/Context/Demo.php index 0b02701..d4e2694 100644 --- a/Features/Context/Demo.php +++ b/Features/Context/Demo.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Features\Context; use EzSystems\BehatBundle\Context\Browser\Context; @@ -14,49 +13,49 @@ use PHPUnit_Framework_Assert as Assertion; /** - * Demo context base class + * Demo context base class. */ class Demo extends Context { /** - * Set initial definitions + * Set initial definitions. */ public function __construct() { parent::__construct(); $this->pageIdentifierMap += array( - "search" => "/content/search", - "premium_article" => "/Getting-Started/Selected-Features/Getting-Started-with-eZ-Publish-Platform", - "blog" => "/Blog", - "feedback_form" => "/Contact-Us", - "place" => "/eZ-Mountains", - "services" => "/Shopping/Services", - "products" => "/Shopping/Products", - "resources" => "/Getting-Started/Resources", - "partner" => "/Partner", + 'search' => '/content/search', + 'premium_article' => '/Getting-Started/Selected-Features/Getting-Started-with-eZ-Publish-Platform', + 'blog' => '/Blog', + 'feedback_form' => '/Contact-Us', + 'place' => '/eZ-Mountains', + 'services' => '/Shopping/Services', + 'products' => '/Shopping/Products', + 'resources' => '/Getting-Started/Resources', + 'partner' => '/Partner', ); $this->mainAttributes += array( - 'ez logo' => array( "class" => "logo", "href" => "/" ) + 'ez logo' => array('class' => 'logo', 'href' => '/'), ); } /** * @When I search for :search */ - public function iSearchFor( $search ) + public function iSearchFor($search) { // workaround to get the search box that doesn't have a unique way to do it - $elements = $this->getXpath()->findFields( 'ezdemo_simple_search[searchText]' ); + $elements = $this->getXpath()->findFields('ezdemo_simple_search[searchText]'); Assertion::assertEquals( 2, - count( $elements ), - 'Expected to find 2 search boxes but found ' . count( $elements ) + count($elements), + 'Expected to find 2 search boxes but found ' . count($elements) ); - $elements[1]->setValue( $search ); + $elements[1]->setValue($search); - $this->iClickAtButton( 'Search' ); + $this->iClickAtButton('Search'); } /** @@ -64,19 +63,19 @@ public function iSearchFor( $search ) */ public function iClickAtEzLogoImage() { - $el = $this->getXpath()->findXpath( $this->makeXpathForBlock( 'ez logo' ) ); - EzAssertion::assertSingleElement( 'eZ Logo', $el, null, 'image link' ); + $el = $this->getXpath()->findXpath($this->makeXpathForBlock('ez logo')); + EzAssertion::assertSingleElement('eZ Logo', $el, null, 'image link'); $el[0]->click(); } /** * @Then I (should) see :total search result(s) */ - public function iSeeSearchResults( $total ) + public function iSeeSearchResults($total) { - $resultCountElement = $this->getXpath()->findXpath( "//div[@class = 'feedback']" ); + $resultCountElement = $this->getXpath()->findXpath("//div[@class = 'feedback']"); - EzAssertion::assertSingleElement( 'search feedback', $resultCountElement ); + EzAssertion::assertSingleElement('search feedback', $resultCountElement); Assertion::assertRegExp( "/Search for \"(.*)\" returned {$total} matches/", diff --git a/Form/Type/FeedbackType.php b/Form/Type/FeedbackType.php index 9b8fde2..b196f6b 100644 --- a/Form/Type/FeedbackType.php +++ b/Form/Type/FeedbackType.php @@ -6,26 +6,24 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; class FeedbackType extends AbstractType { - public function buildForm( FormBuilderInterface $builder, array $options ) + public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add( 'firstName', 'text' ) - ->add( 'lastName', 'text' ) - ->add( 'email', 'email' ) - ->add( 'subject', 'text' ) - ->add( 'country', 'country' ) - ->add( 'message', 'textarea' ) - ->add( 'save', 'submit' ); + ->add('firstName', 'text') + ->add('lastName', 'text') + ->add('email', 'email') + ->add('subject', 'text') + ->add('country', 'country') + ->add('message', 'textarea') + ->add('save', 'submit'); } public function getName() @@ -33,8 +31,8 @@ public function getName() return 'ezdemo_feedback'; } - public function configureOptions( OptionsResolver $resolver ) + public function configureOptions(OptionsResolver $resolver) { - $resolver->setDefaults( array( 'data_class' => 'EzSystems\DemoBundle\Entity\Feedback' ) ); + $resolver->setDefaults(array('data_class' => 'EzSystems\DemoBundle\Entity\Feedback')); } } diff --git a/Form/Type/SimpleSearchType.php b/Form/Type/SimpleSearchType.php index b78e598..0450a7c 100644 --- a/Form/Type/SimpleSearchType.php +++ b/Form/Type/SimpleSearchType.php @@ -6,22 +6,20 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; class SimpleSearchType extends AbstractType { - public function buildForm( FormBuilderInterface $builder, array $options ) + public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->setMethod( 'GET' ) - ->add( 'searchText', 'search' ) - ->add( 'save', 'submit' ); + ->setMethod('GET') + ->add('searchText', 'search') + ->add('save', 'submit'); } public function getName() @@ -29,8 +27,8 @@ public function getName() return 'ezdemo_simple_search'; } - public function configureOptions( OptionsResolver $resolver ) + public function configureOptions(OptionsResolver $resolver) { - $resolver->setDefaults( array( 'data_class' => 'EzSystems\DemoBundle\Entity\SimpleSearch' ) ); + $resolver->setDefaults(array('data_class' => 'EzSystems\DemoBundle\Entity\SimpleSearch')); } } diff --git a/Helper/CriteriaHelper.php b/Helper/CriteriaHelper.php index 896e236..91d6b22 100644 --- a/Helper/CriteriaHelper.php +++ b/Helper/CriteriaHelper.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Helper; use eZ\Publish\API\Repository\Values\Content\Location; @@ -21,7 +20,7 @@ class CriteriaHelper { /** - * Generate criterion list to be used to list article + * Generate criterion list to be used to list article. * * @param \eZ\Publish\API\Repository\Values\Content\Location $location Location of the folder * @param string[] $excludeContentTypeIdentifiers Array of excluded contentType identifiers @@ -29,19 +28,19 @@ class CriteriaHelper * * @return \eZ\Publish\API\Repository\Values\Content\Query\Criterion */ - public function generateListFolderCriterion( Location $location, array $excludeContentTypeIdentifiers = array(), array $languages = array() ) + public function generateListFolderCriterion(Location $location, array $excludeContentTypeIdentifiers = array(), array $languages = array()) { $criteria = array(); - $criteria[] = new Criterion\Visibility( Criterion\Visibility::VISIBLE ); - $criteria[] = new Criterion\ParentLocationId( $location->id ); - $criteria[] = new Criterion\LogicalNot( new Criterion\ContentTypeIdentifier( $excludeContentTypeIdentifiers ) ); - $criteria[] = new Criterion\LanguageCode( $languages ); + $criteria[] = new Criterion\Visibility(Criterion\Visibility::VISIBLE); + $criteria[] = new Criterion\ParentLocationId($location->id); + $criteria[] = new Criterion\LogicalNot(new Criterion\ContentTypeIdentifier($excludeContentTypeIdentifiers)); + $criteria[] = new Criterion\LanguageCode($languages); - return new Criterion\LogicalAnd( $criteria ); + return new Criterion\LogicalAnd($criteria); } /** - * Generate criterion list to be used to list sub folder items + * Generate criterion list to be used to list sub folder items. * * @param \eZ\Publish\API\Repository\Values\Content\Location $location Location of the folder * @param string[] $includedContentTypeIdentifiers Array of included contentType identifiers @@ -49,15 +48,15 @@ public function generateListFolderCriterion( Location $location, array $excludeC * * @return \eZ\Publish\API\Repository\Values\Content\Query\Criterion */ - public function generateSubContentCriterion( Location $location, array $includedContentTypeIdentifiers = array(), array $languages = array() ) + public function generateSubContentCriterion(Location $location, array $includedContentTypeIdentifiers = array(), array $languages = array()) { $criteria = array(); - $criteria[] = new Criterion\Visibility( Criterion\Visibility::VISIBLE ); - $criteria[] = new Criterion\ContentTypeIdentifier( $includedContentTypeIdentifiers ); - $criteria[] = new Criterion\LanguageCode( $languages ); - $criteria[] = new Criterion\ParentLocationId( $location->id ); + $criteria[] = new Criterion\Visibility(Criterion\Visibility::VISIBLE); + $criteria[] = new Criterion\ContentTypeIdentifier($includedContentTypeIdentifiers); + $criteria[] = new Criterion\LanguageCode($languages); + $criteria[] = new Criterion\ParentLocationId($location->id); - return new Criterion\LogicalAnd( $criteria ); + return new Criterion\LogicalAnd($criteria); } /** @@ -67,17 +66,16 @@ public function generateSubContentCriterion( Location $location, array $included * * @return \eZ\Publish\API\Repository\Values\Content\Query\Criterion\LogicalAnd */ - public function generateContentTypeExcludeCriterion( array $excludeContentTypeIdentifiers ) + public function generateContentTypeExcludeCriterion(array $excludeContentTypeIdentifiers) { $excludeCriterion = array(); - foreach ( $excludeContentTypeIdentifiers as $contentTypeIdentifier ) - { + foreach ($excludeContentTypeIdentifiers as $contentTypeIdentifier) { $excludeCriterion[] = new Criterion\LogicalNot( - new Criterion\ContentTypeIdentifier( $contentTypeIdentifier ) + new Criterion\ContentTypeIdentifier($contentTypeIdentifier) ); } - return new Criterion\LogicalAnd( $excludeCriterion ); + return new Criterion\LogicalAnd($excludeCriterion); } /** @@ -89,26 +87,24 @@ public function generateContentTypeExcludeCriterion( array $excludeContentTypeId * * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType */ - public function generateLocationIdExcludeCriterion( array $excludeLocations ) + public function generateLocationIdExcludeCriterion(array $excludeLocations) { $excludeCriterion = array(); - foreach ( $excludeLocations as $location ) - { - if ( !$location instanceof Location ) - { - throw new InvalidArgumentType( 'excludeLocations', 'array of Location objects' ); + foreach ($excludeLocations as $location) { + if (!$location instanceof Location) { + throw new InvalidArgumentType('excludeLocations', 'array of Location objects'); } $excludeCriterion[] = new Criterion\LogicalNot( - new Criterion\LocationId( $location->id ) + new Criterion\LocationId($location->id) ); } - return new Criterion\LogicalAnd( $excludeCriterion ); + return new Criterion\LogicalAnd($excludeCriterion); } /** - * Generate criterion list to be used to list blog_posts + * Generate criterion list to be used to list blog_posts. * * @param \eZ\Publish\API\Repository\Values\Content\Location $location Location of the blog * @param array $viewParameters: View parameters of the blog view @@ -116,37 +112,34 @@ public function generateLocationIdExcludeCriterion( array $excludeLocations ) * * @return \eZ\Publish\API\Repository\Values\Content\Query\Criterion */ - public function generateListBlogPostCriterion( Location $location, array $viewParameters, array $languages = array() ) + public function generateListBlogPostCriterion(Location $location, array $viewParameters, array $languages = array()) { $criteria = array(); - $criteria[] = new Criterion\Visibility( Criterion\Visibility::VISIBLE ); - $criteria[] = new Criterion\Subtree( $location->pathString ); - $criteria[] = new Criterion\ContentTypeIdentifier( array( 'blog_post' ) ); - $criteria[] = new Criterion\LanguageCode( $languages ); + $criteria[] = new Criterion\Visibility(Criterion\Visibility::VISIBLE); + $criteria[] = new Criterion\Subtree($location->pathString); + $criteria[] = new Criterion\ContentTypeIdentifier(array('blog_post')); + $criteria[] = new Criterion\LanguageCode($languages); - if ( !empty( $viewParameters ) ) - { - if ( !empty( $viewParameters['month'] ) && !empty( $viewParameters['year'] ) ) - { + if (!empty($viewParameters)) { + if (!empty($viewParameters['month']) && !empty($viewParameters['year'])) { // Generating the criterion for the given month/year $month = (int)$viewParameters['month']; $year = (int)$viewParameters['year']; - $date = new DateTime( "$year-$month-01" ); - $date->setTime( 00, 00, 00 ); + $date = new DateTime("$year-$month-01"); + $date->setTime(00, 00, 00); $criteria[] = new Criterion\DateMetadata( Criterion\DateMetadata::CREATED, Criterion\Operator::BETWEEN, array( $date->getTimestamp(), - $date->add( new DateInterval( 'P1M' ) )->getTimestamp() + $date->add(new DateInterval('P1M'))->getTimestamp(), ) ); } } - return new Criterion\LogicalAnd( $criteria ); + return new Criterion\LogicalAnd($criteria); } - } diff --git a/Helper/EmailHelper.php b/Helper/EmailHelper.php index 262ccbd..358f35d 100644 --- a/Helper/EmailHelper.php +++ b/Helper/EmailHelper.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Helper; use EzSystems\DemoBundle\Entity\Feedback; @@ -16,7 +15,7 @@ use Symfony\Component\Translation\TranslatorInterface; /** - * Helper for emails + * Helper for emails. * * This class is meant to fulfill email related needs of the DemoBundle. * @@ -43,8 +42,7 @@ public function __construct( TranslatorInterface $translator, EngineInterface $templating, Swift_Mailer $mailer - ) - { + ) { $this->translator = $translator; $this->templating = $templating; $this->mailer = $mailer; @@ -57,13 +55,13 @@ public function __construct( * @param string $feedbackEmailFrom Email address sending feedback form * @param string $feedbackEmailTo Email address feedback forms will be sent to */ - public function sendFeebackMessage( Feedback $feedback, $feedbackEmailFrom, $feedbackEmailTo ) + public function sendFeebackMessage(Feedback $feedback, $feedbackEmailFrom, $feedbackEmailTo) { $message = Swift_Message::newInstance(); - $message->setSubject( $this->translator->trans( 'eZ Demobundle Feedback form' ) ) - ->setFrom( $feedbackEmailFrom ) - ->setTo( $feedbackEmailTo ) + $message->setSubject($this->translator->trans('eZ Demobundle Feedback form')) + ->setFrom($feedbackEmailFrom) + ->setTo($feedbackEmailTo) ->setBody( // Using template engine to generate the message based on a template $this->templating->render( @@ -74,11 +72,11 @@ public function sendFeebackMessage( Feedback $feedback, $feedbackEmailFrom, $fee 'email' => $feedback->email, 'subject' => $feedback->subject, 'country' => $feedback->country, - 'message' => $feedback->message + 'message' => $feedback->message, ) ) ); - $this->mailer->send( $message ); + $this->mailer->send($message); } } diff --git a/Helper/MenuHelper.php b/Helper/MenuHelper.php index a165d53..a7cf6bd 100644 --- a/Helper/MenuHelper.php +++ b/Helper/MenuHelper.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Helper; use eZ\Publish\API\Repository\Repository; @@ -17,7 +16,7 @@ use eZ\Publish\API\Repository\Values\Content\Query\SortClause; /** - * Helper for menus + * Helper for menus. */ class MenuHelper { @@ -38,7 +37,7 @@ class MenuHelper */ private $searchHelper; - public function __construct( Repository $repository, $defaultMenuLimit, SearchHelper $searchHelper ) + public function __construct(Repository $repository, $defaultMenuLimit, SearchHelper $searchHelper) { $this->repository = $repository; $this->defaultMenuLimit = $defaultMenuLimit; @@ -56,26 +55,27 @@ public function __construct( Repository $repository, $defaultMenuLimit, SearchHe * * @return \eZ\Publish\API\Repository\Values\Content\Location[] Location objects, indexed by their contentId. */ - public function getTopMenuContent( $topLocationId, Criterion $criterion = null ) + public function getTopMenuContent($topLocationId, Criterion $criterion = null) { $criteria = array( - new Criterion\ParentLocationId( $topLocationId ), - new Criterion\Visibility( Criterion\Visibility::VISIBLE ) + new Criterion\ParentLocationId($topLocationId), + new Criterion\Visibility(Criterion\Visibility::VISIBLE), ); - if ( !empty( $criterion ) ) + if (!empty($criterion)) { $criteria[] = $criterion; + } $query = new LocationQuery( array( - 'query' => new Criterion\LogicalAnd( $criteria ), - 'sortClauses' => array( new SortClause\Location\Priority( LocationQuery::SORT_ASC ) ) + 'query' => new Criterion\LogicalAnd($criteria), + 'sortClauses' => array(new SortClause\Location\Priority(LocationQuery::SORT_ASC)), ) ); $query->limit = $this->defaultMenuLimit; $query->performCount = false; - return $this->searchHelper->buildListFromSearchResult( $this->repository->getSearchService()->findLocations( $query ) ); + return $this->searchHelper->buildListFromSearchResult($this->repository->getSearchService()->findLocations($query)); } /** @@ -89,29 +89,30 @@ public function getTopMenuContent( $topLocationId, Criterion $criterion = null ) * * @return \eZ\Publish\API\Repository\Values\Content\Content[] */ - public function getLatestContent( Location $rootLocation, array $includeContentTypeIdentifiers = array(), Criterion $criterion = null, $limit = null ) + public function getLatestContent(Location $rootLocation, array $includeContentTypeIdentifiers = array(), Criterion $criterion = null, $limit = null) { $criteria = array( - new Criterion\Subtree( $rootLocation->pathString ), - new Criterion\Visibility( Criterion\Visibility::VISIBLE ) + new Criterion\Subtree($rootLocation->pathString), + new Criterion\Visibility(Criterion\Visibility::VISIBLE), ); - if ( $includeContentTypeIdentifiers ) - $criteria[] = new Criterion\ContentTypeIdentifier( $includeContentTypeIdentifiers ); + if ($includeContentTypeIdentifiers) { + $criteria[] = new Criterion\ContentTypeIdentifier($includeContentTypeIdentifiers); + } - if ( !empty( $criterion ) ) + if (!empty($criterion)) { $criteria[] = $criterion; + } $query = new Query( array( - 'query' => new Criterion\LogicalAnd( $criteria ), - 'sortClauses' => array( new SortClause\DatePublished( Query::SORT_DESC ) ) + 'query' => new Criterion\LogicalAnd($criteria), + 'sortClauses' => array(new SortClause\DatePublished(Query::SORT_DESC)), ) ); $query->limit = $limit ?: $this->defaultMenuLimit; $query->performCount = false; - return $this->searchHelper->buildListFromSearchResult( $this->repository->getSearchService()->findContent( $query ) ); + return $this->searchHelper->buildListFromSearchResult($this->repository->getSearchService()->findContent($query)); } - } diff --git a/Helper/PlaceHelper.php b/Helper/PlaceHelper.php index 5b8fd8b..38eda32 100644 --- a/Helper/PlaceHelper.php +++ b/Helper/PlaceHelper.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Helper; use eZ\Publish\API\Repository\SearchService; @@ -15,7 +14,7 @@ use eZ\Publish\API\Repository\Values\Content\Query\Criterion; /** - * Helper for places + * Helper for places. */ class PlaceHelper { @@ -30,14 +29,14 @@ class PlaceHelper private $searchHelper; /** - * Min distance in kilometers to display items in the place list + * Min distance in kilometers to display items in the place list. * * @var int */ private $placeListMinDist; /** - * Max distance in kilometers to display items in the place list + * Max distance in kilometers to display items in the place list. * * @var int */ @@ -48,8 +47,7 @@ public function __construct( SearchHelper $searchHelper, $placeListMinDist, $placeListMaxDist - ) - { + ) { $this->searchService = $searchService; $this->searchHelper = $searchHelper; $this->placeListMinDist = $placeListMinDist; @@ -57,7 +55,7 @@ public function __construct( } /** - * Returns all places contained in a place_list + * Returns all places contained in a place_list. * * @param \eZ\Publish\API\Repository\Values\Content\Location $location of a place_list * @param string|string[] $contentTypes to be retrieved @@ -65,21 +63,21 @@ public function __construct( * * @return \eZ\Publish\API\Repository\Values\Content\Content[] */ - public function getPlaceList( Location $location, $contentTypes, $languages = array() ) + public function getPlaceList(Location $location, $contentTypes, $languages = array()) { $query = new Query(); $query->filter = new Criterion\LogicalAnd( array( - new Criterion\ContentTypeIdentifier( $contentTypes ), - new Criterion\Subtree( $location->pathString ), - new Criterion\LanguageCode( $languages ) + new Criterion\ContentTypeIdentifier($contentTypes), + new Criterion\Subtree($location->pathString), + new Criterion\LanguageCode($languages), ) ); $query->performCount = false; - $searchResults = $this->searchService->findContent( $query ); + $searchResults = $this->searchService->findContent($query); - return $this->searchHelper->buildListFromSearchResult( $searchResults ); + return $this->searchHelper->buildListFromSearchResult($searchResults); } /** @@ -96,36 +94,35 @@ public function getPlaceList( Location $location, $contentTypes, $languages = ar * * @return \eZ\Publish\API\Repository\Values\Content\Content[] */ - public function getPlaceListSorted( Location $location, $latitude, $longitude, $contentTypes, $maxDist = null, $sortClauses = array(), $languages = array() ) + public function getPlaceListSorted(Location $location, $latitude, $longitude, $contentTypes, $maxDist = null, $sortClauses = array(), $languages = array()) { - if ( $maxDist === null ) - { + if ($maxDist === null) { $maxDist = $this->placeListMaxDist; } $query = new Query(); $query->filter = new Criterion\LogicalAnd( array( - new Criterion\ContentTypeIdentifier( $contentTypes ), - new Criterion\Subtree( $location->pathString ), - new Criterion\LanguageCode( $languages ), + new Criterion\ContentTypeIdentifier($contentTypes), + new Criterion\Subtree($location->pathString), + new Criterion\LanguageCode($languages), new Criterion\MapLocationDistance( - "location", + 'location', Criterion\Operator::BETWEEN, array( $this->placeListMinDist, - $maxDist + $maxDist, ), $latitude, $longitude - ) + ), ) ); $query->sortClauses = $sortClauses; $query->performCount = false; - $searchResults = $this->searchService->findContent( $query ); + $searchResults = $this->searchService->findContent($query); - return $this->searchHelper->buildListFromSearchResult( $searchResults ); + return $this->searchHelper->buildListFromSearchResult($searchResults); } } diff --git a/Helper/SearchHelper.php b/Helper/SearchHelper.php index 2cb982f..5b7d23d 100644 --- a/Helper/SearchHelper.php +++ b/Helper/SearchHelper.php @@ -6,7 +6,6 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ - namespace EzSystems\DemoBundle\Helper; use eZ\Publish\API\Repository\Values\Content\Search\SearchResult; @@ -17,7 +16,7 @@ use eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchAdapter; /** - * Helper for searches + * Helper for searches. */ class SearchHelper { @@ -31,14 +30,14 @@ class SearchHelper */ private $searchListLimit; - public function __construct( SearchService $searchService, $searchListLimit ) + public function __construct(SearchService $searchService, $searchListLimit) { $this->searchService = $searchService; $this->searchListLimit = $searchListLimit; } /** - * Search for content for a given $searchText and returns a pager + * Search for content for a given $searchText and returns a pager. * * @param string $searchText to be looked up * @param int $currentPage to be displayed @@ -46,24 +45,24 @@ public function __construct( SearchService $searchService, $searchListLimit ) * * @return \Pagerfanta\Pagerfanta */ - public function searchForPaginatedContent( $searchText, $currentPage, $languages ) + public function searchForPaginatedContent($searchText, $currentPage, $languages) { // Generating query $query = new Query(); - $query->query = new Criterion\FullText( $searchText ); + $query->query = new Criterion\FullText($searchText); $query->filter = new Criterion\LogicalAnd( array( - new Criterion\Visibility( Criterion\Visibility::VISIBLE ), - new Criterion\LanguageCode( $languages, true ) + new Criterion\Visibility(Criterion\Visibility::VISIBLE), + new Criterion\LanguageCode($languages, true), ) ); // Initialize pagination. $pager = new Pagerfanta( - new ContentSearchAdapter( $query, $this->searchService ) + new ContentSearchAdapter($query, $this->searchService) ); - $pager->setMaxPerPage( $this->searchListLimit ); - $pager->setCurrentPage( $currentPage ); + $pager->setMaxPerPage($this->searchListLimit); + $pager->setCurrentPage($currentPage); return $pager; } @@ -76,11 +75,10 @@ public function searchForPaginatedContent( $searchText, $currentPage, $languages * * @return array */ - public function buildListFromSearchResult( SearchResult $searchResult ) + public function buildListFromSearchResult(SearchResult $searchResult) { $list = array(); - foreach ( $searchResult->searchHits as $searchHit ) - { + foreach ($searchResult->searchHits as $searchHit) { $list[$searchHit->valueObject->id] = $searchHit->valueObject; } diff --git a/Installer/DemoCleanInstaller.php b/Installer/DemoCleanInstaller.php index 6f43432..1e71674 100644 --- a/Installer/DemoCleanInstaller.php +++ b/Installer/DemoCleanInstaller.php @@ -1,6 +1,6 @@ output->writeln( "Copying storage directory contents..." ); + $this->output->writeln('Copying storage directory contents...'); $fs = new Filesystem(); - $fs->mkdir( 'web/var/ezdemo_site' ); + $fs->mkdir('web/var/ezdemo_site'); $fs->mirror( 'vendor/ezsystems/demobundle-data/data/storage', 'web/var/ezdemo_site/storage' diff --git a/Menu/Builder.php b/Menu/Builder.php index c79bbfc..dcfce2c 100644 --- a/Menu/Builder.php +++ b/Menu/Builder.php @@ -1,6 +1,6 @@ factory = $factory; $this->searchService = $searchService; $this->router = $router; @@ -79,13 +78,13 @@ public function __construct( $this->translationHelper = $translationHelper; } - public function createTopMenu( Request $request ) + public function createTopMenu(Request $request) { - $menu = $this->factory->createItem( 'root' ); + $menu = $this->factory->createItem('root'); $this->addLocationsToMenu( $menu, $this->getMenuItems( - $this->configResolver->getParameter( 'content.tree_root.location_id' ) + $this->configResolver->getParameter('content.tree_root.location_id') ) ); @@ -93,62 +92,60 @@ public function createTopMenu( Request $request ) } /** - * Adds locations from $searchHit to $menu + * Adds locations from $searchHit to $menu. * * @param ItemInterface $menu * @param SearchHit[] $searchHits - * @return void */ - private function addLocationsToMenu( ItemInterface $menu, array $searchHits ) + private function addLocationsToMenu(ItemInterface $menu, array $searchHits) { - foreach ( $searchHits as $searchHit ) - { + foreach ($searchHits as $searchHit) { /** @var Location $location */ $location = $searchHit->valueObject; - $menuItem = isset( $menu[$location->parentLocationId] ) ? $menu[$location->parentLocationId] : $menu; + $menuItem = isset($menu[$location->parentLocationId]) ? $menu[$location->parentLocationId] : $menu; $menuItem->addChild( $location->id, array( - 'label' => $this->translationHelper->getTranslatedContentNameByContentInfo( $location->contentInfo ), - 'uri' => $this->router->generate( $location ), - 'attributes' => array( 'id' => 'nav-location-' . $location->id ) + 'label' => $this->translationHelper->getTranslatedContentNameByContentInfo($location->contentInfo), + 'uri' => $this->router->generate($location), + 'attributes' => array('id' => 'nav-location-' . $location->id), ) ); - $menuItem->setChildrenAttribute( 'class', 'nav' ); + $menuItem->setChildrenAttribute('class', 'nav'); } } /** - * Queries the repository for menu items, as locations filtered on the list in TopIdentifierList in menu.ini + * Queries the repository for menu items, as locations filtered on the list in TopIdentifierList in menu.ini. * @param int|string $rootLocationId Root location for menu items. Only two levels below this one are searched * @return SearchHit[] */ - private function getMenuItems( $rootLocationId ) + private function getMenuItems($rootLocationId) { - $rootLocation = $this->locationService->loadLocation( $rootLocationId ); + $rootLocation = $this->locationService->loadLocation($rootLocationId); $query = new LocationQuery(); $query->query = new Criterion\LogicalAnd( array( - new Criterion\ContentTypeIdentifier( $this->getTopMenuContentTypeIdentifierList() ), - new Criterion\Visibility( Criterion\Visibility::VISIBLE ), + new Criterion\ContentTypeIdentifier($this->getTopMenuContentTypeIdentifierList()), + new Criterion\Visibility(Criterion\Visibility::VISIBLE), new Criterion\Location\Depth( Criterion\Operator::BETWEEN, - array( $rootLocation->depth + 1, $rootLocation->depth + 2 ) + array($rootLocation->depth + 1, $rootLocation->depth + 2) ), - new Criterion\Subtree( $rootLocation->pathString ), - new Criterion\LanguageCode( $this->configResolver->getParameter( 'languages' ) ) + new Criterion\Subtree($rootLocation->pathString), + new Criterion\LanguageCode($this->configResolver->getParameter('languages')), ) ); - $query->sortClauses = array( new Query\SortClause\Location\Path() ); + $query->sortClauses = array(new Query\SortClause\Location\Path()); $query->performCount = false; - return $this->searchService->findLocations( $query )->searchHits; + return $this->searchService->findLocations($query)->searchHits; } private function getTopMenuContentTypeIdentifierList() { - return $this->configResolver->getParameter( 'MenuContentSettings.TopIdentifierList', 'menu' ); + return $this->configResolver->getParameter('MenuContentSettings.TopIdentifierList', 'menu'); } } diff --git a/PremiumContent/PremiumLocationViewProvider.php b/PremiumContent/PremiumLocationViewProvider.php index 7b1cfe0..b1aa177 100644 --- a/PremiumContent/PremiumLocationViewProvider.php +++ b/PremiumContent/PremiumLocationViewProvider.php @@ -1,6 +1,6 @@ repository = $repository; $this->premiumSectionId = $premiumSectionId; $this->subscriptionChecker = $subscriptionChecker; } - public function getView( Location $location, $viewType ) + public function getView(Location $location, $viewType) { - if ( $viewType !== 'full' ) - { + if ($viewType !== 'full') { return null; } - if ( $location->getContentInfo()->sectionId !== $this->premiumSectionId ) - { + if ($location->getContentInfo()->sectionId !== $this->premiumSectionId) { return null; } - if ( $this->subscriptionChecker->userIsSubscriber( $this->repository->getCurrentUser() ) ) - { + if ($this->subscriptionChecker->userIsSubscriber($this->repository->getCurrentUser())) { return null; } - return new ContentView( "eZDemoBundle:$viewType:premium_content.html.twig" ); + return new ContentView("eZDemoBundle:$viewType:premium_content.html.twig"); } } diff --git a/PremiumContent/PremiumSubscriptionChecker.php b/PremiumContent/PremiumSubscriptionChecker.php index 15a9dc3..5560d4b 100644 --- a/PremiumContent/PremiumSubscriptionChecker.php +++ b/PremiumContent/PremiumSubscriptionChecker.php @@ -1,6 +1,6 @@ repository = $repository; $this->roleId = $subscriberRoleId; } - public function userIsSubscriber( User $user ) + public function userIsSubscriber(User $user) { $roleService = $this->repository->getRoleService(); + return $this->repository->sudo( - function ( Repository $repository ) use ( $user, $roleService ) - { - foreach ( $repository->getUserService()->loadUserGroupsOfUser( $user ) as $group ) - { - foreach ( $roleService->getRoleAssignmentsForUserGroup( $group ) as $role ) - { - if ( $this->isSubscriberRole( $role->role ) ) - { + function (Repository $repository) use ($user, $roleService) { + foreach ($repository->getUserService()->loadUserGroupsOfUser($user) as $group) { + foreach ($roleService->getRoleAssignmentsForUserGroup($group) as $role) { + if ($this->isSubscriberRole($role->role)) { return true; } } } + return false; } ); } - public function isSubscriberRole( Role $role ) + public function isSubscriberRole(Role $role) { return $role->id === $this->roleId; }