ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
5 include_once "Services/Tree/classes/class.ilTree.php";
6 
13 class ilWorkspaceTree extends ilTree
14 {
18  protected $db;
19 
20  public function __construct($a_tree_id, $a_root_id = 0)
21  {
22  global $DIC;
23 
24  $this->db = $DIC->database();
25  parent::__construct($a_tree_id, $a_root_id);
26 
27  $this->setTableNames('tree_workspace', 'object_data', 'object_reference_ws');
28  $this->setTreeTablePK('tree');
29  $this->setObjectTablePK('obj_id');
30  $this->setReferenceTablePK('wsp_id');
31 
32  // ilTree sets it to ROOT_FOLDER_ID if not given...
33  if (!$a_root_id) {
34  $this->readRootId();
35  }
36  }
37 
44  public function createReference($a_object_id)
45  {
46  $ilDB = $this->db;
47 
48  $next_id = $ilDB->nextId($this->table_obj_reference);
49 
50  $fields = array($this->ref_pk => array("integer", $next_id),
51  $this->obj_pk => array("integer", $a_object_id));
52 
53  $ilDB->insert($this->table_obj_reference, $fields);
54 
55  return $next_id;
56  }
57 
64  public function lookupObjectId($a_node_id)
65  {
66  $ilDB = $this->db;
67 
68  $set = $ilDB->query("SELECT " . $this->obj_pk .
69  " FROM " . $this->table_obj_reference .
70  " WHERE " . $this->ref_pk . " = " . $ilDB->quote($a_node_id, "integer"));
71  $res = $ilDB->fetchAssoc($set);
72 
73  return $res[$this->obj_pk];
74  }
75 
76 
85  public function lookupNodeId($a_obj_id)
86  {
87  $ilDB = $this->db;
88 
89  $set = $ilDB->query("SELECT " . $this->ref_pk .
90  " FROM " . $this->table_obj_reference .
91  " WHERE " . $this->obj_pk . " = " . $ilDB->quote($a_obj_id, "integer"));
92  $res = $ilDB->fetchAssoc($set);
93 
94  return $res[$this->ref_pk];
95  }
96 
103  public function lookupOwner($a_node_id)
104  {
105  $ilDB = $this->db;
106 
107  $set = $ilDB->query("SELECT tree" .
108  " FROM " . $this->table_obj_reference .
109  " JOIN " . $this->table_tree . " ON (" . $this->table_obj_reference . "." . $this->ref_pk . " = " . $this->table_tree . ".child)" .
110  " WHERE " . $this->ref_pk . " = " . $ilDB->quote($a_node_id, "integer"));
111  $res = $ilDB->fetchAssoc($set);
112 
113  return $res["tree"];
114  }
115 
123  public function insertObject($a_parent_node_id, $a_object_id)
124  {
125  $node_id = $this->createReference($a_object_id);
126  $this->insertNode($node_id, $a_parent_node_id);
127  return $node_id;
128  }
129 
136  public function deleteReference($a_node_id)
137  {
138  $ilDB = $this->db;
139 
140  $query = "DELETE FROM " . $this->table_obj_reference .
141  " WHERE " . $this->ref_pk . " = " . $ilDB->quote($a_node_id, "integer");
142  return $ilDB->manipulate($query);
143  }
144 
148  public function cascadingDelete()
149  {
150  $root_id = $this->readRootId();
151  if (!$root_id) {
152  return;
153  }
154 
155  $root = $this->getNodeData($root_id);
156 
157  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
158  $access_handler = new ilWorkspaceAccessHandler($this);
159 
160  // delete node data
161  $nodes = $this->getSubTree($root);
162  foreach ($nodes as $node) {
163  $access_handler->removePermission($node["wsp_id"]);
164 
165  $object = ilObjectFactory::getInstanceByObjId($node["obj_id"], false);
166  if ($object) {
167  $object->delete();
168  }
169 
170  $this->deleteReference($node["wsp_id"]);
171  }
172 
173  $this->deleteTree($root);
174  }
175 
183  public function getObjectsFromType($a_type, $a_with_data = false)
184  {
185  return $this->getSubTree(
186  $this->getNodeData($this->getRootId()),
187  $a_with_data,
188  $a_type
189  );
190  }
191 
197  public function createTreeForUser($a_user_id)
198  {
199  $root = ilObjectFactory::getClassByType("wsrt");
200  $root = new $root(null);
201  $root->create();
202 
203  $root_id = $this->createReference($root->getId());
204  $this->addTree($a_user_id, $root_id);
205  $this->setRootId($root_id);
206  }
207 }
static getClassByType($a_obj_type)
Get class by type.
createTreeForUser($a_user_id)
Create personal workspace tree for user.
global $DIC
Definition: saml.php:7
createReference($a_object_id)
Create workspace reference for object.
cascadingDelete()
Remove all tree and node data.
Access handler for personal workspace.
deleteTree($a_node)
delete node and the whole subtree under this node public
setObjectTablePK($a_column_name)
set column containing primary key in object table public
deleteReference($a_node_id)
Delete object from reference table.
Tree handler for personal workspace.
getObjectsFromType($a_type, $a_with_data=false)
Get all workspace objects of specific type.
$a_type
Definition: workflow.php:92
foreach($_POST as $key=> $value) $res
__construct($a_tree_id, $a_root_id=0)
getRootId()
get the root id of tree public
getNodeData($a_node_id, $a_tree_pk=null)
get all information of a node.
setRootId($a_root_id)
$query
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 &#39;obj_id&#39; You may use...
insertObject($a_parent_node_id, $a_object_id)
Add object to tree.
lookupNodeId($a_obj_id)
Get node id for object id.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Create styles array
The data for the language used.
setTreeTablePK($a_column_name)
set column containing primary key in tree table public
setReferenceTablePK($a_column_name)
set column containing primary key in reference table 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 public
lookupObjectId($a_node_id)
Get object id for node id.
global $ilDB
getSubTree($a_node, $a_with_data=true, $a_type="")
get all nodes in the subtree under specified node
addTree($a_tree_id, $a_node_id=-1)
create a new tree to do: ???
lookupOwner($a_node_id)
Get owner for node id.
readRootId()
read root id from database