/** * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface */ protected function getCategories() { $categories = $this->categoryService->getSubCategories($this->settings['categories']); $categories = GeneralUtility::removeArrayEntryByValue($categories, $this->settings['categories']); $query = $this->categoryRepository->createQuery(); $query->getQuerySettings()->setRespectStoragePage(false); $constraints = []; $constraints[] = $query->in('uid', $categories); $query->matching($query->logicalAnd($constraints)); return $query->execute(); }
/** * @param string|array $categories categories either string (comma separated) or list of uids as array (can be null) * @param string|integer $pid parent page id containing categories * @param string $as render as variable instead of returning array directly * @param boolean $firstOnly if true return only first record * @param boolean $titleOnly if true return titles only (either array or string if firstOnly set) * @return array|string|\TYPO3\CMS\Extbase\Domain\Model\Category array of categories (if as is set) or output or single entry */ public function render($categories = NULL, $pid = NULL, $as = NULL, $firstOnly = FALSE, $titleOnly = FALSE) { if (!empty($categories)) { // explode if string if (is_string($categories)) { $categories = explode(',', $categories); } } else { $categories = NULL; } // page id if (!empty($pid)) { $pid = intval($pid); } // define contain array $contain = array(); // get categories $query = $this->categoryRepository->createQuery(); if (!empty($categories)) { $contain[] = $query->in('uid', $categories); } if (!empty($pid)) { $contain[] = $query->equals('pid', $pid); } if ($titleOnly) { $query->setLimit(1); } // any filters? if (!empty($contain)) { $query->matching($query->logicalAnd($contain)); } // Ignore storage space $query->getQuerySettings()->setRespectStoragePage(false); $categoriesFound = $query->execute(); // nothing found? if ($categoriesFound->count() == 0) { $categoriesFound = NULL; } if ($categoriesFound != null) { if ($firstOnly) { $categoriesFound = $categoriesFound->getFirst(); // title only? /** * @var \TYPO3\CMS\Extbase\Domain\Model\Category $categoriesFound */ if ($titleOnly) { $categoriesFound = $categoriesFound->getTitle(); } } elseif ($titleOnly) { $titles = array(); /** * @var \TYPO3\CMS\Extbase\Domain\Model\Category $category */ foreach ($categoriesFound as $category) { $titles[] = $category->getTitle(); } $categoriesFound = $titles; } } // return directly if (empty($as)) { return $categoriesFound; } $this->templateVariableContainer->add($as, $categoriesFound); $output = $this->renderChildren(); $this->templateVariableContainer->remove($as); return $output; }