/** * @param QModelIndex $parent * @return int */ public function columnCount(QModelIndex $parent) { if ($parent->isValid()) { return $parent->internalPointer()->columnCount(); } else { return $this->rootItem->columnCount(); } }
/** * Loads all children of the given tree item list recursively. * * @param TreeItem[] $treeItems A list of tree items to load it's children. * @param array $compositions The compositions list to load the children from. * @param string $compositionName The name of the relation. * @param TreeItem $parentItem The parent TreeItem. * @param int $maxDepth The maximum depth of the tree. * @param int $depth The actual depth of the tree. * * @return TreeItem[] A list of tree items of the actual node. * * @author Nicolas Pecher * @version * Version 0.1. 23.04.2012 */ protected function loadChildTreeItems(array $treeItems, array $compositions, $compositionName, TreeItem $parentItem, $maxDepth, $depth = 0) { $layer = []; if ($maxDepth === 0 || $depth <= $maxDepth) { foreach ($treeItems as $treeItem) { foreach ($compositions as $composition) { if ($composition[$this->relationTable[$compositionName]['TargetID']] === $treeItem->getObjectId() && $composition[$this->relationTable[$compositionName]['SourceID']] === $parentItem->getObjectId()) { $cDepth = $depth + 1; $childItems = $this->loadChildTreeItems($treeItems, $compositions, $compositionName, $treeItem, $maxDepth, $cDepth); $treeItem->setParentItem($parentItem); $treeItem->addChildren($childItems); $layer[] = $treeItem; break; } } } } return $layer; }
/** * Add an entry in the tree view ; the entry is added in the * children array of its parent * * @param dn DN to add * @param string $dn the dn of the entry to create */ public function addEntry($dn) { if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) { debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); } $server = $this->getServer(); $dnlower = $this->indexDN($dn); # @todo Temporarily removed, some non-ascii char DNs that do exist, fail here for some reason? #if (! ($server->dnExists($dn))) # return; if (isset($this->entries[$dnlower])) { debug_dump_backtrace('Calling add entry to an entry that ALREADY exists?', 1); } if (DEBUG_ENABLED) { debug_log('New ENTRY (%s).', 64, 0, __FILE__, __LINE__, __METHOD__, $dn); } $tree_factory = new TreeItem($server->getIndex(), $dn); $tree_factory->setObjectClasses($server->getDNAttrValue($dn, 'objectClass')); if (($isleaf = $server->getDNAttrValue($dn, 'hassubordinates')) && !strcasecmp($isleaf[0], 'false')) { $tree_factory->setLeaf(); } $this->entries[$dnlower] = $tree_factory; # Is this entry in a base entry? if (in_array_ignore_case($dn, $server->getBaseDN(null))) { $this->entries[$dnlower]->setBase(); # If the parent entry is not in the tree, we add it. This routine will in itself # recall this method until we get to the top of the tree (the base). } else { $parent_dn = $server->getContainer($dn); if (DEBUG_ENABLED) { debug_log('Parent DNs (%s)', 64, 0, __FILE__, __LINE__, __METHOD__, $parent_dn); } if ($parent_dn) { $parent_entry = $this->getEntry($parent_dn); if (!$parent_entry) { $this->addEntry($parent_dn); $parent_entry = $this->getEntry($parent_dn); } # Update this DN's parent's children list as well. $parent_entry->addChild($dn); } } }
/** * Add item to node * @param TreeItem $item */ public function addItem(TreeItem $item) { $this->items[$item->getKey()] = $item; }