getCategories() public method

Determine categories from current request.
public getCategories ( string $categoriesParameter = 'categories' ) : string[]
$categoriesParameter string
return string[]
Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getContentData(PropertyInterface $property)
 {
     // check memoize
     $hash = spl_object_hash($property);
     if (array_key_exists($hash, $this->cache)) {
         return $this->cache[$hash];
     }
     /** @var PropertyParameter[] $params */
     $params = array_merge($this->getDefaultParams($property), $property->getParams());
     // prepare filters
     $filters = $property->getValue();
     $filters['excluded'] = [$property->getStructure()->getUuid()];
     // default value of tags/category is an empty array
     if (!array_key_exists('tags', $filters)) {
         $filters['tags'] = [];
     }
     if (!array_key_exists('categories', $filters)) {
         $filters['categories'] = [];
     }
     // extends selected filter with requested tags
     $filters['websiteTags'] = $this->tagRequestHandler->getTags($params['tags_parameter']->getValue());
     $filters['websiteTagsOperator'] = $params['website_tags_operator']->getValue();
     // extends selected filter with requested categories
     $filters['websiteCategories'] = $this->categoryRequestHandler->getCategories($params['categories_parameter']->getValue());
     $filters['websiteCategoriesOperator'] = $params['website_categories_operator']->getValue();
     // resolve tags to id
     if (!empty($filters['tags'])) {
         $filters['tags'] = $this->tagManager->resolveTagNames($filters['tags']);
     }
     // resolve website tags to id
     if (!empty($filters['websiteTags'])) {
         $filters['websiteTags'] = $this->tagManager->resolveTagNames($filters['websiteTags']);
     }
     // get provider
     $provider = $this->getProvider($property);
     $configuration = $provider->getConfiguration();
     // prepare pagination, limitation and options
     $page = 1;
     $limit = array_key_exists('limitResult', $filters) && $configuration->hasLimit() ? $filters['limitResult'] : null;
     $options = ['webspaceKey' => $property->getStructure()->getWebspaceKey(), 'locale' => $property->getStructure()->getLanguageCode()];
     if (isset($params['max_per_page']) && $configuration->hasPagination()) {
         // is paginated
         $page = $this->getCurrentPage($params['page_parameter']->getValue());
         $pageSize = intval($params['max_per_page']->getValue());
         // resolve paginated filters
         $data = $provider->resolveResourceItems($filters, $params, $options, !empty($limit) ? intval($limit) : null, $page, $pageSize);
     } else {
         $data = $provider->resolveResourceItems($filters, $params, $options, !empty($limit) ? intval($limit) : null);
     }
     // append view data
     $filters['page'] = $page;
     $filters['hasNextPage'] = $data->getHasNextPage();
     $filters['referencedUuids'] = $data->getReferencedUuids();
     $filters['paginated'] = $configuration->hasPagination();
     $property->setValue($filters);
     // save result in cache
     return $this->cache[$hash] = $data->getItems();
 }
Example #2
0
 public function setUp()
 {
     $this->contentDataProvider = $this->prophesize(DataProviderInterface::class);
     $this->contentDataProvider->getConfiguration()->willReturn($this->getProviderConfiguration());
     $this->contentDataProvider->getDefaultPropertyParameter()->willReturn([]);
     $this->dataProviderPool = new DataProviderPool();
     $this->dataProviderPool->add('content', $this->contentDataProvider->reveal());
     $this->tagManager = $this->getMockForAbstractClass(TagManagerInterface::class, [], '', false, true, true, ['resolveTagIds', 'resolveTagNames']);
     $this->requestStack = $this->getMockBuilder(RequestStack::class)->getMock();
     $this->request = $this->getMockBuilder(Request::class)->getMock();
     $this->requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue($this->request));
     $this->tagRequestHandler = $this->prophesize(TagRequestHandlerInterface::class);
     $this->tagRequestHandler->getTags('tags')->willReturn([]);
     $this->categoryRequestHandler = $this->prophesize(CategoryRequestHandlerInterface::class);
     $this->categoryRequestHandler->getCategories('categories')->willReturn([]);
     $this->smartContent = new SmartContent($this->dataProviderPool, $this->tagManager, $this->requestStack, $this->tagRequestHandler->reveal(), $this->categoryRequestHandler->reveal(), 'SuluContentBundle:Template:content-types/smart_content.html.twig');
     $this->tagManager->expects($this->any())->method('resolveTagIds')->will($this->returnValueMap([[[1, 2], ['Tag1', 'Tag2']]]));
     $this->tagManager->expects($this->any())->method('resolveTagName')->will($this->returnValueMap([[['Tag1', 'Tag2'], [1, 2]]]));
 }