24 define(
"IL_LAST_NODE", -2);
25 define(
"IL_FIRST_NODE", -1);
146 function ilTree($a_tree_id, $a_root_id = 0)
151 (isset($ilDB)) ? $this->ilDB =& $ilDB : $this->ilDB =& $ilias->db;
156 $ilErr->setErrorHandling(PEAR_ERROR_CALLBACK,array($ilErr,
'errorHandler'));
163 $this->lang_code =
"en";
165 if (!isset($a_tree_id) or (func_num_args() == 0) )
167 $this->ilErr->raiseError(get_class($this).
"::Constructor(): No tree_id given!",$this->ilErr->WARNING);
170 if (func_num_args() > 2)
172 $this->ilErr->raiseError(get_class($this).
"::Constructor(): Wrong parameter count!",$this->ilErr->WARNING);
179 if (empty($a_root_id))
181 $a_root_id = ROOT_FOLDER_ID;
184 $this->tree_id = $a_tree_id;
185 $this->root_id = $a_root_id;
186 $this->table_tree =
'tree';
187 $this->table_obj_data =
'object_data';
188 $this->table_obj_reference =
'object_reference';
189 $this->ref_pk =
'ref_id';
190 $this->obj_pk =
'obj_id';
191 $this->tree_pk =
'tree';
193 $this->use_cache =
true;
196 $this->translation_cache = array();
197 $this->parent_type_cache = array();
208 $this->use_cache = $a_use;
229 if (!is_object($ilUser))
231 $this->lang_code =
"en";
235 $this->lang_code = $ilUser->getCurrentLanguage();
254 function setTableNames($a_table_tree,$a_table_obj_data,$a_table_obj_reference =
"")
256 if (!isset($a_table_tree) or !isset($a_table_obj_data))
258 $this->ilErr->raiseError(get_class($this).
"::setTableNames(): Missing parameter! ".
259 "tree table: ".$a_table_tree.
" object data table: ".$a_table_obj_data,$this->ilErr->WARNING);
262 $this->table_tree = $a_table_tree;
263 $this->table_obj_data = $a_table_obj_data;
264 $this->table_obj_reference = $a_table_obj_reference;
277 if (!isset($a_column_name))
279 $this->ilErr->raiseError(get_class($this).
"::setReferenceTablePK(): No column name given!",$this->ilErr->WARNING);
282 $this->ref_pk = $a_column_name;
294 if (!isset($a_column_name))
296 $this->ilErr->raiseError(get_class($this).
"::setObjectTablePK(): No column name given!",$this->ilErr->WARNING);
299 $this->obj_pk = $a_column_name;
311 if (!isset($a_column_name))
313 $this->ilErr->raiseError(get_class($this).
"::setTreeTablePK(): No column name given!",$this->ilErr->WARNING);
316 $this->tree_pk = $a_column_name;
327 if ($this->table_obj_reference)
330 return "JOIN ".$this->table_obj_reference.
" ON ".$this->table_tree.
".child=".$this->table_obj_reference.
".".$this->ref_pk.
" ".
331 "JOIN ".$this->table_obj_data.
" ON ".$this->table_obj_reference.
".".$this->obj_pk.
"=".$this->table_obj_data.
".".$this->obj_pk.
" ";
336 return "JOIN ".$this->table_obj_data.
" ON ".$this->table_tree.
".child=".$this->table_obj_data.
".".$this->obj_pk.
" ";
348 function getChilds($a_node_id, $a_order =
"", $a_direction =
"ASC")
352 if (!isset($a_node_id))
354 $message = get_class($this).
"::getChilds(): No node_id given!";
355 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
368 if (!empty($a_order))
370 $order_clause =
"ORDER BY ".$a_order.
" ".$a_direction;
374 $order_clause =
"ORDER BY ".$this->table_tree.
".lft";
378 $q =
"SELECT * FROM ".$this->table_tree.
" ".
380 "WHERE parent = ".$this->ilDB->quote($a_node_id).
" ".
381 "AND ".$this->table_tree.
".".$this->tree_pk.
" = ".$this->ilDB->quote($this->tree_id).
" ".
385 $r = $this->ilDB->query($q);
388 $count = $r->numRows();
401 #$GLOBALS['ilLog']->write(__METHOD__.': Storing in tree cache '.$row['child'].' = true');
402 $this->in_tree_cache[$row[
'child']] = $row[
'tree'] == 1;
408 $childs[$count - 1][
"last"] =
true;
428 $childs = $this->
getChilds($a_node,$a_order,$a_direction);
430 foreach($childs as $child)
432 if(!in_array($child[
"type"],$a_filter))
434 $filtered[] = $child;
437 return $filtered ? $filtered : array();
450 if (!isset($a_node_id) or !isset($a_type))
452 $message = get_class($this).
"::getChildsByType(): Missing parameter! node_id:".$a_node_id.
" type:".$a_type;
453 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
459 if ($a_type==
'rolf' && $this->table_obj_reference) {
463 $q =
"SELECT * FROM ".$this->table_tree.
" ".
465 "WHERE parent = '".$a_node_id.
"' ".
466 "AND ".$this->table_tree.
".".$this->tree_pk.
" = '".$this->tree_id.
"' ".
467 "AND ".$this->table_obj_data.
".type='".$a_type.
"' ".
470 $q =
"SELECT * FROM ".$this->table_tree.
" ".
472 "WHERE parent = '".$a_node_id.
"' ".
473 "AND ".$this->table_tree.
".".$this->tree_pk.
" = '".$this->tree_id.
"' ".
474 "AND ".$this->table_obj_data.
".type='".$a_type.
"' ".
475 "ORDER BY ".$this->table_tree.
".lft";
477 $r = $this->ilDB->query($q);
498 if (!isset($a_node_id) or !isset($a_types))
500 $message = get_class($this).
"::getChildsByType(): Missing parameter! node_id:".$a_node_id.
" type:".$a_types;
501 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
507 $q =
"SELECT * FROM ".$this->table_tree.
" ".
509 "WHERE parent = '".$a_node_id.
"' ".
510 "AND ".$this->table_tree.
".".$this->tree_pk.
" = '".$this->tree_id.
"' ".
512 "ORDER BY ".$this->table_tree.
".lft";
513 $r = $this->ilDB->query($q);
537 if($a_node_id <= 1 or $a_parent_id <= 0)
539 $message = sprintf(
'%s::insertNode(): Invalid parameters! $a_node_id: %s $a_parent_id: %s',
543 $this->log->write($message,$this->log->FATAL);
544 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
549 if (!isset($a_node_id) or !isset($a_parent_id))
551 $this->ilErr->raiseError(get_class($this).
"::insertNode(): Missing parameter! ".
552 "node_id: ".$a_node_id.
" parent_id: ".$a_parent_id,$this->ilErr->WARNING);
556 $this->ilErr->raiseError(get_class($this).
"::insertNode(): Node ".$a_node_id.
" already in tree ".
557 $this->table_tree.
"!",$this->ilErr->WARNING);
571 $q =
"SELECT * FROM ".$this->table_tree.
" ".
572 "WHERE child = '".$a_parent_id.
"' ".
573 "AND ".$this->tree_pk.
" = '".$this->tree_id.
"'";
574 $res = $this->ilDB->query($q);
577 if ($r->parent == NULL)
583 $this->ilErr->raiseError(get_class($this).
"::insertNode(): Parent with ID ".$a_parent_id.
" not found in ".
584 $this->table_tree.
"!",$this->ilErr->WARNING);
592 $q =
"UPDATE ".$this->table_tree.
" SET ".
594 "WHEN lft > ".$left.
" ".
599 "WHEN rgt > ".$left.
" ".
603 "WHERE ".$this->tree_pk.
" = '".$this->tree_id.
"'";
604 $this->ilDB->query($q);
617 $q =
'SELECT rgt,lft,parent FROM '.$this->table_tree.
' '.
618 'WHERE child = '.$a_parent_id.
' '.
620 $res = $this->ilDB->query($q);
624 if ($r[
'parent'] == NULL)
630 $this->ilErr->raiseError(get_class($this).
"::insertNode(): Parent with ID ".
631 $a_parent_id.
" not found in ".$this->table_tree.
"!",$this->ilErr->WARNING);
633 $parentRgt = $r[
'rgt'];
634 $parentLft = $r[
'lft'];
637 $availableSpace = $parentRgt - $parentLft;
638 if ($availableSpace < 2)
649 $q =
'SELECT MAX(rgt) AS max_rgt FROM '.$this->table_tree.
' '.
650 'WHERE parent = '.$a_parent_id.
' '.
652 $res = $this->ilDB->query($q);
654 if (isset($r[
'max_rgt']))
658 $availableSpace = $parentRgt - $r[
'max_rgt'];
659 $lft = $r[
'max_rgt'] + 1;
666 $lft = $parentLft + 1;
673 if ($availableSpace < 2)
676 $q =
"UPDATE ".$this->table_tree.
" SET ".
678 "WHEN lft > ".$parentRgt.
" ".
679 "THEN lft + ".(2 + $this->gap * 2).
' '.
683 "WHEN rgt >= ".$parentRgt.
" ".
684 "THEN rgt + ".(2 + $this->gap * 2).
' '.
687 "WHERE ".$this->tree_pk.
" = '".$this->tree_id.
"'";
688 $this->ilDB->query($q);
704 $q =
"SELECT * FROM ".$this->table_tree.
" ".
705 "WHERE child = '".$a_parent_id.
"' ".
706 "AND ".$this->tree_pk.
" = '".$this->tree_id.
"'";
707 $res = $this->ilDB->query($q);
710 if ($r->parent == NULL)
716 $this->ilErr->raiseError(get_class($this).
"::insertNode(): Parent with ID ".
717 $a_parent_id.
" not found in ".$this->table_tree.
"!",$this->ilErr->WARNING);
725 $q =
"UPDATE ".$this->table_tree.
" SET ".
727 "WHEN lft > ".$right.
" ".
732 "WHEN rgt >= ".$right.
" ".
736 "WHERE ".$this->tree_pk.
" = '".$this->tree_id.
"'";
737 $this->ilDB->query($q);
751 $q =
"SELECT * FROM ".$this->table_tree.
" ".
752 "WHERE child = '".$a_pos.
"' ".
753 "AND ".$this->tree_pk.
" = '".$this->tree_id.
"'";
754 $res = $this->ilDB->query($q);
758 if ($r->parent != $a_parent_id)
764 $this->ilErr->raiseError(get_class($this).
"::insertNode(): Parents mismatch! ".
765 "new node parent: ".$a_parent_id.
" sibling parent: ".$r->parent,$this->ilErr->WARNING);
773 $q =
"UPDATE ".$this->table_tree.
" SET ".
775 "WHEN lft > ".$right.
" ".
780 "WHEN rgt > ".$right.
" ".
784 "WHERE ".$this->tree_pk.
" = '".$this->tree_id.
"'";
785 $this->ilDB->query($q);
791 $depth = $this->
getDepth($a_parent_id) + 1;
795 $q =
"INSERT INTO ".$this->table_tree.
" (".$this->tree_pk.
",child,parent,lft,rgt,depth) ".
797 "('".$this->tree_id.
"','".$a_node_id.
"','".$a_parent_id.
"','".$lft.
"','".$rgt.
"','".$depth.
"')";
799 $this->ilDB->query($q);
804 #$GLOBALS['ilLog']->write(__METHOD__.': Storing in tree cache '.$a_node_id.' = true');
805 $this->in_tree_cache[$a_node_id] =
true;
810 if ($a_reset_deletion_date)
836 if($depth and $subnode[
'depth'] > $depth)
840 if(!$first and in_array($subnode[
'type'],$a_filter))
842 $depth = $subnode[
'depth'];
848 $filtered[] = $subnode;
850 return $filtered ? $filtered : array();
864 $query =
"SELECT t2.lft lft, t2.rgt rgt, t2.child child, type ".
865 "FROM ".$this->table_tree.
" t1 ".
866 "JOIN ".$this->table_tree.
" t2 ON (t2.lft BETWEEN t1.lft AND t1.rgt) ".
867 "JOIN ".$this->table_obj_reference.
" obr ON t2.child = obr.ref_id ".
868 "JOIN ".$this->table_obj_data.
" obd ON obr.obj_id = obd.obj_id ".
869 "WHERE t1.child = ".$ilDB->quote($a_endnode_id).
" ".
870 "AND t1.".$this->tree_pk.
" = ".$ilDB->quote($this->tree_id).
" ".
871 "AND t2.".$this->tree_pk.
" = ".$ilDB->quote($this->tree_id).
" ".
874 $res = $ilDB->query($query);
877 $node[
'lft'] = $row->lft;
878 $node[
'rgt'] = $row->rgt;
879 $node[
'child'] = $row->child;
880 $node[
'type'] = $row->type;
884 return (array) $nodes;
896 function getSubTree($a_node,$a_with_data =
true, $a_type =
"")
898 if (!is_array($a_node))
900 $this->ilErr->raiseError(get_class($this).
"::getSubTree(): Wrong datatype for node_data! ",$this->ilErr->WARNING);
903 if($a_node[
'lft'] < 1 or $a_node[
'rgt'] < 2)
905 $message = sprintf(
'%s::getSubTree(): Invalid node given! $a_node["lft"]: %s $a_node["rgt"]: %s',
910 $this->log->write($message,$this->log->FATAL);
912 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
920 $type_str =
"AND ".$this->table_obj_data.
".type='".$a_type.
"' ";
923 $q =
"SELECT * FROM ".$this->table_tree.
" ".
925 "WHERE ".$this->table_tree.
".lft BETWEEN '".$a_node[
"lft"].
"' AND '".$a_node[
"rgt"].
"' ".
926 "AND ".$this->table_tree.
".".$this->tree_pk.
" = '".$this->tree_id.
"' ".
928 "ORDER BY ".$this->table_tree.
".lft";
930 $r = $this->ilDB->query($q);
940 $subtree[] = $row[
'child'];
944 #$GLOBALS['ilLog']->write(__METHOD__.': Storing in tree cache '.$a_node_id.' = true');
945 $this->in_tree_cache[$row[
'child']] =
true;
949 return $subtree ? $subtree : array();
962 $a_filter = $a_filter ? $a_filter : array();
964 foreach($this->getSubtree($this->
getNodeData($a_node)) as $node)
966 if(in_array($node[
"type"],$a_filter))
970 $types[
"$node[type]"] = $node[
"type"];
972 return $types ? $types : array();
982 if (!is_array($a_node))
984 $this->ilErr->raiseError(get_class($this).
"::deleteTree(): Wrong datatype for node_data! ",$this->ilErr->WARNING);
986 if($this->
__isMainTree() and $a_node[$this->tree_pk] === 1)
988 if($a_node[
'lft'] <= 1 or $a_node[
'rgt'] <= 2)
990 $message = sprintf(
'%s::deleteTree(): Invalid parameters given: $a_node["lft"]: %s, $a_node["rgt"] %s',
995 $this->log->write($message,$this->log->FATAL);
996 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
1000 $message = sprintf(
'%s::deleteTree(): Check delete failed: $a_node["lft"]: %s, $a_node["rgt"] %s',
1004 $this->log->write($message,$this->log->FATAL);
1005 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
1009 $diff = $a_node[
"rgt"] - $a_node[
"lft"] + 1;
1019 $query =
"SELECT * FROM ".$this->table_tree.
" ".
1020 "WHERE child = '".$a_node[
'child'].
"' ".
1023 $res = $this->ilDB->query($query);
1026 $a_node[
'lft'] = $row->lft;
1027 $a_node[
'rgt'] = $row->rgt;
1028 $diff = $a_node[
"rgt"] - $a_node[
"lft"] + 1;
1032 $q =
"DELETE FROM ".$this->table_tree.
" ".
1033 "WHERE lft BETWEEN '".$a_node[
"lft"].
"' AND '".$a_node[
"rgt"].
"' ".
1034 "AND rgt BETWEEN '".$a_node[
"lft"].
"' AND '".$a_node[
"rgt"].
"' ".
1036 $this->ilDB->query($q);
1041 if ($a_node[$this->tree_pk] >= 0 &&
1042 $a_node[
'rgt'] - $a_node[
'lft'] >= $this->gap * 2)
1046 $q =
"UPDATE ".$this->table_tree.
" SET ".
1048 "WHEN lft > '".$a_node[
"lft"].
" '".
1049 "THEN lft - '".$diff.
" '".
1053 "WHEN rgt > '".$a_node[
"lft"].
" '".
1054 "THEN rgt - '".$diff.
" '".
1058 $this->ilDB->query($q);
1067 #$GLOBALS['ilLog']->write(__METHOD__.': Resetting in tree cache ');
1069 $this->in_tree_cache = array();
1086 $pathIds =& $this->
getPathId($a_endnode_id, $a_startnode_id);
1092 if (count($pathIds) == 0)
1097 $inClause =
'child IN (';
1098 for ($i=0; $i < count($pathIds); $i++)
1100 if ($i > 0) $inClause .=
',';
1101 $inClause .= $ilDB->quote($pathIds[$i]);
1106 'FROM '.$this->table_tree.
' '.
1108 'WHERE '.$inClause.
' '.
1109 'AND '.$this->table_tree.
'.'.$this->tree_pk.
' = '.$this->ilDB->quote($this->tree_id).
' '.
1111 $r = $ilDB->query($q);
1113 $pathFull = array();
1121 #$GLOBALS['ilLog']->write(__METHOD__.': Storing in tree cache '.$row['child']);
1122 $this->in_tree_cache[$row[
'child']] = $row[
'tree'] == 1;
1144 if (!isset($a_endnode_id))
1146 $this->ilErr->raiseError(get_class($this).
"::getPathId(): No endnode_id given! ",$this->ilErr->WARNING);
1149 $q =
"SELECT T2.child ".
1150 "FROM ".$this->table_tree.
" AS T1, ".$this->table_tree.
" AS T2 ".
1151 "WHERE T1.child = '".$a_endnode_id.
"' ".
1152 "AND T1.lft BETWEEN T2.lft AND T2.rgt ".
1153 "AND T1.".$this->tree_pk.
" = '".$this->tree_id.
" '".
1154 "AND T2.".$this->tree_pk.
" = '".$this->tree_id.
" '".
1155 "ORDER BY T2.depth";
1157 $r = $this->ilDB->query($q);
1158 $takeId = $a_startnode_id == 0;
1161 if ($takeId || $row[
'child'] == $a_startnode_id)
1164 $pathIds[] = $row[
'child'];
1185 $takeId = $a_startnode_id == 0;
1187 if (!isset($a_endnode_id))
1189 $this->ilErr->raiseError(get_class($this).
"::getPathId(): No endnode_id given! ",$this->ilErr->WARNING);
1195 $q =
'SELECT t.depth,t.parent '.
1196 'FROM '.$this->table_tree.
' AS t '.
1197 'WHERE child='.$this->ilDB->quote($a_endnode_id).
' '.
1198 'AND '.$this->tree_pk.
' = '.$this->tree_id.
' '.
1201 $r = $this->ilDB->query($q);
1203 if ($r->numRows() == 0)
1208 $nodeDepth = $row[
'depth'];
1209 $parentId = $row[
'parent'];
1214 if ($nodeDepth == 1)
1216 $takeId = $takeId || $a_endnode_id == $a_startnode_id;
1217 if ($takeId) $pathIds[] = $a_endnode_id;
1219 else if ($nodeDepth == 2)
1221 $takeId = $takeId || $parentId == $a_startnode_id;
1222 if ($takeId) $pathIds[] = $parentId;
1223 $takeId = $takeId || $a_endnode_id == $a_startnode_id;
1224 if ($takeId) $pathIds[] = $a_endnode_id;
1226 else if ($nodeDepth == 3)
1228 $takeId = $takeId || $this->root_id == $a_startnode_id;
1230 $takeId = $takeId || $parentId == $a_startnode_id;
1231 if ($takeId) $pathIds[] = $parentId;
1232 $takeId = $takeId || $a_endnode_id == $a_startnode_id;
1233 if ($takeId) $pathIds[] = $a_endnode_id;
1235 else if ($nodeDepth < 32)
1246 $qSelect =
't1.child as c0';
1248 for ($i = 1; $i < $nodeDepth - 2; $i++)
1250 $qSelect .=
', t'.$i.
'.parent as c'.$i;
1251 $qJoin .=
' JOIN '.$this->table_tree.
' AS t'.$i.
' ON '.
1252 't'.$i.
'.child=t'.($i - 1).
'.parent AND '.
1253 't'.$i.
'.'.$this->tree_pk.
' = '.$this->tree_id;
1255 $q =
'SELECT '.$qSelect.
' '.
1256 'FROM '.$this->table_tree.
' AS t0 '.$qJoin.
' '.
1257 'WHERE t0.'.$this->tree_pk.
' = '.$this->tree_id.
' '.
1258 'AND t0.child='.$parentId.
' '.
1260 $r = $this->ilDB->query($q);
1261 if ($r->numRows() == 0)
1267 $takeId = $takeId || $this->root_id == $a_startnode_id;
1269 for ($i = $nodeDepth - 4; $i >=0; $i--)
1271 $takeId = $takeId || $row[
'c'.$i] == $a_startnode_id;
1272 if ($takeId) $pathIds[] = $row[
'c'.$i];
1274 $takeId = $takeId || $parentId == $a_startnode_id;
1275 if ($takeId) $pathIds[] = $parentId;
1276 $takeId = $takeId || $a_endnode_id == $a_startnode_id;
1277 if ($takeId) $pathIds[] = $a_endnode_id;
1299 if ($this->
isCacheUsed() && isset($this->path_id_cache[$a_endnode_id][$a_startnode_id]))
1302 return $this->path_id_cache[$a_endnode_id][$a_startnode_id];
1310 $this->path_id_cache[$a_endnode_id][$a_startnode_id] = $pathIds;
1339 if ($titlePath == null || count($titlePath) == 0)
1341 if ($a_startnode_id == 0)
1352 if ($a_startnode_id != null && $a_startnode_id != 0)
1356 $parent = $a_startnode_id;
1361 $nodePath = array();
1369 require_once(
'include/Unicode/UtfNormal.php');
1370 $inClause =
'd.title IN (';
1371 for ($i=0; $i < count($titlePath); $i++)
1374 if ($i > 0) $inClause .=
',';
1375 $inClause .= $ilDB->quote($titlePath[$i]);
1380 if ($this->table_obj_reference)
1382 $joinClause =
'JOIN '.$this->table_obj_reference.
' AS r ON t.child=r.'.$this->ref_pk.
' '.
1383 'JOIN '.$this->table_obj_data.
' AS d ON r.'.$this->obj_pk.
'=d.'.
$this->obj_pk;
1387 $joinClause =
'JOIN '.$this->table_obj_data.
' AS d ON t.child=d.'.
$this->obj_pk;
1394 $q =
'SELECT t.depth, t.parent, t.child, d.'.$this->obj_pk.
' AS obj_id, d.type, d.title '.
1395 'FROM '.$this->table_tree.
' AS t '.
1397 'WHERE '.$inClause.
' '.
1398 'AND t.depth <= '.(count($titlePath)+count($nodePath)).
' '.
1400 'ORDER BY t.depth, t.child ASC';
1401 $r = $ilDB->query($q);
1407 $row[
'ref_id'] = $row[
'child'];
1412 for ($i = 0; $i < count($titlePath); $i++) {
1413 $pathElementFound =
false;
1414 foreach ($rows as $row) {
1415 if ($row[
'parent'] == $parent &&
1416 strtolower($row[
'title']) == $titlePath[$i])
1421 $parent = $row[
'child'];
1422 $pathElementFound =
true;
1427 if (! $pathElementFound)
1459 $pathIds =& $this->
getPathId($a_endnode_id, $a_startnode_id);
1462 if (count($pathIds) == 0)
1467 $inClause =
't.child IN (';
1468 for ($i=0; $i < count($pathIds); $i++)
1470 if ($i > 0) $inClause .=
',';
1471 $inClause .= $ilDB->quote($pathIds[$i]);
1475 $q =
'SELECT t.depth,t.parent,t.child,d.obj_id,d.type,d.title '.
1476 'FROM '.$this->table_tree.
' AS t '.
1477 'JOIN '.$this->table_obj_reference.
' AS r ON r.ref_id=t.child '.
1478 'JOIN '.$this->table_obj_data.
' AS d ON d.obj_id=r.obj_id '.
1479 'WHERE '.$inClause.
' '.
1480 'ORDER BY t.depth ';
1481 $r = $ilDB->query($q);
1483 $titlePath = array();
1486 $titlePath[] = $row;
1500 $q =
"SELECT lft,rgt FROM ".$this->table_tree.
" ".
1501 "WHERE ".$this->tree_pk.
" = '".$this->tree_id.
"'";
1503 $r = $this->ilDB->query($q);
1511 $all = array_merge($lft,$rgt);
1512 $uni = array_unique($all);
1514 if (count($all) != count($uni))
1516 $message = sprintf(
'%s::checkTree(): Tree is corrupted!',
1519 $this->log->write($message,$this->log->FATAL);
1520 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
1531 $q =
"SELECT * FROM ".$this->table_tree.
" ".
1532 "WHERE ".$this->tree_pk.
" = '".$this->tree_id.
"' ".
1534 $r1 = $this->ilDB->query($q);
1538 if (($row[
"child"] == 0) && $a_no_zero_child)
1540 $this->ilErr->raiseError(get_class($this).
"::checkTreeChilds(): Tree contains child with ID 0!",$this->ilErr->WARNING);
1543 if ($this->table_obj_reference)
1546 $q =
"SELECT * FROM ".$this->table_obj_reference.
" WHERE ".$this->ref_pk.
"='".$row[
"child"].
"'";
1547 $r2 = $this->ilDB->query($q);
1549 if ($r2->numRows() == 0)
1551 $this->ilErr->raiseError(get_class($this).
"::checkTree(): No Object-to-Reference entry found for ID ".
1552 $row[
"child"].
"!",$this->ilErr->WARNING);
1554 if ($r2->numRows() > 1)
1556 $this->ilErr->raiseError(get_class($this).
"::checkTree(): More Object-to-Reference entries found for ID ".
1557 $row[
"child"].
"!",$this->ilErr->WARNING);
1563 $q =
"SELECT * FROM ".$this->table_obj_data.
" WHERE ".$this->obj_pk.
"='".$obj_ref[
$this->obj_pk].
"'";
1564 $r3 = $this->ilDB->query($q);
1565 if ($r3->numRows() == 0)
1567 $this->ilErr->raiseError(get_class($this).
"::checkTree(): No child found for ID ".
1568 $obj_ref[$this->obj_pk].
"!",$this->ilErr->WARNING);
1570 if ($r3->numRows() > 1)
1572 $this->ilErr->raiseError(get_class($this).
"::checkTree(): More childs found for ID ".
1573 $obj_ref[$this->obj_pk].
"!",$this->ilErr->WARNING);
1580 $q =
"SELECT * FROM ".$this->table_obj_data.
" WHERE ".$this->obj_pk.
"='".$row[
"child"].
"'";
1581 $r2 = $this->ilDB->query($q);
1583 if ($r2->numRows() == 0)
1585 $this->ilErr->raiseError(get_class($this).
"::checkTree(): No child found for ID ".
1586 $row[
"child"].
"!",$this->ilErr->WARNING);
1588 if ($r2->numRows() > 1)
1590 $this->ilErr->raiseError(get_class($this).
"::checkTree(): More childs found for ID ".
1591 $row[
"child"].
"!",$this->ilErr->WARNING);
1606 $q =
"SELECT MAX(depth) FROM ".$this->table_tree;
1607 $r = $this->ilDB->query($q);
1609 $row = $r->fetchRow();
1624 $q =
"SELECT depth FROM ".$this->table_tree.
" ".
1625 "WHERE child = '".$a_node_id.
"' ".
1626 "AND ".$this->tree_pk.
" = '".$this->tree_id.
"'";
1628 $res = $this->ilDB->query($q);
1652 if (!isset($a_node_id))
1654 $this->ilErr->raiseError(get_class($this).
"::getNodeData(): No node_id given! ",$this->ilErr->WARNING);
1660 $message = sprintf(
'%s::getNodeData(): No valid parameter given! $a_node_id: %s',
1664 $this->log->write($message,$this->log->FATAL);
1665 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
1670 $q =
"SELECT * FROM ".$this->table_tree.
" ".
1672 "WHERE ".$this->table_tree.
".child = '".$a_node_id.
"' ".
1673 "AND ".$this->table_tree.
".".$this->tree_pk.
" = '".
1674 (($a_tree_pk === null) ? $this->tree_id : $a_tree_pk).
1677 $r = $this->ilDB->query($q);
1697 $data[
"desc"] = $a_row[
"description"];
1702 if (is_object($objDefinition))
1704 $translation_type = $objDefinition->getTranslationType(
$data[
"type"]);
1708 if ($translation_type ==
"sys")
1711 if (
$data[
"type"] ==
"rolf" and
$data[
"obj_id"] != ROLE_FOLDER_ID)
1713 $data[
"description"] = $lng->txt(
"obj_".
$data[
"type"].
"_local_desc").$data[
"title"].$data[
"desc"];
1714 $data[
"desc"] = $lng->txt(
"obj_".
$data[
"type"].
"_local_desc").$data[
"title"].$data[
"desc"];
1715 $data[
"title"] = $lng->txt(
"obj_".
$data[
"type"].
"_local");
1719 $data[
"title"] = $lng->txt(
"obj_".
$data[
"type"]);
1720 $data[
"description"] = $lng->txt(
"obj_".
$data[
"type"].
"_desc");
1721 $data[
"desc"] = $lng->txt(
"obj_".
$data[
"type"].
"_desc");
1725 elseif ($translation_type ==
"db")
1730 array_key_exists(
$data[
"obj_id"].
'.'.$lang_code, $this->translation_cache)) {
1732 $key =
$data[
"obj_id"].
'.'.$lang_code;
1733 $data[
"title"] = $this->translation_cache[$key][
'title'];
1734 $data[
"description"] = $this->translation_cache[$key][
'description'];
1735 $data[
"desc"] = $this->translation_cache[$key][
'desc'];
1740 $q =
"SELECT title,description FROM object_translation ".
1741 "WHERE obj_id = ".$data[
"obj_id"].
" ".
1742 "AND lang_code = '".$this->lang_code.
"' ".
1743 "AND NOT lang_default = 1";
1744 $r = $this->ilDB->query($q);
1750 $data[
"title"] = $row->title;
1752 $data[
"desc"] = $row->description;
1757 if ($this->
isCacheUsed() && count($this->translation_cache) < 1000)
1759 $key =
$data[
"obj_id"].
'.'.$lang_code;
1760 $this->translation_cache[$key] = array();
1761 $this->translation_cache[$key][
'title'] =
$data[
"title"] ;
1762 $this->translation_cache[$key][
'description'] =
$data[
"description"];
1763 $this->translation_cache[$key][
'desc'] =
$data[
"desc"];
1769 if(
$data[
'type'] ==
'crsr' or
$data[
'type'] ==
'catr')
1771 include_once(
'./Services/ContainerReference/classes/class.ilContainerReference.php');
1788 if (!isset($a_node_id))
1791 #$this->ilErr->raiseError(get_class($this)."::getNodeData(): No node_id given! ",$this->ilErr->WARNING);
1795 if ($this->
isCacheUsed() && isset($this->in_tree_cache[$a_node_id]))
1797 #$GLOBALS['ilLog']->write(__METHOD__.': Using in tree cache '.$a_node_id);
1799 return $this->in_tree_cache[$a_node_id];
1802 $q =
"SELECT * FROM ".$this->table_tree.
" ".
1803 "WHERE ".$this->table_tree.
".child = ".$this->ilDB->quote($a_node_id).
" ".
1804 "AND ".$this->table_tree.
".".$this->tree_pk.
" = '".$this->tree_id.
"'";
1805 $r = $this->ilDB->query($q);
1807 if ($r->numRows() > 0)
1811 #$GLOBALS['ilLog']->write(__METHOD__.': Storing in tree cache '.$a_node_id.' = true');
1812 $this->in_tree_cache[$a_node_id] =
true;
1820 #$GLOBALS['ilLog']->write(__METHOD__.': Storing in tree cache '.$a_node_id.' = false');
1821 $this->in_tree_cache[$a_node_id] =
false;
1838 if (!isset($a_node_id))
1841 $this->ilErr->raiseError(get_class($this).
"::getParentNodeData(): No node_id given! ",$this->ilErr->WARNING);
1844 if ($this->table_obj_reference)
1847 $innerjoin =
"JOIN ".$this->table_obj_reference.
" ON v.child=".$this->table_obj_reference.
".".$this->ref_pk.
" ".
1848 "JOIN ".$this->table_obj_data.
" ON ".$this->table_obj_reference.
".".$this->obj_pk.
"=".$this->table_obj_data.
".".$this->obj_pk.
" ";
1853 $innerjoin =
"JOIN ".$this->table_obj_data.
" ON v.child=".$this->table_obj_data.
".".$this->obj_pk.
" ";
1856 $q =
"SELECT * FROM ".$this->table_tree.
" s,".$this->table_tree.
" v ".
1858 "WHERE s.child = '".$a_node_id.
"' ".
1859 "AND s.parent = v.child ".
1860 "AND s.lft > v.lft ".
1861 "AND s.rgt < v.rgt ".
1862 "AND s.".$this->tree_pk.
" = '".$this->tree_id.
"' ".
1863 "AND v.".$this->tree_pk.
" = '".$this->tree_id.
"'";
1864 $r = $this->ilDB->query($q);
1880 if (!isset($a_startnode_id) or !isset($a_querynode_id))
1884 #$this->ilErr->raiseError(get_class($this)."::isGrandChild(): Missing parameter! startnode: ".$a_startnode_id." querynode: ".
1885 # $a_querynode_id,$this->ilErr->WARNING);
1888 $q =
"SELECT * FROM ".$this->table_tree.
" s,".$this->table_tree.
" v ".
1889 "WHERE s.child = '".$a_startnode_id.
"' ".
1890 "AND v.child = '".$a_querynode_id.
"' ".
1891 "AND s.".$this->tree_pk.
" = '".$this->tree_id.
"' ".
1892 "AND v.".$this->tree_pk.
" = '".$this->tree_id.
"' ".
1893 "AND v.lft BETWEEN s.lft AND s.rgt ".
1894 "AND v.rgt BETWEEN s.lft AND s.rgt";
1895 $r = $this->ilDB->query($q);
1897 return $r->numRows();
1914 $message = sprintf(
'%s::addTree(): Operation not allowed on main tree! $a_tree_if: %s $a_node_id: %s',
1918 $this->log->write($message,$this->log->FATAL);
1919 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
1922 if (!isset($a_tree_id))
1924 $this->ilErr->raiseError(get_class($this).
"::addTree(): No tree_id given! ",$this->ilErr->WARNING);
1927 if ($a_node_id <= 0)
1929 $a_node_id = $a_tree_id;
1932 $q =
"INSERT INTO ".$this->table_tree.
" (".$this->tree_pk.
", child, parent, lft, rgt, depth) ".
1934 "('".$a_tree_id.
"','".$a_node_id.
"', 0, 1, 2, 1)";
1936 $this->ilDB->query($q);
1949 if (!isset($a_type) or (!is_string($a_type)))
1951 $this->ilErr->raiseError(get_class($this).
"::getNodeDataByType(): Type not given or wrong datatype!",$this->ilErr->WARNING);
1959 $q =
"SELECT * FROM ".$this->table_tree.
" ".
1960 "WHERE ".$this->tree_pk.
" = '".$this->tree_id.
"'".
1962 $r = $this->ilDB->query($q);
1970 $q =
"SELECT * FROM ".$this->table_tree.
" ".
1972 "WHERE ".$this->table_obj_data.
".type = '".$a_type.
"' ".
1973 "AND ".$this->table_tree.
".lft BETWEEN '".$left.
"' AND '".$right.
"' ".
1974 "AND ".$this->table_tree.
".rgt BETWEEN '".$left.
"' AND '".$right.
"' ".
1975 "AND ".$this->table_tree.
".".$this->tree_pk.
" = '".$this->tree_id.
"'";
1976 $r = $this->ilDB->query($q);
1998 $message = sprintf(
'%s::removeTree(): Operation not allowed on main tree! $a_tree_if: %s',
2001 $this->log->write($message,$this->log->FATAL);
2002 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
2006 $this->ilErr->raiseError(get_class($this).
"::removeTree(): No tree_id given! Action aborted",$this->ilErr->MESSAGE);
2009 $q =
"DELETE FROM ".$this->table_tree.
" WHERE ".$this->tree_pk.
" = '".$a_tree_id.
"'";
2010 $this->ilDB->query($q);
2028 $message = sprintf(
'%s::saveSubTree(): No valid parameter given! $a_node_id: %s',
2031 $this->log->write($message,$this->log->FATAL);
2032 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
2039 'object_reference' =>
'WRITE'));
2043 $q =
"SELECT * FROM ".$this->table_tree.
" ".
2044 "WHERE ".$this->tree_pk.
" = '".$this->tree_id.
"' ".
2045 "AND child = '".$a_node_id.
"' ";
2046 $r = $this->ilDB->query($q);
2055 $q =
"SELECT child FROM ".$this->table_tree.
" ".
2056 "WHERE ".$this->tree_pk.
" = '".$this->tree_id.
"' ".
2057 "AND lft BETWEEN '".$lft.
"' AND '".$rgt.
"'";
2058 $r = $this->ilDB->query($q);
2060 $subnodes = array();
2063 $subnodes[] = $row[
'child'];
2066 if(!count($subnodes))
2073 ilDBX::_unlockTables();
2080 foreach($subnodes as $child)
2082 #$q = "INSERT INTO ".$this->table_tree." ".
2083 # "VALUES ('".-$a_node_id."','".$node["child"]."','".$node["parent"]."','".
2084 # $node["lft"]."','".$node["rgt"]."','".$node["depth"]."')";
2085 #$r = $this->ilDB->query($q);
2095 $query =
"UPDATE ".$this->table_tree.
" ".
2096 "SET tree = ".$ilDB->quote(-$a_node_id).
" ".
2097 "WHERE ".$this->tree_pk.
" = ".$ilDB->quote($this->tree_id).
" ".
2098 "AND lft BETWEEN ".$ilDB->quote($lft).
" AND ".$ilDB->quote($rgt).
" ";
2099 $res = $ilDB->query($query);
2104 ilDBX::_unlockTables();
2116 return $this->
isSaved($a_node_id);
2125 if ($this->
isCacheUsed() && isset($this->is_saved_cache[$a_node_id]))
2128 return $this->is_saved_cache[$a_node_id];
2131 $q =
"SELECT * FROM ".$this->table_tree.
" ".
2132 "WHERE child = '".$a_node_id.
"'";
2133 $s = $this->ilDB->query($q);
2136 if ($r[$this->tree_pk] < 0)
2140 $this->is_saved_cache[$a_node_id] =
true;
2148 $this->is_saved_cache[$a_node_id] =
false;
2164 if (!isset($a_parent_id))
2166 $this->ilErr->raiseError(get_class($this).
"::getSavedNodeData(): No node_id given!",$this->ilErr->WARNING);
2169 $q =
"SELECT * FROM ".$this->table_tree.
" ".
2171 "WHERE ".$this->table_tree.
".".$this->tree_pk.
" < 0 ".
2172 "AND ".$this->table_tree.
".parent = '".$a_parent_id.
"' ";
2173 $r = $this->ilDB->query($q);
2180 return $saved ? $saved : array();
2191 if (!isset($a_node_id))
2193 $this->ilErr->raiseError(get_class($this).
"::getParentId(): No node_id given! ",$this->ilErr->WARNING);
2196 $q =
"SELECT parent FROM ".$this->table_tree.
" ".
2197 "WHERE child='".$a_node_id.
"' ".
2198 "AND ".$this->tree_pk.
"='".$this->tree_id.
"'";
2199 $r = $this->ilDB->query($q);
2203 return $row->parent;
2214 if (!isset($a_node_id))
2216 $this->ilErr->raiseError(get_class($this).
"::getLeftValued(): No node_id given! ",$this->ilErr->WARNING);
2219 $q =
"SELECT lft FROM ".$this->table_tree.
" ".
2220 "WHERE child='".$a_node_id.
"' ".
2221 "AND ".$this->tree_pk.
"='".$this->tree_id.
"'";
2222 $r = $this->ilDB->query($q);
2237 if (!isset($a_node))
2239 $this->ilErr->raiseError(get_class($this).
"::getChildSequenceNumber(): No node_id given! ",$this->ilErr->WARNING);
2242 $type_str = ($type !=
"")
2243 ?
"AND type='$type'"
2246 $q =
"SELECT count(*) AS cnt FROM ".$this->table_tree.
" ".
2248 "WHERE lft <=".$this->ilDB->quote($a_node[
"lft"]).
" ".
2250 "AND parent=".$this->ilDB->quote($a_node[
"parent"]).
" ".
2251 "AND ".$this->table_tree.
".".$this->tree_pk.
"=".$this->ilDB->quote($this->tree_id);
2252 $r = $this->ilDB->query($q);
2267 $query =
"SELECT child FROM $this->table_tree ".
2268 "WHERE parent = '0'".
2269 "AND ".$this->tree_pk.
" = '".$this->tree_id.
"'";
2272 $this->root_id = $row->child;
2287 $this->root_id = $a_root_id;
2307 $this->tree_id = $a_tree_id;
2319 if (!isset($a_node_id))
2321 $this->ilErr->raiseError(get_class($this).
"::getNodeData(): No node_id given! ",$this->ilErr->WARNING);
2325 $q =
"SELECT lft FROM ".$this->table_tree.
" ".
2326 "WHERE ".$this->table_tree.
".child = '".$a_node_id.
"' ".
2327 "AND ".$this->table_tree.
".".$this->tree_pk.
" = '".$this->tree_id.
"'";
2328 $r = $this->ilDB->query($q);
2332 $type_where = ($a_type !=
"")
2333 ?
"AND ".$this->table_obj_data.
".type = '$a_type' "
2335 $q =
"SELECT * FROM ".$this->table_tree.
" ".
2337 "WHERE lft > '".$curr_node[
"lft"].
"' ".
2339 "AND ".$this->table_tree.
".".$this->tree_pk.
" = '".$this->tree_id.
"'".
2340 "ORDER BY lft LIMIT 1";
2341 $r = $this->ilDB->query($q);
2343 if ($r->numRows() < 1)
2363 if (!isset($a_node_id))
2365 $this->ilErr->raiseError(get_class($this).
"::getNodeData(): No node_id given! ",$this->ilErr->WARNING);
2369 $q =
"SELECT lft FROM ".$this->table_tree.
" ".
2370 "WHERE ".$this->table_tree.
".child = '".$a_node_id.
"' ".
2371 "AND ".$this->table_tree.
".".$this->tree_pk.
" = '".$this->tree_id.
"'";
2372 $r = $this->ilDB->query($q);
2376 $type_where = ($a_type !=
"")
2377 ?
"AND ".$this->table_obj_data.
".type = '$a_type' "
2379 $q =
"SELECT * FROM ".$this->table_tree.
" ".
2381 "WHERE lft < '".$curr_node[
"lft"].
"' ".
2383 "AND ".$this->table_tree.
".".$this->tree_pk.
" = '".$this->tree_id.
"'".
2384 "ORDER BY lft DESC LIMIT 1";
2385 $r = $this->ilDB->query($q);
2387 if ($r->numRows() < 1)
2412 $this->table_obj_data =>
'WRITE',
2413 $this->table_obj_reference =>
'WRITE',
2414 'object_translation' =>
'WRITE',
2415 'object_data od' =>
'WRITE',
2416 'container_reference cr' =>
'WRITE'));
2439 $q =
"UPDATE ".$this->table_tree.
" SET lft='".$i.
"' WHERE child='".$node_id.
"'";
2440 $this->ilDB->query($q);
2444 foreach ($childs as $child)
2446 $i = $this->
__renumber($child[
"child"],$i+1);
2452 if (count($childs) > 0)
2454 $i += $this->gap * 2;
2457 $q =
"UPDATE ".$this->table_tree.
" SET rgt='".$i.
"' WHERE child='".$node_id.
"'";
2458 $this->ilDB->query($q);
2477 array_key_exists($a_ref_id.
'.'.$a_type, $this->parent_type_cache)) {
2478 return $this->parent_type_cache[$a_ref_id.
'.'.$a_type];
2484 if ($this->
__isMainTree() && count($this->parent_type_cache) < 1000) {
2485 $this->parent_type_cache[$a_ref_id.
'.'.$a_type] =
false;
2489 $path = array_reverse($this->
getPathFull($a_ref_id));
2491 foreach($path as $node)
2493 if($node[
"type"] == $a_type)
2496 if ($this->
__isMainTree() && count($this->parent_type_cache) < 1000) {
2497 $this->parent_type_cache[$a_ref_id.
'.'.$a_type] = $node[
"child"];
2499 return $node[
"child"];
2503 if ($this->
__isMainTree() && count($this->parent_type_cache) < 1000) {
2504 $this->parent_type_cache[$a_ref_id.
'.'.$a_type] =
false;
2522 if($a_db_table ===
'tree')
2524 if($a_tree == 1 and $a_child == ROOT_FOLDER_ID)
2526 $message = sprintf(
'%s::_removeEntry(): Tried to delete root node! $a_tree: %s $a_child: %s',
2530 $ilLog->write($message,$ilLog->FATAL);
2531 $ilErr->raiseError($message,$ilErr->WARNING);
2535 $q =
"DELETE from ".$a_db_table.
" WHERE tree='".$a_tree.
"' AND child='".$a_child.
"'";
2548 if($a_source_id <= 0 or $a_target_id <= 0)
2550 $message = sprintf(
'%s::insertNode(): Invalid parameters! $a_source_id: %s $a_target_id: %s',
2554 $this->log->write($message,$this->log->FATAL);
2555 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
2569 return $this->table_tree ===
'tree';
2583 $query =
"SELECT * FROM ".$this->table_tree.
" ".
2584 "WHERE lft >= ".$a_node[
'lft'].
" ".
2585 "AND rgt <= ".$a_node[
'rgt'].
" ".
2589 $res = $this->ilDB->query($query);
2591 $counter = (int) $lft_childs = array();
2594 $lft_childs[$row->child] = $row->parent;
2599 if($counter != count($lft_childs))
2601 $message = sprintf(
'%s::__checkTree(): Duplicate entries for "child" in maintree! $a_node_id: %s',
2604 $this->log->write($message,$this->log->FATAL);
2605 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
2609 $parent_childs = array();
2619 $query =
"SELECT * FROM ".$this->table_tree.
" ".
2620 "WHERE child = '".$a_node_id.
"' ".
2621 "AND tree = '".$this->tree_id.
"'";
2623 $res = $this->ilDB->query($query);
2627 $parent_childs[$a_node_id] = $row->parent;
2633 $message = sprintf(
'%s::__getSubTreeByParentRelation(): Multiple entries in maintree! $a_node_id: %s',
2636 $this->log->write($message,$this->log->FATAL);
2637 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
2641 $query =
"SELECT * FROM ".$this->table_tree.
" ".
2642 "WHERE parent = '".$a_node_id.
"'";
2644 $res = $this->ilDB->query($query);
2657 ksort($parent_childs);
2659 if(count($lft_childs) != count($parent_childs))
2661 $message = sprintf(
'%s::__validateSubtrees(): (COUNT) Tree is corrupted! Left/Right subtree does not comply .'.
2662 'with parent relation',
2664 $this->log->write($message,$this->log->FATAL);
2665 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
2668 foreach($lft_childs as $key => $value)
2670 if($parent_childs[$key] != $value)
2672 $message = sprintf(
'%s::__validateSubtrees(): (COMPARE) Tree is corrupted! Left/Right subtree does not comply '.
2673 'with parent relation',
2675 $this->log->write($message,$this->log->FATAL);
2676 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
2678 if($key == ROOT_FOLDER_ID)
2680 $message = sprintf(
'%s::__validateSubtrees(): (ROOT_FOLDER) Tree is corrupted! Tried to delete root folder',
2682 $this->log->write($message,$this->log->FATAL);
2683 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
2706 $query =
"SELECT * FROM ".$this->table_tree.
" ".
2707 "WHERE (child = ".$this->ilDB->quote($a_source_id).
" ".
2708 "OR child = ".$this->ilDB->quote($a_target_id).
") ".
2709 "AND tree = ".$this->ilDB->quote($this->tree_id);
2710 $res = $this->ilDB->query($query);
2711 #var_dump("<pre>",$query,"<pre>");
2714 if(
$res->numRows() != 2)
2720 $this->log->write(__METHOD__.
' Objects not found in tree!',$this->log->FATAL);
2721 $this->ilErr->raiseError(
'Error moving node',$this->ilErr->WARNING);
2725 if($row->child == $a_source_id)
2727 $source_lft = $row->lft;
2728 $source_rgt = $row->rgt;
2729 $source_depth = $row->depth;
2730 $source_parent = $row->parent;
2734 $target_lft = $row->lft;
2735 $target_rgt = $row->rgt;
2736 $target_depth = $row->depth;
2740 #var_dump("<pre>",$source_lft,$source_rgt,$source_depth,$target_lft,$target_rgt,$target_depth,"<pre>");
2742 if($target_lft >= $source_lft and $target_rgt <= $source_rgt)
2748 $this->log->write(__METHOD__.
' Target is child of source',$this->log->FATAL);
2749 $this->ilErr->raiseError(
'Error moving node',$this->ilErr->WARNING);
2754 $spread_diff = $source_rgt - $source_lft + 1;
2755 #var_dump("<pre>","SPREAD_DIFF: ",$spread_diff,"<pre>");
2757 $query =
"UPDATE ".$this->table_tree .
" SET ".
2759 "WHEN lft > ".$this->ilDB->quote($target_rgt).
" ".
2760 "THEN lft + ".$this->ilDB->quote($spread_diff).
" ".
2764 "WHEN rgt >= ".$this->ilDB->quote($target_rgt).
" ".
2765 "THEN rgt + ".$this->ilDB->quote($spread_diff).
" ".
2768 "WHERE tree = ".$this->ilDB->quote($this->tree_id);
2769 #var_dump("<pre>",$query,"<pre>");
2770 $res = $this->ilDB->query($query);
2774 if($source_lft > $target_rgt)
2776 $where_offset = $spread_diff;
2777 $move_diff = $target_rgt - $source_lft - $spread_diff;
2782 $move_diff = $target_rgt - $source_lft;
2784 $depth_diff = $target_depth - $source_depth + 1;
2787 $query =
"UPDATE ".$this->table_tree .
" SET ".
2789 "WHEN parent = ".$this->ilDB->quote($source_parent).
" ".
2790 "THEN ".$this->ilDB->quote($a_target_id).
" ".
2793 "rgt = rgt + ".$this->ilDB->quote($move_diff).
", ".
2794 "lft = lft + ".$this->ilDB->quote($move_diff).
", ".
2795 "depth = depth + ".$this->ilDB->quote($depth_diff).
" ".
2796 "WHERE lft >= ".$this->ilDB->quote(($source_lft + $where_offset)).
" ".
2797 "AND rgt <= ".$this->ilDB->quote(($source_rgt + $where_offset)).
" ".
2798 "AND tree = ".$this->ilDB->quote($this->tree_id);
2799 #var_dump("<pre>",$query,"<pre>");
2800 $res = $this->ilDB->query($query);
2803 $query =
"UPDATE ".$this->table_tree .
" SET ".
2805 "WHEN lft >= ".$this->ilDB->quote(($source_lft + $where_offset)).
" ".
2806 "THEN lft - ".$this->ilDB->quote($spread_diff).
" ".
2810 "WHEN rgt >= ".$this->ilDB->quote(($source_rgt + $where_offset)).
" ".
2811 "THEN rgt - ".$this->ilDB->quote($spread_diff).
" ".
2814 "WHERE tree = ".$this->tree_id;
2815 #var_dump("<pre>",$query,"</pre>");
2816 $res = $this->ilDB->query($query);
2834 if (is_array($types) && count ($types) > 0)
2836 $type_str =
" AND ";
2837 if (is_array($types)) {
2838 $type_filter = array();
2839 foreach ($types as $type) {
2840 $type_filter []= $fieldname.
"='".$type.
"'";
2842 $type_str .=
" (" . join (
" OR ", $type_filter) .
") ";
2844 } elseif (is_string($types) && strlen($types) > 0) {
2845 $type_str .=
" AND ".$fieldname.
"= ".$ilDB->quote($types).
" ";