/**
  * Returns the node in an array representation that can be used for serialization
  *
  * @param bool $addChildNodes
  * @return array
  */
 public function toArray($addChildNodes = TRUE)
 {
     $arrayRepresentation = array('serializeClassName' => get_class($this), 'id' => $this->id);
     if ($this->parentNode !== NULL) {
         $arrayRepresentation['parentNode'] = $this->parentNode->toArray(FALSE);
     } else {
         $arrayRepresentation['parentNode'] = '';
     }
     if ($this->hasChildNodes() && $addChildNodes) {
         $arrayRepresentation['childNodes'] = $this->childNodes->toArray();
     } else {
         $arrayRepresentation['childNodes'] = '';
     }
     return $arrayRepresentation;
 }
 /**
  * Builds a complete node including children
  *
  * @param \t3lib_tree_Node|\TYPO3\CMS\Backend\Tree\TreeNode $basicNode
  * @param NULL|t3lib_tree_tca_DatabaseNode $parent
  * @param integer $level
  * @param bool $restriction
  * @return t3lib_tree_tca_DatabaseNode node
  */
 protected function buildRepresentationForNode(t3lib_tree_Node $basicNode, t3lib_tree_tca_DatabaseNode $parent = NULL, $level = 0, $restriction = FALSE)
 {
     /**@param $node t3lib_tree_tca_DatabaseNode */
     $node = t3lib_div::makeInstance('t3lib_tree_tca_DatabaseNode');
     $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 = t3lib_BEfunc::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(t3lib_div::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(!t3lib_div::inList($this->getNonSelectableLevelList(), $level) && !in_array($basicNode->getId(), $this->getItemUnselectableList()));
     $node->setSortValue($this->nodeSortValues[$basicNode->getId()]);
     $node->setIcon(t3lib_iconWorks::mapRecordTypeToSpriteIconClass($this->tableName, $row));
     $node->setParentNode($parent);
     if ($basicNode->hasChildNodes()) {
         $node->setHasChildren(TRUE);
         $childNodes = t3lib_div::makeInstance('t3lib_tree_SortedNodeCollection');
         $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;
 }
 /**
  * Compares a node with another one
  *
  * @noapi
  * @see t3lib_tree_Node::compareTo
  * @return void
  */
 public function nodeCompare(t3lib_tree_Node $node, t3lib_tree_Node $otherNode)
 {
     return $node->compareTo($otherNode);
 }
 /**
  * Sets data of the node by a given data array
  *
  * @param array $data
  * @return void
  */
 public function dataFromArray($data)
 {
     parent::dataFromArray($data);
     $this->setType($data['type']);
     $this->setText($data['label'], $data['t3TextSourceField'], $data['prefix'], $data['suffix']);
     $this->setEditableText($data['editableText']);
     $this->setCls($data['cls']);
     $this->setQTip($data['qtip']);
     $this->setExpanded($data['expanded']);
     $this->setExpandable($data['expandable']);
     $this->setDraggable($data['draggable']);
     $this->setIsDropTarget($data['isTarget']);
     $this->setSpriteIconCode($data['spriteIconCode']);
     $this->setInCopyMode($data['t3InCopyMode']);
     $this->setInCutMode($data['t3InCutMode']);
     $this->setContextInfo($data['t3ContextInfo']);
     $this->setLabelIsEditable($data['editable']);
     $this->setAllowChildren($data['allowChildren']);
     // only set the leaf attribute if it's applied
     // otherwise you cannot insert nodes into this one
     if (isset($data['leaf'])) {
         $this->setLeaf(FALSE);
     }
 }
 /**
  * Sets data of the node by a given data array
  *
  * @param array $data
  * @return void
  */
 public function dataFromArray($data)
 {
     parent::dataFromArray($data);
     $this->setLabel($data['label']);
     $this->setType($data['type']);
     $this->setClass($data['class']);
     $this->setIcon($data['icon']);
     $this->setCallbackAction($data['callbackAction']);
 }
 /**
  * Gets the expanded state of a given node
  *
  * @param t3lib_tree_AbstractNode $node
  * @return bool
  */
 protected function isExpanded(t3lib_tree_Node $node)
 {
     return $this->getExpandAll() || t3lib_div::inList($this->expandedList, $node->getId());
 }
 /**
  * Returns a node collection of filtered nodes
  *
  * @param t3lib_tree_Node $node
  * @param string $searchFilter
  * @param int $mountPoint
  * @return void
  */
 public function getFilteredNodes(t3lib_tree_Node $node, $searchFilter, $mountPoint = 0)
 {
     /** @var $nodeCollection t3lib_tree_pagetree_NodeCollection */
     $nodeCollection = t3lib_div::makeInstance('t3lib_tree_pagetree_NodeCollection');
     $records = $this->getSubpages(-1, $searchFilter);
     if (!is_array($records) || !count($records)) {
         return $nodeCollection;
     }
     $isNumericSearchFilter = is_numeric($searchFilter) && $searchFilter > 0;
     $nodeId = intval($node->getId());
     foreach ($records as $record) {
         $record = t3lib_tree_pagetree_Commands::getNodeRecord($record['uid']);
         if (intval($record['pid']) === -1 || in_array($record['uid'], $this->hiddenRecords)) {
             continue;
         }
         $rootline = t3lib_BEfunc::BEgetRootLine($record['uid'], ' AND uid != ' . $nodeId);
         $rootline = array_reverse($rootline);
         if ($nodeId === 0) {
             array_shift($rootline);
         }
         $reference = $nodeCollection;
         $inFilteredRootline = FALSE;
         $amountOfRootlineElements = count($rootline);
         for ($i = 0; $i < $amountOfRootlineElements; ++$i) {
             $rootlineElement = $rootline[$i];
             if (intval($rootlineElement['pid']) === $nodeId) {
                 $inFilteredRootline = TRUE;
             }
             if (!$inFilteredRootline) {
                 continue;
             }
             $rootlineElement = t3lib_tree_pagetree_Commands::getNodeRecord($rootlineElement['uid']);
             $ident = intval($rootlineElement['sorting']) . intval($rootlineElement['uid']);
             if ($reference->offsetExists($ident)) {
                 /** @var $refNode t3lib_tree_pagetree_Node */
                 $refNode = $reference->offsetGet($ident);
                 $refNode->setExpanded(TRUE);
                 $refNode->setLeaf(FALSE);
                 $reference = $refNode->getChildNodes();
                 continue;
             }
             $refNode = t3lib_tree_pagetree_Commands::getNewNode($rootlineElement, $mountPoint);
             $replacement = '<span class="typo3-pagetree-filteringTree-highlight">$1</span>';
             if ($isNumericSearchFilter && intval($rootlineElement['uid']) === intval($searchFilter)) {
                 $text = str_replace('$1', $refNode->getText(), $replacement);
             } else {
                 $text = preg_replace('/(' . $searchFilter . ')/i', $replacement, $refNode->getText());
             }
             $refNode->setText($text, $refNode->getTextSourceField(), $refNode->getPrefix(), $refNode->getSuffix());
             /** @var $childCollection t3lib_tree_pagetree_NodeCollection */
             $childCollection = t3lib_div::makeInstance('t3lib_tree_pagetree_NodeCollection');
             if ($i + 1 >= $amountOfRootlineElements) {
                 $childNodes = $this->getNodes($refNode, $mountPoint);
                 foreach ($childNodes as $childNode) {
                     /** @var $childNode t3lib_tree_pagetree_Node */
                     $childRecord = $childNode->getRecord();
                     $childIdent = intval($childRecord['sorting']) . intval($childRecord['uid']);
                     $childCollection->offsetSet($childIdent, $childNode);
                 }
                 $refNode->setChildNodes($childNodes);
             }
             $refNode->setChildNodes($childCollection);
             $reference->offsetSet($ident, $refNode);
             $reference->ksort();
             $reference = $childCollection;
         }
     }
     return $nodeCollection;
 }
 /**
  * Gets node children
  *
  * @param t3lib_tree_Node $node
  * @param  $level
  * @return A|null|object
  */
 protected function getChildrenOf(t3lib_tree_Node $node, $level)
 {
     $nodeData = NULL;
     if ($node->getId() !== 0) {
         $nodeData = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', $this->tableName, 'uid=' . $node->getId());
     }
     if ($nodeData == NULL) {
         $nodeData = array('uid' => 0, $this->getLookupField() => '');
     }
     $storage = NULL;
     $children = $this->getRelatedRecords($nodeData);
     if (count($children)) {
         $storage = t3lib_div::makeInstance('t3lib_tree_NodeCollection');
         foreach ($children as $child) {
             $node = t3lib_div::makeInstance('t3lib_tree_Node');
             $node->setId($child);
             if ($level <= $this->levelMaximum) {
                 $children = $this->getChildrenOf($node, $level + 1);
                 if ($children !== NULL) {
                     $node->setChildNodes($children);
                 }
             }
             $storage->append($node);
         }
     }
     return $storage;
 }