ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjMediaPool.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once "classes/class.ilObject.php";
5 require_once "./Services/MetaData/classes/class.ilMDLanguageItem.php";
6 require_once("./Modules/Folder/classes/class.ilObjFolder.php");
7 require_once("./Modules/MediaPool/classes/class.ilMediaPoolItem.php");
8 
21 class ilObjMediaPool extends ilObject
22 {
23  var $tree;
24 
31  function ilObjMediaPool($a_id = 0,$a_call_by_reference = true)
32  {
33  // this also calls read() method! (if $a_id is set)
34  $this->type = "mep";
35  $this->ilObject($a_id,$a_call_by_reference);
36  }
37 
43  function setDefaultWidth($a_val)
44  {
45  $this->default_width = $a_val;
46  }
47 
53  function getDefaultWidth()
54  {
55  return $this->default_width;
56  }
57 
63  function setDefaultHeight($a_val)
64  {
65  $this->default_height = $a_val;
66  }
67 
73  function getDefaultHeight()
74  {
75  return $this->default_height;
76  }
77 
81  function read()
82  {
83  global $ilDB;
84 
85  parent::read();
86 
87  $set = $ilDB->query("SELECT * FROM mep_data ".
88  " WHERE id = ".$ilDB->quote($this->getId(), "integer")
89  );
90  if ($rec = $ilDB->fetchAssoc($set))
91  {
92  $this->setDefaultWidth($rec["default_width"]);
93  $this->setDefaultHeight($rec["default_height"]);
94  }
95  $this->tree = ilObjMediaPool::getPoolTree($this->getId());
96  }
97 
98 
106  static function getPoolTree($a_obj_id)
107  {
108  $tree = new ilTree($a_obj_id);
109  $tree->setTreeTablePK("mep_id");
110  $tree->setTableNames("mep_tree", "mep_item");
111 
112  return $tree;
113  }
114 
118  function create()
119  {
120  global $ilDB;
121 
122  parent::create();
123 
124  $ilDB->manipulate("INSERT INTO mep_data ".
125  "(id) VALUES (".
126  $ilDB->quote($this->getId(), "integer").
127  ")");
128 
129  // create media pool tree
130  $this->tree =& new ilTree($this->getId());
131  $this->tree->setTreeTablePK("mep_id");
132  $this->tree->setTableNames('mep_tree','mep_item');
133  $this->tree->addTree($this->getId(), 1);
134 
135  }
136 
140  function &getTree()
141  {
142  return $this->tree;
143  }
144 
151  function update()
152  {
153  global $ilDB;
154 
155  if (!parent::update())
156  {
157  return false;
158  }
159 
160  // put here object specific stuff
161  $ilDB->manipulate("UPDATE mep_data SET ".
162  " default_width = ".$ilDB->quote($this->getDefaultWidth(), "integer").",".
163  " default_height = ".$ilDB->quote($this->getDefaultHeight(), "integer").
164  " WHERE id = ".$ilDB->quote($this->getId(), "integer")
165  );
166 
167  return true;
168  }
169 
170 
181  function delete()
182  {
183  // always call parent delete function first!!
184  if (!parent::delete())
185  {
186  return false;
187  }
188 
189  // get childs
190  $childs = $this->tree->getSubTree($this->tree->getNodeData($this->tree->readRootId()));
191 
192  // delete tree
193  $this->tree->removeTree($this->tree->getTreeId());
194 
195  // delete childs
196  foreach ($childs as $child)
197  {
198  $fid = ilMediaPoolItem::lookupForeignId($child["obj_id"]);
199  switch ($child["type"])
200  {
201  case "mob":
202  if (ilObject::_lookupType($fid) == "mob")
203  {
204  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
205  $mob = new ilObjMediaObject($fid);
206  $mob->delete();
207  }
208  break;
209 
210 /* case "fold":
211  if (ilObject::_lookupType($fid) == "fold")
212  {
213  include_once("./Modules/Folder/classes/class.ilObjFolder.php");
214  $fold = new ilObjFolder($fid, false);
215  $fold->delete();
216  }
217  break;*/
218  }
219  }
220 
221  return true;
222  }
223 
233  function initDefaultRoles()
234  {
235  global $rbacadmin;
236 
237  // create a local role folder
238  //$rfoldObj = $this->createRoleFolder("Local roles","Role Folder of forum obj_no.".$this->getId());
239 
240  // create moderator role and assign role to rolefolder...
241  //$roleObj = $rfoldObj->createRole("Moderator","Moderator of forum obj_no.".$this->getId());
242  //$roles[] = $roleObj->getId();
243 
244  //unset($rfoldObj);
245  //unset($roleObj);
246 
247  return $roles ? $roles : array();
248  }
249 
263  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
264  {
265  global $tree;
266 
267  switch ($a_event)
268  {
269  case "link":
270 
271  //var_dump("<pre>",$a_params,"</pre>");
272  //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
273  //exit;
274  break;
275 
276  case "cut":
277 
278  //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
279  //exit;
280  break;
281 
282  case "copy":
283 
284  //var_dump("<pre>",$a_params,"</pre>");
285  //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
286  //exit;
287  break;
288 
289  case "paste":
290 
291  //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
292  //exit;
293  break;
294 
295  case "new":
296 
297  //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
298  //exit;
299  break;
300  }
301 
302  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
303  if ($a_node_id==$_GET["ref_id"])
304  {
305  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
306  $parent_type = $parent_obj->getType();
307  if($parent_type == $this->getType())
308  {
309  $a_node_id = (int) $tree->getParentId($a_node_id);
310  }
311  }
312 
313  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
314  }
315 
316 
320  function getChilds($obj_id = "", $a_type = "")
321  {
322  $objs = array();
323  $mobs = array();
324  $pgs = array();
325  if ($obj_id == "")
326  {
327  $obj_id = $this->tree->getRootId();
328  }
329 
330  if ($a_type == "fold" || $a_type == "")
331  {
332  $objs = $this->tree->getChildsByType($obj_id, "fold");
333  }
334  if ($a_type == "mob" || $a_type == "")
335  {
336  $mobs = $this->tree->getChildsByType($obj_id, "mob");
337  }
338  foreach($mobs as $key => $mob)
339  {
340  $objs[] = $mob;
341  }
342  if ($a_type == "pg" || $a_type == "")
343  {
344  $pgs = $this->tree->getChildsByType($obj_id, "pg");
345  }
346  foreach($pgs as $key => $pg)
347  {
348  $objs[] = $pg;
349  }
350 
351  return $objs;
352  }
353 
357  function getChildsExceptFolders($obj_id = "")
358  {
359  $objs = array();
360  $mobs = array();
361  if ($obj_id == "")
362  {
363  $obj_id = $this->tree->getRootId();
364  }
365 
366  $objs = $this->tree->getFilteredChilds(array("fold", "dummy"), $obj_id);
367  return $objs;
368  }
369 
373  function getMediaObjects($a_title_filter = "", $a_format_filter = "")
374  {
375  global $ilDB;
376 
377  $query = "SELECT DISTINCT mep_tree.*, object_data.* ".
378  "FROM mep_tree JOIN mep_item ON (mep_tree.child = mep_item.obj_id) ".
379  " JOIN object_data ON (mep_item.foreign_id = object_data.obj_id) ";
380 
381  if ($a_format_filter != "")
382  {
383  $query.= " JOIN media_item ON (media_item.mob_id = object_data.obj_id) ";
384  }
385 
386  $query .=
387  " WHERE mep_tree.mep_id = ".$ilDB->quote($this->getId(), "integer").
388  " AND object_data.type = ".$ilDB->quote("mob", "text");
389 
390  // filter
391  if (trim($a_title_filter) != "") // title
392  {
393  $query.= " AND ".$ilDB->like("object_data.title", "text", "%".trim($a_title_filter)."%");
394  }
395  if ($a_format_filter != "") // format
396  {
397  $filter = ($a_format_filter == "unknown")
398  ? ""
399  : $a_format_filter;
400  $query.= " AND ".$ilDB->equals("media_item.format", $filter, "text", true);
401  }
402 
403  $query.=
404  " ORDER BY object_data.title";
405 
406  $objs = array();
407  $set = $ilDB->query($query);
408  while ($rec = $ilDB->fetchAssoc($set))
409  {
410  $rec["foreign_id"] = $rec["obj_id"];
411  $rec["obj_id"] = "";
412  $objs[] = $rec;
413  }
414  return $objs;
415  }
416 
420  function getUsedFormats()
421  {
422  global $ilDB, $lng;
423 
424  $query = "SELECT DISTINCT media_item.format f FROM mep_tree ".
425  " JOIN mep_item ON (mep_item.obj_id = mep_tree.child) ".
426  " JOIN object_data ON (mep_item.foreign_id = object_data.obj_id) ".
427  " JOIN media_item ON (media_item.mob_id = object_data.obj_id) ".
428  " WHERE mep_tree.mep_id = ".$ilDB->quote($this->getId(), "integer").
429  " AND object_data.type = ".$ilDB->quote("mob", "text").
430  " ORDER BY f";
431  $formats = array();
432  $set = $ilDB->query($query);
433  while ($rec = $ilDB->fetchAssoc($set))
434  {
435  if ($rec["f"] != "")
436  {
437  $formats[$rec["f"]] = $rec["f"];
438  }
439  else
440  {
441  $formats["unknown"] = $lng->txt("mep_unknown");
442  }
443  }
444 
445  return $formats;
446  }
447 
448  function getParentId($obj_id = "")
449  {
450  if ($obj_id == "")
451  {
452  return false;
453  }
454  if ($obj_id == $this->tree->getRootId())
455  {
456  return false;
457  }
458 
459  return $this->tree->getParentId($obj_id);
460  }
461 
467  function insertInTree($a_obj_id, $a_parent = "")
468  {
469  if (!$this->tree->isInTree($a_obj_id))
470  {
471  $parent = ($a_parent == "")
472  ? $this->tree->getRootId()
473  : $a_parent;
474  $this->tree->insertNode($a_obj_id, $parent);
475  return true;
476  }
477  else
478  {
479  return false;
480  }
481  }
482 
483 
488  function deleteChild($obj_id)
489  {
490  $fid = ilMediaPoolItem::lookupForeignId($obj_id);
493 
494  $node_data = $this->tree->getNodeData($obj_id);
495  $subtree = $this->tree->getSubtree($node_data);
496 
497  // delete tree
498  if($this->tree->isInTree($obj_id))
499  {
500  $this->tree->deleteTree($node_data);
501  }
502 
503  // delete objects
504  foreach ($subtree as $node)
505  {
506  $fid = ilMediaPoolItem::lookupForeignId($node["child"]);
507  if ($node["type"] == "mob")
508  {
509  if (ilObject::_lookupType($fid) == "mob")
510  {
511  $obj =& new ilObjMediaObject($fid);
512  $obj->delete();
513  }
514  }
515 
516  if ($node["type"] == "fold")
517  {
518  if ($fid > 0 && ilObject::_lookupType($fid) == "fold")
519  {
520  $obj = new ilObjFolder($fid, false);
521  $obj->delete();
522  }
523  }
524 
525  if ($node["type"] == "pg")
526  {
527  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
528  if (ilMediaPoolPage::_exists($node["child"]))
529  {
530  $pg = new ilMediaPoolPage($node["child"]);
531  $pg->delete();
532  }
533  }
534 
535  include_once("./Modules/MediaPool/classes/class.ilMediaPoolItem.php");
536  $item = new ilMediaPoolItem($node["child"]);
537  $item->delete();
538  }
539  }
540 
547  static function isForeignIdInTree($a_pool_id, $a_foreign_id)
548  {
549  global $ilDB;
550 
551  $set = $ilDB->query("SELECT * FROM mep_tree JOIN mep_item ON (child = obj_id) WHERE ".
552  " foreign_id = ".$ilDB->quote($a_foreign_id, "integer").
553  " AND mep_id = ".$ilDB->quote($a_pool_id, "integer")
554  );
555  if ($rec = $ilDB->fetchAssoc($set))
556  {
557  return true;
558  }
559  return false;
560  }
561 
565  static function isItemIdInTree($a_pool_id, $a_item_id)
566  {
567  global $ilDB;
568 
569  $set = $ilDB->query("SELECT * FROM mep_tree WHERE child = ".
570  $ilDB->quote($a_item_id, "integer").
571  " AND mep_id = ".$ilDB->quote($a_pool_id, "integer"));
572  if ($rec = $ilDB->fetchAssoc($set))
573  {
574  return true;
575  }
576  return false;
577  }
578 
579 }
580 ?>