Example #1
0
 /**
  * Checks if a Location object matches.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  *
  * @return bool
  */
 public function matchLocation(Location $location)
 {
     $section = $this->repository->sudo(function (Repository $repository) use($location) {
         return $repository->getSectionService()->loadSection($location->getContentInfo()->sectionId);
     });
     return isset($this->values[$section->identifier]);
 }
 public function getView(Location $location, $viewType)
 {
     if ($viewType !== 'full') {
         return null;
     }
     if ($location->getContentInfo()->sectionId !== $this->premiumSectionId) {
         return null;
     }
     if ($this->subscriptionChecker->userIsSubscriber($this->repository->getCurrentUser())) {
         return null;
     }
     return new ContentView("eZDemoBundle:{$viewType}:premium_content.html.twig");
 }
Example #3
0
 /**
  * Magic isset for signaling existence of convenience properties
  *
  * @param string $property
  *
  * @return boolean
  */
 public function __isset($property)
 {
     if ($property === 'contentId' || $property === 'path') {
         return true;
     }
     return parent::__isset($property);
 }
Example #4
0
 /**
  * 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)
 {
     $response = new Response();
     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');
     $content = $this->getRepository()->getContentService()->loadContentByContentInfo($location->getContentInfo());
     // Getting language for the current siteaccess
     $languages = $this->getConfigResolver()->getParameter('languages');
     $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($location, $excludedContentTypes, $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($location, $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;
     }
     return $this->get('ez_content')->viewLocation($location->id, 'full', true, ['pagerFolder' => $pager, 'treeItems' => $treeItems]);
 }
 /**
  * Checks if a Location object matches.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  *
  * @return boolean
  */
 public function matchLocation(Location $location)
 {
     $contentType = $this->repository->getContentTypeService()->loadContentType($location->getContentInfo()->contentTypeId);
     return isset($this->values[$contentType->identifier]);
 }
Example #6
0
 /**
  * Checks if a Location object matches.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  *
  * @return boolean
  */
 public function matchLocation(APILocation $location)
 {
     return isset($this->values[$location->getContentInfo()->id]);
 }
 /**
  * Searches children locations of the provided parent location id.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  * @param int $offset
  * @param int $limit
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult
  */
 protected function searchChildrenLocations(APILocation $location, $offset = 0, $limit = -1)
 {
     $query = new LocationQuery(['filter' => new Criterion\ParentLocationId($location->id), 'offset' => $offset >= 0 ? (int) $offset : 0, 'limit' => $limit >= 0 ? (int) $limit : null, 'sortClauses' => $location->getSortClauses()]);
     return $this->repository->getSearchService()->findLocations($query);
 }
 /**
  * Get the translated field from a content object
  * 
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  * @param string $fieldIdentifier
  * @return \eZ\Publish\API\Repository\Values\Content\Field
  */
 protected function getTranslatedLocationFieldValue($location, $fieldIdentifier)
 {
     $content = $this->getRepository()->getContentService()->loadContentByContentInfo($location->getContentInfo());
     return $this->getTranslatedContentFieldValue($content, $fieldIdentifier);
 }
 /**
  * Returns the content info of the content object of this location
  *
  * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo
  */
 public function getContentInfo()
 {
     return $this->location->getContentInfo();
 }
 /**
  * Internal helper method used to recover a location tree.
  *
  * @access private
  *
  * @internal
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  * @param \eZ\Publish\API\Repository\Values\Content\Location $newParentlocation
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Location
  */
 public function recoverLocation(Location $location, Location $newParentlocation = null)
 {
     if ($newParentlocation) {
         $location->setParentLocationId($newParentlocation->id);
     }
     $location->setDepth($this->locations[$location->parentLocationId]->depth + 1);
     $location->setPathString($this->locations[$location->parentLocationId]->pathString . $location->id . "/");
     // If the main location of the restored content is also trashed /
     // deleted
     if (!isset($this->locations[$location->getContentInfo()->mainLocationId])) {
         $location->getContentInfo()->setMainLocationId($location->id);
     }
     $this->repository->getUrlAliasService()->createAliasesForLocation($location);
     return $this->locations[$location->id] = $location;
 }
 /**
  * Checks if a Location object matches.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  *
  * @return boolean
  */
 public function matchLocation(APILocation $location)
 {
     return $this->matchContentInfo($location->getContentInfo());
 }
 /**
  * Auto-generates aliases for the given $location
  *
  * Old aliases will automatically be moved to history mode.
  *
  * ATTENTION: This method is not part of the Public API but is only used
  * internally in this implementation.
  *
  * @access private
  *
  * @internal
  *
  * @param Location $location
  *
  * @return void
  */
 public function createAliasesForLocation(Location $location)
 {
     $contentService = $this->repository->getContentService();
     $content = $contentService->loadContent($location->getContentInfo()->id);
     if ($content->getVersionInfo()->status !== VersionInfo::STATUS_PUBLISHED) {
         // Skip not yet published content
         return;
     }
     $versionInfo = $content->getVersionInfo();
     $contentInfo = $versionInfo->getContentInfo();
     $this->obsoleteOldAliases($location);
     foreach ($versionInfo->getNames() as $languageCode => $name) {
         $this->createInternalUrlAlias($location, $this->createUrlAliasPath($location, $name, $languageCode), $languageCode, $contentInfo->mainLanguageCode === $languageCode && $contentInfo->alwaysAvailable);
     }
 }
Example #13
0
 /**
  * Action used to display a blog_post
  *  - Adds the content's author to the response.
  * Note: This is a partly customized controller action. It is executed just before the original
  *       Viewcontroller's viewLocation method. To be able to do that, we need to implement it's
  *       full signature.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location of the blog post
  * @param $viewType
  * @param bool $layout
  * @param array $params
  * @return \Symfony\Component\HttpFoundation\Response
  */
 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);
     // 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($location->id, $viewType, $layout, array('author' => $author) + $params);
 }
 /**
  * Returns (searches) subgroups of a user group described by its main location.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  * @param int $offset
  * @param int $limit
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult
  */
 protected function searchSubGroups(Location $location, $offset = 0, $limit = 25)
 {
     $searchQuery = new LocationQuery();
     $searchQuery->offset = $offset;
     $searchQuery->limit = $limit;
     $searchQuery->filter = new CriterionLogicalAnd([new CriterionContentTypeId($this->settings['userGroupClassID']), new CriterionParentLocationId($location->id)]);
     $searchQuery->sortClauses = $location->getSortClauses();
     return $this->repository->getSearchService()->findLocations($searchQuery, array(), false);
 }