19 require_once(BASE.
"wcmf/lib/core/class.WCMFException.php");
20 require_once(BASE.
"wcmf/lib/util/class.Log.php");
21 require_once(BASE.
"wcmf/lib/util/class.StringUtil.php");
22 require_once(BASE.
"wcmf/lib/persistence/class.PersistentObject.php");
23 require_once(BASE.
"wcmf/lib/persistence/class.PersistenceFacade.php");
24 require_once(BASE.
"wcmf/lib/model/class.NodeUtil.php");
25 require_once(BASE.
"wcmf/lib/util/class.ArrayUtil.php");
30 define(
"ADDCHILD_FRONT", -1);
31 define(
"ADDCHILD_BACK", -2);
35 define(
"SORTTYPE_ASC", -1);
36 define(
"SORTTYPE_DESC", -2);
53 $maxWeight = sizeOf($g_sortCriteria);
55 foreach ($g_sortCriteria as $criteria => $sortType)
57 $weightedValue = ($maxWeight-$i)*($maxWeight-$i);
62 if ($a->getOID() != $b->getOID())
63 ($a->getOID() > $b->getOID()) ? $AGreaterB = 1 : $AGreaterB = -1;
66 else if ($criteria ==
TYPE)
68 if ($a->getType() != $b->getType())
69 ($a->getType() > $b->getType()) ? $AGreaterB = 1 : $AGreaterB = -1;
72 else if($a->getValue($criteria) != null || $b->getValue($criteria) != null)
74 $aValue = strToLower($a->getValue($criteria));
75 $bValue = strToLower($b->getValue($criteria));
76 if ($aValue != $bValue)
77 ($aValue > $bValue) ? $AGreaterB = 1 : $AGreaterB = -1;
80 else if($a->getProperty($criteria) != null || $b->getProperty($criteria) != null)
82 $aProperty = strToLower($a->getProperty($criteria));
83 $bProperty = strToLower($b->getProperty($criteria));
84 if ($aProperty != $bProperty)
85 ($aProperty > $bProperty) ? $AGreaterB = 1 : $AGreaterB = -1;
90 if ($AGreaterB == 1) $sumA += $weightedValue;
91 else if ($AGreaterB == -1) $sumB += $weightedValue;
95 if ($AGreaterB == 1) $sumB += $weightedValue;
96 else if ($AGreaterB == -1) $sumA += $weightedValue;
102 if ($sumA == $sumB)
return 0;
103 return ($sumA > $sumB) ? 1 : -1;
130 function Node ($type, $oid=null)
147 if ($type == null || $this->_children[$i]->
getType() == $type)
154 for ($i=0; $i<
sizeof($childoids); $i++)
168 if (!is_a($child,
'node') && !is_a($child,
'Node'))
169 WCMFException::throwEx(
"addChild() assumes a Node as parameter. Found: ".get_class($child),__FILE__,__LINE__);
180 $childOID = $child->getOID();
187 $child->updateParent($this);
201 if ($this->_parents[$i]->
getOID() == $parent->getOID())
211 for($i=0;$i<sizeOf($this->_children);$i++)
214 $parentOID = $parent->getOID();
215 ArrayUtil::array_insert($this->_properties[
'parentoids'],
sizeof($this->_properties[
'parentoids']), $parentOID);
225 for($i=0;$i<sizeOf($this->_children);$i++)
227 if ($this->_children[$i]->
getOID() == $childOID)
238 array_splice($this->_children, $i, 1);
260 $existingOIDs = array();
261 for($i=0;$i<sizeOf($this->_children);$i++)
262 array_push($existingOIDs, $this->_children[$i]->
getOID());
266 for($i=0;$i<sizeOf($childoids);$i++)
268 $curOID = $childoids[$i];
274 $exists = in_array($curOID, $existingOIDs);
275 if ($exists && !$forceUpdate)
281 $child = &$persistenceFacade->load($curOID, $buildDepth);
298 $children = $this->
getChildrenEx(null, $type, $values, $properties, $useRegExp);
299 if (
sizeof($children) > 0)
310 $returnArray = array();
311 for($i=0;$i<sizeOf($this->_children);$i++)
312 $returnArray[$i] = & $this->_children[$i];
327 return Node::filter($this->_children, $oid, $type, $values, $properties, $useRegExp);
339 function sortChildren ($criteria, $recursive=
false, $changeSortkey=
false, $sortFunction=
'')
341 $this->_children =
Node::sort($this->_children, $criteria, $recursive, $changeSortkey, $sortFunction);
356 function sort (&$nodeList, $criteria, $recursive=
false, $changeSortkey=
false, $sortFunction=
'')
358 if ($sortFunction ==
'')
362 if (!is_array($criteria))
365 $g_sortCriteria = $criteria;
366 usort ($nodeList,
'nodeCmpFunction');
369 usort ($nodeList, $sortFunction);
375 for($i=0;$i<sizeOf($nodeList);$i++)
384 for ($i=0; $i<
sizeof($nodeList); $i++)
385 $nodeList[$i]->
sortChildren($criteria, $recursive, $changeSortkey, $sortFunction);
401 function filter (&$nodeList, $oid, $type, $values, $properties, $useRegExp=
true)
403 $returnArray = array();
404 for($i=0;$i<sizeOf($nodeList);$i++)
406 $curNode = &$nodeList[$i];
407 if (is_a($curNode,
'node') || is_a($curNode,
'Node'))
411 if ($oid != null && $curNode->getOID() != $oid)
414 if ($type != null && $curNode->getType() != $type)
417 if ($values != null && is_array($values))
419 foreach($values as $key => $value)
421 $nodeValue = $curNode->getValue($key);
422 if ($useRegExp && !preg_match(
"/".$value.
"/m", $nodeValue) || !$useRegExp && $value != $nodeValue)
430 if ($properties != null && is_array($properties))
432 foreach($properties as $key => $value)
434 $nodeProperty = $curNode->getProperty($key);
435 if ($useRegExp && !preg_match(
"/".$value.
"/m", $nodeProperty) || !$useRegExp && $value != $nodeProperty)
443 $returnArray[
sizeof($returnArray)] = &$curNode;
460 $pChildren = $parent->getChildren();
462 for ($i=0;$i<sizeOf($pChildren);$i++)
464 if ($pChildren[$i]->
getOID()==$this->_oid && $i<(sizeOf($pChildren)-1))
466 $nextSibling = $pChildren[++$i];
470 if ($nextSibling != null)
484 $pChildren = $parent->getChildren();
486 for ($i=0;$i<sizeOf($pChildren);$i++)
488 if ($pChildren[$i]->
getOID()==$this->_oid && $i>0)
490 $prevSibling = $pChildren[--$i];
494 if ($prevSibling != null)
511 $existingOIDs = array();
512 for($i=0;$i<sizeOf($this->_parents);$i++)
513 array_push($existingOIDs, $this->_parents[$i]->
getOID());
517 for($i=0;$i<sizeOf($parentoids);$i++)
519 $curOID = $parentoids[$i];
525 $exists = in_array($curOID, $existingOIDs);
526 if ($exists && !$forceUpdate)
531 $parents = $this->
getParentsEx($curOID, null, null, null);
532 if (
sizeof($parents) > 0 && $parents[0] != null)
533 $parents[0]->deleteChild($this,
true);
539 $parent->addChild($this);
556 if ($type == null || $this->_parents[$i]->
getType() == $type)
563 for ($i=0; $i<
sizeof($parentoids); $i++)
576 if (
sizeof($this->_parents) > 0)
577 return $this->_parents[0];
591 $parents = $this->
getParentsEx(null, $type, $values, $properties, $useRegExp);
592 if (
sizeof($parents) > 0)
603 $returnArray = array();
604 for($i=0;$i<sizeOf($this->_parents);$i++)
605 $returnArray[$i] = & $this->_parents[$i];
618 function getParentsEx ($oid, $type, $values, $properties, $useRegExp=
true)
620 return Node::filter($this->_parents, $oid, $type, $values, $properties, $useRegExp);
630 while ($parent != null && is_a($parent,
'node'))
633 $parent = & $parent->getParent();
643 $this->_path = $this->
getType();
645 while ($parent != null && is_a($parent,
'node'))
648 $parent = & $parent->getParent();
658 $visitor->visit($this);
667 parent::setState($state);
669 for($i=0;$i<sizeOf($this->_children);$i++)
670 $this->_children[$i]->
setState($state, $recursive);
684 foreach ($oids as $oid)
687 if (!isset($oidList[$baseOid])) {
688 $oidList[$baseOid] = array();
690 if ($oid != $baseOid) {
691 $oidList[$baseOid][] = $oid;
697 foreach ($oidList as $key => $value)
699 if (
sizeof($value) == 0) {
705 $result = array_merge($result, $value);
738 $str .= parent::toString($verbose);
739 $str .=
'depth:'.$this->getDepth().
' ';
740 $str .=
'path:'.$this->getPath().
' ';
745 for($i=0;$i<sizeOf($parents);$i++)
746 $str .= $parents[$i]->
getOID().
',';
747 $str = substr($str, 0, strlen($str)-1);
754 for($i=0;$i<sizeOf($children);$i++)
755 $str .= $children[$i]->
getOID().
',';
756 $str = substr($str, 0, strlen($str)-1);
& getFirstParent($type, $values, $properties, $useRegExp=true)
getNumChildren($memOnly=true, $type=null)
array_remove(&$input, &$val)
Node is the basic component for building trees (although a Node can have one than more parents)...
warn($message, $category)
sort(&$nodeList, $criteria, $recursive=false, $changeSortkey=false, $sortFunction='')
getNumParents($memOnly=true, $type=null)
getDisplayValues(&$node, $useDisplayType=false, $language=null, $values=null)
loadChildren($type, $buildDepth=BUILDDEPTH_SINGLE, $forceUpdate=false)
& getFirstChild($type, $values, $properties, $useRegExp=true)
addChild(&$child, $addtype=ADDCHILD_BACK)
removeDuplicateOidsWithoutRole($oids)
array_insert(&$input, $pos, &$val, $unique=true)
throwEx($message, $file='', $line='')
getParentsEx($oid, $type, $values, $properties, $useRegExp=true)
filter(&$nodeList, $oid, $type, $values, $properties, $useRegExp=true)
getDisplayValues($useDisplayType=false)
loadParents($type, $forceUpdate=false)
sortChildren($criteria, $recursive=false, $changeSortkey=false, $sortFunction='')
getDisplayValue($useDisplayType=false)
getBaseOID($oid, $validate=true)
PersistentObject($type, $oid=null)
getOIDParameter($oid, $param, $validate=true)
getDisplayValue(&$node, $useDisplayType=false, $language=null, $values=null)
setState($state, $recursive=true)
getChildrenEx($oid, $type, $values, $properties, $useRegExp=true)
deleteChild($childOID, $reallyDelete=false)
updateParent(&$parent, $recursive=true)
PersistentObject is the base class of all persistent objects. It implements the basic persistence met...