ILIAS  release_7 Revision v7.30-3-g800a261c036
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
13{
17 protected $db;
18
19 public function __construct($a_tree_id, $a_root_id = 0)
20 {
21 global $DIC;
22
23 $this->db = $DIC->database();
24 parent::__construct($a_tree_id, $a_root_id);
25
26 $this->setTableNames('tree_workspace', 'object_data', 'object_reference_ws');
27 $this->setTreeTablePK('tree');
28 $this->setObjectTablePK('obj_id');
29 $this->setReferenceTablePK('wsp_id');
30
31 // ilTree sets it to ROOT_FOLDER_ID if not given...
32 if (!$a_root_id) {
33 $this->readRootId();
34 }
35 }
36
43 public function createReference($a_object_id)
44 {
46
47 $next_id = $ilDB->nextId($this->table_obj_reference);
48
49 $fields = array($this->ref_pk => array("integer", $next_id),
50 $this->obj_pk => array("integer", $a_object_id));
51
52 $ilDB->insert($this->table_obj_reference, $fields);
53
54 return $next_id;
55 }
56
63 public function lookupObjectId($a_node_id)
64 {
66
67 $set = $ilDB->query("SELECT " . $this->obj_pk .
68 " FROM " . $this->table_obj_reference .
69 " WHERE " . $this->ref_pk . " = " . $ilDB->quote($a_node_id, "integer"));
70 $res = $ilDB->fetchAssoc($set);
71
72 return $res[$this->obj_pk];
73 }
74
75
84 public function lookupNodeId($a_obj_id)
85 {
87
88 $set = $ilDB->query("SELECT " . $this->ref_pk .
89 " FROM " . $this->table_obj_reference .
90 " WHERE " . $this->obj_pk . " = " . $ilDB->quote($a_obj_id, "integer"));
91 $res = $ilDB->fetchAssoc($set);
92
93 return (int) $res[$this->ref_pk];
94 }
95
102 public function lookupOwner($a_node_id)
103 {
105
106 $set = $ilDB->query("SELECT tree" .
107 " FROM " . $this->table_obj_reference .
108 " JOIN " . $this->table_tree . " ON (" . $this->table_obj_reference . "." . $this->ref_pk . " = " . $this->table_tree . ".child)" .
109 " WHERE " . $this->ref_pk . " = " . $ilDB->quote($a_node_id, "integer"));
110 $res = $ilDB->fetchAssoc($set);
111
112 return $res["tree"];
113 }
114
122 public function insertObject($a_parent_node_id, $a_object_id)
123 {
124 $node_id = $this->createReference($a_object_id);
125 $this->insertNode($node_id, $a_parent_node_id);
126 return $node_id;
127 }
128
135 public function deleteReference($a_node_id)
136 {
138
139 $query = "DELETE FROM " . $this->table_obj_reference .
140 " WHERE " . $this->ref_pk . " = " . $ilDB->quote($a_node_id, "integer");
141 return $ilDB->manipulate($query);
142 }
143
147 public function cascadingDelete()
148 {
149 $root_id = $this->readRootId();
150 if (!$root_id) {
151 return;
152 }
153
154 $root = $this->getNodeData($root_id);
155
156 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
157 $access_handler = new ilWorkspaceAccessHandler($this);
158
159 // delete node data
160 $nodes = $this->getSubTree($root);
161 foreach ($nodes as $node) {
162 $access_handler->removePermission($node["wsp_id"]);
163
164 $object = ilObjectFactory::getInstanceByObjId($node["obj_id"], false);
165 if ($object) {
166 $object->delete();
167 }
168
169 $this->deleteReference($node["wsp_id"]);
170 }
171
172 $this->deleteTree($root);
173 }
174
182 public function getObjectsFromType($a_type, $a_with_data = false)
183 {
184 return $this->getSubTree(
185 $this->getNodeData($this->getRootId()),
186 $a_with_data,
187 $a_type
188 );
189 }
190
196 public function createTreeForUser($a_user_id)
197 {
198 $root = ilObjectFactory::getClassByType("wsrt");
199 $root = new $root(null);
200 $root->create();
201
202 $root_id = $this->createReference($root->getId());
203 $this->addTree($a_user_id, $root_id);
204 $this->setRootId($root_id);
205 }
206}
An exception for terminatinating execution or to throw for unit testing.
static 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.
getObjectsFromType($a_type, $a_with_data=false)
Get all workspace objects of specific type.
__construct($a_tree_id, $a_root_id=0)
Constructor @access public.
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 $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$query
foreach($_POST as $key=> $value) $res
global $ilDB