ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
15  public function __construct($a_tree_id, $a_root_id = 0)
16  {
17  parent::__construct($a_tree_id, $a_root_id);
18 
19  $this->table_tree = 'tree_workspace';
20  $this->table_obj_data = 'object_data';
21  $this->table_obj_reference = 'object_reference_ws';
22  $this->ref_pk = 'wsp_id';
23  $this->obj_pk = 'obj_id';
24  $this->tree_pk = 'tree';
25 
26  // ilTree sets it to ROOT_FOLDER_ID if not given...
27  if(!$a_root_id)
28  {
29  $this->root_id = $this->readRootId();
30  }
31  }
32 
39  public function createReference($a_object_id)
40  {
41  global $ilDB;
42 
43  $next_id = $ilDB->nextId($this->table_obj_reference);
44 
45  $fields = array($this->ref_pk => array("integer", $next_id),
46  $this->obj_pk => array("integer", $a_object_id));
47 
48  $ilDB->insert($this->table_obj_reference, $fields);
49 
50  return $next_id;
51  }
52 
59  public function lookupObjectId($a_node_id)
60  {
61  global $ilDB;
62 
63  $set = $ilDB->query("SELECT ".$this->obj_pk.
64  " FROM ".$this->table_obj_reference.
65  " WHERE ".$this->ref_pk." = ".$ilDB->quote($a_node_id, "integer"));
66  $res = $ilDB->fetchAssoc($set);
67 
68  return $res[$this->obj_pk];
69  }
70 
71 
80  public function lookupNodeId($a_obj_id)
81  {
82  global $ilDB;
83 
84  $set = $ilDB->query("SELECT ".$this->ref_pk.
85  " FROM ".$this->table_obj_reference.
86  " WHERE ".$this->obj_pk." = ".$ilDB->quote($a_obj_id, "integer"));
87  $res = $ilDB->fetchAssoc($set);
88 
89  return $res[$this->ref_pk];
90  }
91 
98  public function lookupOwner($a_node_id)
99  {
100  global $ilDB;
101 
102  $set = $ilDB->query("SELECT tree".
103  " FROM ".$this->table_obj_reference.
104  " JOIN ".$this->table_tree." ON (".$this->table_obj_reference.".".$this->ref_pk." = ".$this->table_tree.".child)".
105  " WHERE ".$this->ref_pk." = ".$ilDB->quote($a_node_id, "integer"));
106  $res = $ilDB->fetchAssoc($set);
107 
108  return $res["tree"];
109  }
110 
118  public function insertObject($a_parent_node_id, $a_object_id)
119  {
120  $node_id = $this->createReference($a_object_id);
121  $this->insertNode($node_id, $a_parent_node_id);
122  return $node_id;
123  }
124 
131  public function deleteReference($a_node_id)
132  {
133  global $ilDB;
134 
135  $query = "DELETE FROM ".$this->table_obj_reference.
136  " WHERE ".$this->ref_pk." = ".$ilDB->quote($a_node_id, "integer");
137  return $ilDB->manipulate($query);
138  }
139 
143  public function cascadingDelete()
144  {
145  $root_id = $this->readRootId();
146  if(!$root_id)
147  {
148  return;
149  }
150 
151  $root = $this->getNodeData($root_id);
152 
153  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
154  $access_handler = new ilWorkspaceAccessHandler($this);
155 
156  // delete node data
157  $nodes = $this->getSubTree($root);
158  foreach($nodes as $node)
159  {
160  $access_handler->removePermission($node["wsp_id"]);
161 
162  $object = ilObjectFactory::getInstanceByObjId($node["obj_id"], false);
163  if($object)
164  {
165  $object->delete();
166  }
167 
168  $this->deleteReference($node["wsp_id"]);
169  }
170 
171  $this->deleteTree($root);
172  }
173 
180  public function getObjectsFromType($a_type)
181  {
182  return $this->getSubTree(
183  $this->getNodeData($this->getRootId()),
184  false, $a_type);
185  }
186 
192  public function createTreeForUser($a_user_id)
193  {
194  $root = ilObjectFactory::getClassByType("wsrt");
195  $root = new $root(null);
196  $root->create();
197 
198  $root_id = $this->createReference($root->getId());
199  $this->addTree($a_user_id, $root_id);
200  $this->setRootId($root_id);
201  }
202 }
203 
204 ?>