ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWorkspaceTree.php
Go to the documentation of this file.
1<?php
2
25{
26 public function __construct(
27 int $a_tree_id,
28 int $a_root_id = 0
29 ) {
30 global $DIC;
31
32 parent::__construct($a_tree_id, $a_root_id);
33 $this->setTableNames('tree_workspace', 'object_data', 'object_reference_ws');
34 $this->setTreeTablePK('tree');
35 $this->setObjectTablePK('obj_id');
36 $this->setReferenceTablePK('wsp_id');
37
38 if (!$this->exists()) {
39 $this->createTreeForUser($a_tree_id);
40 }
41
42 // ilTree sets it to ROOT_FOLDER_ID if not given...
43 if (!$a_root_id) {
44 $this->readRootId();
45 }
46 }
47
48 protected function exists(): bool
49 {
50 $db = $this->db;
51 $set = $db->queryF(
52 "SELECT * FROM tree_workspace " .
53 " WHERE tree = %s ",
54 ["integer"],
55 [$this->getTreeId()]
56 );
57 if ($rec = $db->fetchAssoc($set)) {
58 return true;
59 }
60 return false;
61 }
62
68 public function createReference(int $a_object_id): int
69 {
71
72 $next_id = $ilDB->nextId($this->table_obj_reference);
73
74 $fields = array($this->ref_pk => array("integer", $next_id),
75 $this->obj_pk => array("integer", $a_object_id));
76
77 $ilDB->insert($this->table_obj_reference, $fields);
78
79 return $next_id;
80 }
81
87 public function lookupObjectId(int $a_node_id): int
88 {
90
91 $set = $ilDB->query("SELECT " . $this->obj_pk .
92 " FROM " . $this->table_obj_reference .
93 " WHERE " . $this->ref_pk . " = " . $ilDB->quote($a_node_id, "integer"));
94 $res = $ilDB->fetchAssoc($set);
95
96 return (int) ($res[$this->obj_pk] ?? 0);
97 }
98
99
106 public function lookupNodeId(int $a_obj_id): int
107 {
109
110 $set = $ilDB->query("SELECT " . $this->ref_pk .
111 " FROM " . $this->table_obj_reference .
112 " WHERE " . $this->obj_pk . " = " . $ilDB->quote($a_obj_id, "integer"));
113 $res = $ilDB->fetchAssoc($set);
114
115 return (int) ($res[$this->ref_pk] ?? 0);
116 }
117
123 public function lookupOwner(int $a_node_id): int
124 {
126
127 $set = $ilDB->query("SELECT tree" .
128 " FROM " . $this->table_obj_reference .
129 " JOIN " . $this->table_tree . " ON (" . $this->table_obj_reference . "." . $this->ref_pk . " = " . $this->table_tree . ".child)" .
130 " WHERE " . $this->ref_pk . " = " . $ilDB->quote($a_node_id, "integer"));
131 $res = $ilDB->fetchAssoc($set);
132
133 return (int) ($res["tree"] ?? 0);
134 }
135
143 public function insertObject(
144 int $a_parent_node_id,
145 int $a_object_id
146 ): int {
147 $node_id = $this->createReference($a_object_id);
148 $this->insertNode($node_id, $a_parent_node_id);
149 return $node_id;
150 }
151
155 public function deleteReference(int $a_node_id): int
156 {
157 $ilDB = $this->db;
158
159 $query = "DELETE FROM " . $this->table_obj_reference .
160 " WHERE " . $this->ref_pk . " = " . $ilDB->quote($a_node_id, "integer");
161 return $ilDB->manipulate($query);
162 }
163
167 public function cascadingDelete(): void
168 {
169 $root_id = $this->readRootId();
170 if (!$root_id) {
171 return;
172 }
173
174 $root = $this->getNodeData($root_id);
175
176 $access_handler = new ilWorkspaceAccessHandler($this);
177
178 // delete node data
179 $nodes = $this->getSubTree($root);
180 foreach ($nodes as $node) {
181 $access_handler->removePermission($node["wsp_id"]);
182
183 $object = ilObjectFactory::getInstanceByObjId($node["obj_id"], false);
184 if ($object) {
185 $object->delete();
186 }
187
188 $this->deleteReference($node["wsp_id"]);
189 }
190
191 $this->deleteTree($root);
192 }
193
198 public function getObjectsFromType(
199 string $a_type,
200 bool $a_with_data = false
201 ): array {
202 return $this->getSubTree(
203 $this->getNodeData($this->getRootId()),
204 $a_with_data,
205 [$a_type]
206 );
207 }
208
213 public function createTreeForUser(int $a_user_id): void
214 {
215 $root = ilObjectFactory::getClassByType("wsrt");
216 $root = new $root(0);
217 $root->create();
218
219 $root_id = $this->createReference($root->getId());
220 $this->addTree($a_user_id, $root_id);
221 $this->setRootId($root_id);
222 }
223}
static getClassByType(string $obj_type)
static getInstanceByObjId(?int $obj_id, bool $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...
setReferenceTablePK(string $a_column_name)
set column containing primary key in reference table
insertNode(int $a_node_id, int $a_parent_id, int $a_pos=self::POS_LAST_NODE, bool $a_reset_deletion_date=false)
insert new node with node_id under parent node with parent_id
string $ref_pk
column name containing primary key in reference table
ilDBInterface $db
string $obj_pk
column name containing primary key in object table
setTreeTablePK(string $a_column_name)
set column containing primary key in tree table
setObjectTablePK(string $a_column_name)
set column containing primary key in object table
setTableNames(string $a_table_tree, string $a_table_obj_data, string $a_table_obj_reference="")
set table names The primary key of the table containing your object_data must be 'obj_id' You may use...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(int $a_tree_id, int $a_root_id=0)
createReference(int $a_object_id)
Create workspace reference for object.
deleteReference(int $a_node_id)
Delete object from reference table.
cascadingDelete()
Remove all tree and node data.
lookupObjectId(int $a_node_id)
Get object id for node id.
lookupNodeId(int $a_obj_id)
Get node id for object id As we do not allow references in workspace this should not be ambigious.
getObjectsFromType(string $a_type, bool $a_with_data=false)
Get all workspace objects of specific type.
insertObject(int $a_parent_node_id, int $a_object_id)
Add object to tree.
lookupOwner(int $a_node_id)
Get owner for node id.
createTreeForUser(int $a_user_id)
Create personal workspace tree for user.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26