ILIAS  release_8 Revision v8.24
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
global $DIC
Definition: feed.php:28
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$query