ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilWorkspaceTree.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once "Services/Tree/classes/class.ilTree.php";
6
14{
15 public function __construct($a_tree_id, $a_root_id = 0)
16 {
17 parent::__construct($a_tree_id, $a_root_id);
18
19 $this->setTableNames('tree_workspace', 'object_data', 'object_reference_ws');
20 $this->setTreeTablePK('tree');
21 $this->setObjectTablePK('obj_id');
22 $this->setReferenceTablePK('wsp_id');
23
24 // ilTree sets it to ROOT_FOLDER_ID if not given...
25 if(!$a_root_id)
26 {
27 $this->readRootId();
28 }
29 }
30
37 public function createReference($a_object_id)
38 {
39 global $ilDB;
40
41 $next_id = $ilDB->nextId($this->table_obj_reference);
42
43 $fields = array($this->ref_pk => array("integer", $next_id),
44 $this->obj_pk => array("integer", $a_object_id));
45
46 $ilDB->insert($this->table_obj_reference, $fields);
47
48 return $next_id;
49 }
50
57 public function lookupObjectId($a_node_id)
58 {
59 global $ilDB;
60
61 $set = $ilDB->query("SELECT ".$this->obj_pk.
62 " FROM ".$this->table_obj_reference.
63 " WHERE ".$this->ref_pk." = ".$ilDB->quote($a_node_id, "integer"));
64 $res = $ilDB->fetchAssoc($set);
65
66 return $res[$this->obj_pk];
67 }
68
69
78 public function lookupNodeId($a_obj_id)
79 {
80 global $ilDB;
81
82 $set = $ilDB->query("SELECT ".$this->ref_pk.
83 " FROM ".$this->table_obj_reference.
84 " WHERE ".$this->obj_pk." = ".$ilDB->quote($a_obj_id, "integer"));
85 $res = $ilDB->fetchAssoc($set);
86
87 return $res[$this->ref_pk];
88 }
89
96 public function lookupOwner($a_node_id)
97 {
98 global $ilDB;
99
100 $set = $ilDB->query("SELECT tree".
101 " FROM ".$this->table_obj_reference.
102 " JOIN ".$this->table_tree." ON (".$this->table_obj_reference.".".$this->ref_pk." = ".$this->table_tree.".child)".
103 " WHERE ".$this->ref_pk." = ".$ilDB->quote($a_node_id, "integer"));
104 $res = $ilDB->fetchAssoc($set);
105
106 return $res["tree"];
107 }
108
116 public function insertObject($a_parent_node_id, $a_object_id)
117 {
118 $node_id = $this->createReference($a_object_id);
119 $this->insertNode($node_id, $a_parent_node_id);
120 return $node_id;
121 }
122
129 public function deleteReference($a_node_id)
130 {
131 global $ilDB;
132
133 $query = "DELETE FROM ".$this->table_obj_reference.
134 " WHERE ".$this->ref_pk." = ".$ilDB->quote($a_node_id, "integer");
135 return $ilDB->manipulate($query);
136 }
137
141 public function cascadingDelete()
142 {
143 $root_id = $this->readRootId();
144 if(!$root_id)
145 {
146 return;
147 }
148
149 $root = $this->getNodeData($root_id);
150
151 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
152 $access_handler = new ilWorkspaceAccessHandler($this);
153
154 // delete node data
155 $nodes = $this->getSubTree($root);
156 foreach($nodes as $node)
157 {
158 $access_handler->removePermission($node["wsp_id"]);
159
160 $object = ilObjectFactory::getInstanceByObjId($node["obj_id"], false);
161 if($object)
162 {
163 $object->delete();
164 }
165
166 $this->deleteReference($node["wsp_id"]);
167 }
168
169 $this->deleteTree($root);
170 }
171
178 public function getObjectsFromType($a_type)
179 {
180 return $this->getSubTree(
181 $this->getNodeData($this->getRootId()),
182 false, $a_type);
183 }
184
190 public function createTreeForUser($a_user_id)
191 {
192 $root = ilObjectFactory::getClassByType("wsrt");
193 $root = new $root(null);
194 $root->create();
195
196 $root_id = $this->createReference($root->getId());
197 $this->addTree($a_user_id, $root_id);
198 $this->setRootId($root_id);
199 }
200}
201
202?>
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static getClassByType($a_obj_type)
Get class by type.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
getSubTree($a_node, $a_with_data=true, $a_type="")
get all nodes in the subtree under specified node
setObjectTablePK($a_column_name)
set column containing primary key in object table @access public
setReferenceTablePK($a_column_name)
set column containing primary key in reference table @access public
deleteTree($a_node)
delete node and the whole subtree under this node @access public
setTreeTablePK($a_column_name)
set column containing primary key in tree table @access public
setTableNames($a_table_tree, $a_table_obj_data, $a_table_obj_reference="")
set table names The primary key of the table containing your object_data must be 'obj_id' You may use...
readRootId()
read root id from database
getNodeData($a_node_id, $a_tree_pk=null)
get all information of a node.
getRootId()
get the root id of tree @access public
insertNode($a_node_id, $a_parent_id, $a_pos=IL_LAST_NODE, $a_reset_deletion_date=false)
insert new node with node_id under parent node with parent_id @access public
addTree($a_tree_id, $a_node_id=-1)
create a new tree to do: ???
setRootId($a_root_id)
Access handler for personal workspace.
Tree handler for personal workspace.
lookupNodeId($a_obj_id)
Get node id for object id.
insertObject($a_parent_node_id, $a_object_id)
Add object to tree.
cascadingDelete()
Remove all tree and node data.
deleteReference($a_node_id)
Delete object from reference table.
lookupObjectId($a_node_id)
Get object id for node id.
__construct($a_tree_id, $a_root_id=0)
getObjectsFromType($a_type)
Get all workspace objects of specific type.
lookupOwner($a_node_id)
Get owner for node id.
createReference($a_object_id)
Create workspace reference for object.
createTreeForUser($a_user_id)
Create personal workspace tree for user.
global $ilDB