/**
  * Find category tree
  *
  * @param array $rootIdList list of id s
  * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
  */
 public function findTree(array $rootIdList)
 {
     $subCategories = Tx_News_Service_CategoryService::getChildrenCategories(implode(',', $rootIdList));
     $ordering = array('sorting' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING);
     $categories = $this->findByIdList(explode(',', $subCategories), $ordering);
     $flatCategories = array();
     foreach ($categories as $category) {
         $flatCategories[$category->getUid()] = array('item' => $category, 'parent' => $category->getParentcategory() ? $category->getParentcategory()->getUid() : NULL);
     }
     $tree = array();
     // If leaves are selected without its parents selected, those are shown as parent
     foreach ($flatCategories as $id => &$flatCategory) {
         if (!isset($flatCategories[$flatCategory['parent']])) {
             $flatCategory['parent'] = NULL;
         }
     }
     foreach ($flatCategories as $id => &$node) {
         if ($node['parent'] === NULL) {
             $tree[$id] =& $node;
         } else {
             $flatCategories[$node['parent']]['children'][$id] =& $node;
         }
     }
     return $tree;
 }
 /**
  * Builds a complete node including children
  *
  * @param \TYPO3\CMS\Backend\Tree\TreeNode|\TYPO3\CMS\Backend\Tree\TreeNode $basicNode
  * @param NULL|\TYPO3\CMS\Core\Tree\TableConfiguration\DatabaseTreeNode $parent
  * @param integer $level
  * @param bool $restriction
  * @return \TYPO3\CMS\Core\Tree\TableConfiguration\DatabaseTreeNode node
  */
 protected function buildRepresentationForNode(\TYPO3\CMS\Backend\Tree\TreeNode $basicNode, \TYPO3\CMS\Core\Tree\TableConfiguration\DatabaseTreeNode $parent = NULL, $level = 0, $restriction = FALSE)
 {
     /**@param $node \TYPO3\CMS\Core\Tree\TableConfiguration\DatabaseTreeNode */
     $node = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Tree\\TableConfiguration\\DatabaseTreeNode');
     $row = array();
     if ($basicNode->getId() == 0) {
         $node->setSelected(FALSE);
         $node->setExpanded(TRUE);
         $node->setLabel($GLOBALS['LANG']->sL($GLOBALS['TCA'][$this->tableName]['ctrl']['title']));
     } else {
         $row = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL($this->tableName, $basicNode->getId(), '*', '', FALSE);
         if ($this->getLabelField() !== '') {
             $label = Tx_News_Service_CategoryService::translateCategoryRecord($row[$this->getLabelField()], $row);
             $node->setLabel($label);
         } else {
             $node->setLabel($basicNode->getId());
         }
         $node->setSelected(\TYPO3\CMS\Core\Utility\GeneralUtility::inList($this->getSelectedList(), $basicNode->getId()));
         $node->setExpanded($this->isExpanded($basicNode));
         $node->setLabel($node->getLabel());
     }
     $node->setId($basicNode->getId());
     // Break to force single category activation
     if ($parent != NULL && $level != 0 && $this->isSingleCategoryAclActivated() && !$this->isCategoryAllowed($node)) {
         return NULL;
     }
     $node->setSelectable(!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($this->getNonSelectableLevelList(), $level) && !in_array($basicNode->getId(), $this->getItemUnselectableList()));
     $node->setSortValue($this->nodeSortValues[$basicNode->getId()]);
     $node->setIcon(\TYPO3\CMS\Backend\Utility\IconUtility::mapRecordTypeToSpriteIconClass($this->tableName, $row));
     $node->setParentNode($parent);
     if ($basicNode->hasChildNodes()) {
         $node->setHasChildren(TRUE);
         /** @var \TYPO3\CMS\Backend\Tree\SortedTreeNodeCollection $childNodes */
         $childNodes = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\SortedTreeNodeCollection');
         $foundSomeChild = FALSE;
         foreach ($basicNode->getChildNodes() as $child) {
             // Change in custom TreeDataProvider by adding the if clause
             if ($restriction || $this->isCategoryAllowed($child)) {
                 $returnedChild = $this->buildRepresentationForNode($child, $node, $level + 1, TRUE);
                 if (!is_null($returnedChild)) {
                     $foundSomeChild = TRUE;
                     $childNodes->append($returnedChild);
                 } else {
                     $node->setParentNode(NULL);
                     $node->setHasChildren(FALSE);
                 }
             }
             // Change in custom TreeDataProvider end
         }
         if ($foundSomeChild) {
             $node->setChildNodes($childNodes);
         }
     }
     return $node;
 }
Пример #3
0
 /**
  * Generate additional label for category records
  * including the title of the parent category
  *
  * @param array $params
  * @return void
  */
 public function getUserLabelCategory(array &$params)
 {
     // In list view: show normal label
     $listView = strpos(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'), 'typo3/sysext/list/mod1/db_list.php') || strpos(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'), 'typo3/mod.php?&M=web_list') || strpos(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'), 'typo3/mod.php?M=web_list');
     // No overlay if language of category is not base or no language yet selected
     if ($listView || !is_array($params['row'])) {
         $params['title'] = $params['row']['title'];
     } else {
         $params['title'] = Tx_News_Service_CategoryService::translateCategoryRecord($params['row']['title'], $params['row']);
     }
 }
 /**
  * Returns a category constraint created by
  * a given list of categories and a junction string
  *
  * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
  * @param  array $categories
  * @param  string $conjunction
  * @param  boolean $includeSubCategories
  * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface|null
  */
 protected function createCategoryConstraint(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query, $categories, $conjunction, $includeSubCategories = FALSE)
 {
     $constraint = NULL;
     $categoryConstraints = array();
     // If "ignore category selection" is used, nothing needs to be done
     if (empty($conjunction)) {
         return $constraint;
     }
     if (!is_array($categories)) {
         $categories = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $categories, TRUE);
     }
     foreach ($categories as $category) {
         if ($includeSubCategories) {
             $subCategories = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', Tx_News_Service_CategoryService::getChildrenCategories($category, 0, '', TRUE), TRUE);
             $subCategoryConstraint = array();
             $subCategoryConstraint[] = $query->contains('categories', $category);
             if (count($subCategories) > 0) {
                 foreach ($subCategories as $subCategory) {
                     $subCategoryConstraint[] = $query->contains('categories', $subCategory);
                 }
             }
             if ($subCategoryConstraint) {
                 $categoryConstraints[] = $query->logicalOr($subCategoryConstraint);
             }
         } else {
             $categoryConstraints[] = $query->contains('categories', $category);
         }
     }
     if ($categoryConstraints) {
         switch (strtolower($conjunction)) {
             case 'or':
                 $constraint = $query->logicalOr($categoryConstraints);
                 break;
             case 'notor':
                 $constraint = $query->logicalNot($query->logicalOr($categoryConstraints));
                 break;
             case 'notand':
                 $constraint = $query->logicalNot($query->logicalAnd($categoryConstraints));
                 break;
             case 'and':
             default:
                 $constraint = $query->logicalAnd($categoryConstraints);
         }
     }
     return $constraint;
 }
Пример #5
0
 /**
  * @test
  * @dataProvider removeValuesFromStringDataProvider
  */
 public function removeValuesFromString($expected, $given)
 {
     $result = Tx_News_Service_CategoryService::removeValuesFromString($given[0], $given[1]);
     $this->assertEquals($expected, $result);
 }