ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjMediaPool.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
25 require_once "classes/class.ilObject.php";
26 require_once "./Services/MetaData/classes/class.ilMDLanguageItem.php";
27 require_once("./Modules/Folder/classes/class.ilObjFolder.php");
28 
41 class ilObjMediaPool extends ilObject
42 {
43  var $tree;
44 
51  function ilObjMediaPool($a_id = 0,$a_call_by_reference = true)
52  {
53  // this also calls read() method! (if $a_id is set)
54  $this->type = "mep";
55  $this->ilObject($a_id,$a_call_by_reference);
56  }
57 
61  function read()
62  {
63  parent::read();
64 
65  $this->tree = ilObjMediaPool::getPoolTree($this->getId());
66  }
67 
75  static function getPoolTree($a_obj_id)
76  {
77  $tree = new ilTree($a_obj_id);
78  $tree->setTreeTablePK("mep_id");
79  $tree->setTableNames("mep_tree", "object_data");
80 
81  return $tree;
82  }
83 
87  function create()
88  {
90 
91  // create media pool tree
92  $this->tree =& new ilTree($this->getId());
93  $this->tree->setTreeTablePK("mep_id");
94  $this->tree->setTableNames('mep_tree','object_data');
95  $this->tree->addTree($this->getId(), 1);
96 
97  }
98 
102  function &getTree()
103  {
104  return $this->tree;
105  }
106 
113  function update()
114  {
115  if (!parent::update())
116  {
117  return false;
118  }
119 
120  // put here object specific stuff
121 
122  return true;
123  }
124 
125 
136  function delete()
137  {
138  // always call parent delete function first!!
139  if (!parent::delete())
140  {
141  return false;
142  }
143 
144  // get childs
145  $childs = $this->tree->getSubTree($this->tree->getNodeData($this->tree->readRootId()));
146 
147  // delete tree
148  $this->tree->removeTree($this->tree->getTreeId());
149 
150  // delete childs
151  foreach ($childs as $child)
152  {
153  switch ($child["type"])
154  {
155  case "mob":
156  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
157  $mob = new ilObjMediaObject($child["obj_id"]);
158  $mob->delete();
159  break;
160 
161  case "fold":
162  include_once("./Modules/Folder/classes/class.ilObjFolder.php");
163  $fold = new ilObjFolder($child["obj_id"], false);
164  $fold->delete();
165  break;
166  }
167  }
168 
169 
170 
171  return true;
172  }
173 
183  function initDefaultRoles()
184  {
185  global $rbacadmin;
186 
187  // create a local role folder
188  //$rfoldObj = $this->createRoleFolder("Local roles","Role Folder of forum obj_no.".$this->getId());
189 
190  // create moderator role and assign role to rolefolder...
191  //$roleObj = $rfoldObj->createRole("Moderator","Moderator of forum obj_no.".$this->getId());
192  //$roles[] = $roleObj->getId();
193 
194  //unset($rfoldObj);
195  //unset($roleObj);
196 
197  return $roles ? $roles : array();
198  }
199 
213  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
214  {
215  global $tree;
216 
217  switch ($a_event)
218  {
219  case "link":
220 
221  //var_dump("<pre>",$a_params,"</pre>");
222  //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
223  //exit;
224  break;
225 
226  case "cut":
227 
228  //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
229  //exit;
230  break;
231 
232  case "copy":
233 
234  //var_dump("<pre>",$a_params,"</pre>");
235  //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
236  //exit;
237  break;
238 
239  case "paste":
240 
241  //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
242  //exit;
243  break;
244 
245  case "new":
246 
247  //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
248  //exit;
249  break;
250  }
251 
252  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
253  if ($a_node_id==$_GET["ref_id"])
254  {
255  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
256  $parent_type = $parent_obj->getType();
257  if($parent_type == $this->getType())
258  {
259  $a_node_id = (int) $tree->getParentId($a_node_id);
260  }
261  }
262 
263  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
264  }
265 
266 
270  function getChilds($obj_id = "", $a_type = "")
271  {
272  $objs = array();
273  $mobs = array();
274  if ($obj_id == "")
275  {
276  $obj_id = $this->tree->getRootId();
277  }
278 
279  if ($a_type != "mob")
280  {
281  $objs = $this->tree->getChildsByType($obj_id, "fold");
282  }
283  if ($a_type != "fold")
284  {
285  $mobs = $this->tree->getChildsByType($obj_id, "mob");
286  }
287  foreach($mobs as $key => $mob)
288  {
289  $objs[] = $mob;
290  }
291 
292  return $objs;
293  }
294 
295  function getParentId($obj_id = "")
296  {
297  if ($obj_id == "")
298  {
299  return false;
300  }
301  if ($obj_id == $this->tree->getRootId())
302  {
303  return false;
304  }
305 
306  return $this->tree->getParentId($obj_id);
307  }
308 
309  function insertInTree($a_obj_id, $a_parent = "")
310  {
311  if (!$this->tree->isInTree($a_obj_id))
312  {
313  $parent = ($a_parent == "")
314  ? $this->tree->getRootId()
315  : $a_parent;
316  $this->tree->insertNode($a_obj_id, $parent);
317  return true;
318  }
319  else
320  {
321  return false;
322  }
323  }
324 
325 
326  function deleteChild($obj_id)
327  {
328  $type = ilObject::_lookupType($obj_id);
329  $title = ilObject::_lookupTitle($obj_id);
330 
331 
332  $node_data = $this->tree->getNodeData($obj_id);
333  $subtree = $this->tree->getSubtree($node_data);
334 
335  // delete tree
336  if($this->tree->isInTree($obj_id))
337  {
338  $this->tree->deleteTree($node_data);
339  }
340 
341  // delete objects
342  foreach ($subtree as $node)
343  {
344  if ($node["type"] == "mob")
345  {
346  $obj =& new ilObjMediaObject($node["child"]);
347  $obj->delete();
348  }
349 
350  if ($node["type"] == "fold")
351  {
352  $obj =& new ilObjFolder($node["child"], false);
353  $obj->delete();
354  }
355  }
356  }
357 }
358 ?>