Example #1
0
 /**
  * Fetch result as tree
  *
  * @return Node
  */
 public function fetchTree()
 {
     $result = $this->fetchAll();
     $sorted = array();
     $quotedDn = preg_quote($this->connection->getDN(), '/');
     foreach ($result as $key => &$item) {
         $new_key = LdapUtils::implodeDN(array_reverse(LdapUtils::explodeDN(preg_replace('/,' . $quotedDn . '$/', '', $key))));
         $sorted[$new_key] = $key;
     }
     unset($groups);
     ksort($sorted);
     $tree = Root::forConnection($this->connection);
     $root_dn = $tree->getDN();
     foreach ($sorted as $sort_key => &$key) {
         if ($key === $root_dn) {
             continue;
         }
         $tree->createChildByDN($key, $result[$key]);
     }
     return $tree;
 }
Example #2
0
 /**
  * @param $dn
  * @param array $props
  * @return Node
  */
 public function createChildByDN($dn, $props = array())
 {
     $dn = $this->stripMyDN($dn);
     $parts = array_reverse(LdapUtils::explodeDN($dn));
     $parent = $this;
     while ($rdn = array_shift($parts)) {
         if ($parent->hasChildRDN($rdn)) {
             $child = $parent->getChildByRDN($rdn);
         } else {
             $child = Node::createWithRDN($parent, $rdn, (array) $props);
             $parent->addChild($child);
         }
         $parent = $child;
     }
     return $child;
 }