ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
4require_once "./Services/Object/classes/class.ilObject.php";
5require_once "./Services/MetaData/classes/class.ilMDLanguageItem.php";
6require_once("./Modules/Folder/classes/class.ilObjFolder.php");
7require_once("./Modules/MediaPool/classes/class.ilMediaPoolItem.php");
8
22{
23 protected $mep_tree;
24 public $for_translation = 0;
25
32 public function __construct($a_id = 0, $a_call_by_reference = true)
33 {
34 global $DIC;
35
36 $this->db = $DIC->database();
37 $this->lng = $DIC->language();
38 // this also calls read() method! (if $a_id is set)
39 $this->type = "mep";
40 parent::__construct($a_id, $a_call_by_reference);
41 }
42
48 public function setDefaultWidth($a_val)
49 {
50 $this->default_width = $a_val;
51 }
52
58 public function getDefaultWidth()
59 {
60 return $this->default_width;
61 }
62
68 public function setDefaultHeight($a_val)
69 {
70 $this->default_height = $a_val;
71 }
72
78 public function getDefaultHeight()
79 {
80 return $this->default_height;
81 }
82
88 public function setForTranslation($a_val)
89 {
90 $this->for_translation = $a_val;
91 }
92
98 public function getForTranslation()
99 {
101 }
102
106 public function read()
107 {
109
110 parent::read();
111
112 $set = $ilDB->query(
113 "SELECT * FROM mep_data " .
114 " WHERE id = " . $ilDB->quote($this->getId(), "integer")
115 );
116 if ($rec = $ilDB->fetchAssoc($set)) {
117 $this->setDefaultWidth($rec["default_width"]);
118 $this->setDefaultHeight($rec["default_height"]);
119 $this->setForTranslation($rec["for_translation"]);
120 }
121 $this->mep_tree = ilObjMediaPool::_getPoolTree($this->getId());
122 }
123
124
132 public static function _getPoolTree($a_obj_id)
133 {
134 $tree = new ilTree($a_obj_id);
135 $tree->setTreeTablePK("mep_id");
136 $tree->setTableNames("mep_tree", "mep_item");
137
138 return $tree;
139 }
140
146 public function getPoolTree()
147 {
148 return self::_getPoolTree($this->getId());
149 }
150
151
155 public function create()
156 {
158
159 parent::create();
160
161 $ilDB->manipulate("INSERT INTO mep_data " .
162 "(id, default_width, default_height, for_translation) VALUES (" .
163 $ilDB->quote($this->getId(), "integer") . ", " .
164 $ilDB->quote($this->getDefaultWidth(), "integer") . ", " .
165 $ilDB->quote($this->getDefaultHeight(), "integer") . ", " .
166 $ilDB->quote($this->getForTranslation(), "integer") .
167 ")");
168
169 $this->createMepTree();
170 }
171
178 public function createMepTree()
179 {
180 // create media pool tree
181 $this->mep_tree = new ilTree($this->getId());
182 $this->mep_tree->setTreeTablePK("mep_id");
183 $this->mep_tree->setTableNames('mep_tree', 'mep_item');
184 $this->mep_tree->addTree($this->getId(), 1);
185 }
186
187
191 public function &getTree()
192 {
193 return $this->mep_tree;
194 }
195
202 public function update()
203 {
205
206 if (!parent::update()) {
207 return false;
208 }
209
210 // put here object specific stuff
211 $ilDB->manipulate(
212 "UPDATE mep_data SET " .
213 " default_width = " . $ilDB->quote($this->getDefaultWidth(), "integer") . "," .
214 " default_height = " . $ilDB->quote($this->getDefaultHeight(), "integer") . "," .
215 " for_translation = " . $ilDB->quote($this->getForTranslation(), "integer") . " " .
216 " WHERE id = " . $ilDB->quote($this->getId(), "integer")
217 );
218
219 return true;
220 }
221
222
233 public function delete()
234 {
235 // always call parent delete function first!!
236 if (!parent::delete()) {
237 return false;
238 }
239
240 // get childs
241 $childs = $this->mep_tree->getSubTree($this->mep_tree->getNodeData($this->mep_tree->readRootId()));
242
243 // delete tree
244 $this->mep_tree->removeTree($this->mep_tree->getTreeId());
245
246 // delete childs
247 foreach ($childs as $child) {
248 $fid = ilMediaPoolItem::lookupForeignId($child["obj_id"]);
249 switch ($child["type"]) {
250 case "mob":
251 if (ilObject::_lookupType($fid) == "mob") {
252 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
253 $mob = new ilObjMediaObject($fid);
254 $mob->delete();
255 }
256 break;
257 }
258 }
259
260 return true;
261 }
262
266 public function getChilds($obj_id = "", $a_type = "")
267 {
268 $objs = array();
269 $mobs = array();
270 $pgs = array();
271 if ($obj_id == "") {
272 $obj_id = $this->mep_tree->getRootId();
273 }
274
275 if ($a_type == "fold" || $a_type == "") {
276 $objs = $this->mep_tree->getChildsByType($obj_id, "fold");
277 }
278 if ($a_type == "mob" || $a_type == "") {
279 $mobs = $this->mep_tree->getChildsByType($obj_id, "mob");
280 }
281 foreach ($mobs as $key => $mob) {
282 $objs[] = $mob;
283 }
284 if ($a_type == "pg" || $a_type == "") {
285 $pgs = $this->mep_tree->getChildsByType($obj_id, "pg");
286 }
287 foreach ($pgs as $key => $pg) {
288 $objs[] = $pg;
289 }
290
291 return $objs;
292 }
293
297 public function getChildsExceptFolders($obj_id = "")
298 {
299 if ($obj_id == "") {
300 $obj_id = $this->mep_tree->getRootId();
301 }
302
303 $objs = $this->mep_tree->getFilteredChilds(array("fold", "dummy"), $obj_id);
304 return $objs;
305 }
306
310 public function getMediaObjects($a_title_filter = "", $a_format_filter = "", $a_keyword_filter = '', $a_caption_filter)
311 {
313
314 $query = "SELECT DISTINCT mep_tree.*, object_data.* " .
315 "FROM mep_tree JOIN mep_item ON (mep_tree.child = mep_item.obj_id) " .
316 " JOIN object_data ON (mep_item.foreign_id = object_data.obj_id) ";
317
318 if ($a_format_filter != "" or $a_caption_filter != '') {
319 $query .= " JOIN media_item ON (media_item.mob_id = object_data.obj_id) ";
320 }
321
322 $query .=
323 " WHERE mep_tree.mep_id = " . $ilDB->quote($this->getId(), "integer") .
324 " AND object_data.type = " . $ilDB->quote("mob", "text");
325
326 // filter
327 if (trim($a_title_filter) != "") { // title
328 $query .= " AND " . $ilDB->like("object_data.title", "text", "%" . trim($a_title_filter) . "%");
329 }
330 if ($a_format_filter != "") { // format
331 $filter = ($a_format_filter == "unknown")
332 ? ""
333 : $a_format_filter;
334 $query .= " AND " . $ilDB->equals("media_item.format", $filter, "text", true);
335 }
336 if (trim($a_caption_filter)) {
337 $query .= 'AND ' . $ilDB->like('media_item.caption', 'text', '%' . trim($a_caption_filter) . '%');
338 }
339
340 $query .=
341 " ORDER BY object_data.title";
342
343 $objs = array();
344 $set = $ilDB->query($query);
345 while ($rec = $ilDB->fetchAssoc($set)) {
346 $rec["foreign_id"] = $rec["obj_id"];
347 $rec["obj_id"] = "";
348 $objs[] = $rec;
349 }
350
351 // Keyword filter
352 if ($a_keyword_filter) {
353 include_once './Services/MetaData/classes/class.ilMDKeyword.php';
354 $res = ilMDKeyword::_searchKeywords($a_keyword_filter, 'mob', 0);
355
356 foreach ($objs as $obj) {
357 if (in_array($obj['foreign_id'], $res)) {
358 $filtered[] = $obj;
359 }
360 }
361 return (array) $filtered;
362 }
363 return $objs;
364 }
365
366
371 public static function getAllMobIds($a_id)
372 {
373 global $DIC;
374
375 $ilDB = $DIC->database();
376
377 $query = "SELECT foreign_id as id FROM " .
378 " 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 " WHERE mep_tree.mep_id = " . $ilDB->quote($a_id, "integer") .
381 " AND mep_item.type = " . $ilDB->quote("mob", "text") .
382 " AND object_data.type = " . $ilDB->quote("mob", "text");
383 $set = $ilDB->query($query);
384 $ids = array();
385 while ($rec = $ilDB->fetchAssoc($set)) {
386 $ids[] = $rec["id"];
387 }
388 return $ids;
389 }
390
394 public function getUsedFormats()
395 {
398
399 $query = "SELECT DISTINCT media_item.format f FROM mep_tree " .
400 " JOIN mep_item ON (mep_item.obj_id = mep_tree.child) " .
401 " JOIN object_data ON (mep_item.foreign_id = object_data.obj_id) " .
402 " JOIN media_item ON (media_item.mob_id = object_data.obj_id) " .
403 " WHERE mep_tree.mep_id = " . $ilDB->quote($this->getId(), "integer") .
404 " AND object_data.type = " . $ilDB->quote("mob", "text") .
405 " ORDER BY f";
406 $formats = array();
407 $set = $ilDB->query($query);
408 while ($rec = $ilDB->fetchAssoc($set)) {
409 if ($rec["f"] != "") {
410 $formats[$rec["f"]] = $rec["f"];
411 } else {
412 $formats["unknown"] = $lng->txt("mep_unknown");
413 }
414 }
415
416 return $formats;
417 }
418
419 public function getParentId($obj_id = "")
420 {
421 if ($obj_id == "") {
422 return false;
423 }
424 if ($obj_id == $this->mep_tree->getRootId()) {
425 return false;
426 }
427
428 return $this->mep_tree->getParentId($obj_id);
429 }
430
436 public function insertInTree($a_obj_id, $a_parent = "")
437 {
438 if (!$this->mep_tree->isInTree($a_obj_id)) {
439 $parent = ($a_parent == "")
440 ? $this->mep_tree->getRootId()
441 : $a_parent;
442 $this->mep_tree->insertNode($a_obj_id, $parent);
443 return true;
444 } else {
445 return false;
446 }
447 }
448
449
454 public function deleteChild($obj_id)
455 {
456 $node_data = $this->mep_tree->getNodeData($obj_id);
457 $subtree = $this->mep_tree->getSubtree($node_data);
458
459 // delete tree
460 if ($this->mep_tree->isInTree($obj_id)) {
461 $this->mep_tree->deleteTree($node_data);
462 }
463
464 // delete objects
465 foreach ($subtree as $node) {
466 $fid = ilMediaPoolItem::lookupForeignId($node["child"]);
467 if ($node["type"] == "mob") {
468 if (ilObject::_lookupType($fid) == "mob") {
469 $obj = new ilObjMediaObject($fid);
470 $obj->delete();
471 }
472 }
473
474 if ($node["type"] == "fold") {
475 if ($fid > 0 && ilObject::_lookupType($fid) == "fold") {
476 $obj = new ilObjFolder($fid, false);
477 $obj->delete();
478 }
479 }
480
481 if ($node["type"] == "pg") {
482 include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
483 if (ilPageObject::_exists("mep", $node["child"])) {
484 $pg = new ilMediaPoolPage($node["child"]);
485 $pg->delete();
486 }
487 }
488
489 include_once("./Modules/MediaPool/classes/class.ilMediaPoolItem.php");
490 $item = new ilMediaPoolItem($node["child"]);
491 $item->delete();
492 }
493 }
494
501 public static function isForeignIdInTree($a_pool_id, $a_foreign_id)
502 {
503 global $DIC;
504
505 $ilDB = $DIC->database();
506
507 $set = $ilDB->query(
508 "SELECT * FROM mep_tree JOIN mep_item ON (child = obj_id) WHERE " .
509 " foreign_id = " . $ilDB->quote($a_foreign_id, "integer") .
510 " AND mep_id = " . $ilDB->quote($a_pool_id, "integer")
511 );
512 if ($rec = $ilDB->fetchAssoc($set)) {
513 return true;
514 }
515 return false;
516 }
517
521 public static function isItemIdInTree($a_pool_id, $a_item_id)
522 {
523 global $DIC;
524
525 $ilDB = $DIC->database();
526
527 $set = $ilDB->query("SELECT * FROM mep_tree WHERE child = " .
528 $ilDB->quote($a_item_id, "integer") .
529 " AND mep_id = " . $ilDB->quote($a_pool_id, "integer"));
530 if ($rec = $ilDB->fetchAssoc($set)) {
531 return true;
532 }
533 return false;
534 }
535
542 public function createFolder($a_title, $a_parent = 0)
543 {
544 // perform save
545 $mep_item = new ilMediaPoolItem();
546 $mep_item->setTitle($a_title);
547 $mep_item->setType("fold");
548 $mep_item->create();
549 if ($mep_item->getId() > 0) {
550 $tree = $this->getTree();
551 $parent = $a_parent > 0
552 ? $a_parent
553 : $tree->getRootId();
554 $this->insertInTree($mep_item->getId(), $parent);
555 return $mep_item->getId();
556 }
557 return false;
558 }
559
566 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
567 {
568 $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
569
570 $new_obj->setTitle($this->getTitle());
571 $new_obj->setDescription($this->getDescription());
572 $new_obj->setDefaultWidth($this->getDefaultWidth());
573 $new_obj->setDefaultHeight($this->getDefaultHeight());
574 $new_obj->update();
575
576 // copy content
577 $this->copyTreeContent(
578 $new_obj,
579 $new_obj->getTree()->readRootId(),
580 $this->getTree()->readRootId()
581 );
582
583 return $new_obj;
584 }
585
592 public function copyTreeContent($a_new_obj, $a_target_parent, $a_source_parent)
593 {
594 include_once("./Modules/MediaPool/classes/class.ilMediaPoolItem.php");
595 include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
596 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
597
598 // get all chapters of root lm
599 $nodes = $this->getTree()->getChilds($a_source_parent);
600 foreach ($nodes as $node) {
601 $item = new ilMediaPoolItem();
602 $item->setType($node["type"]);
603 switch ($node["type"]) {
604 case "mob":
605 $mob_id = ilMediaPoolItem::lookupForeignId($node["child"]);
606 $mob = new ilObjMediaObject($mob_id);
607 $new_mob = $mob->duplicate();
608 $item->setForeignId($new_mob->getId());
609 $item->setTitle($new_mob->getTitle());
610 $item->create();
611 break;
612
613 case "pg":
614 $item->setTitle($node["title"]);
615 $item->create();
616 $page = new ilMediaPoolPage($node["child"]);
617 $new_page = new ilMediaPoolPage();
618 $new_page->setParentId($a_new_obj->getId());
619 $new_page->setId($item->getId());
620 $new_page->create();
621
622 // copy page
623 $page->copy($new_page->getId(), $new_page->getParentType(), $new_page->getParentId(), true);
624 break;
625
626 case "fold":
627 $item->setTitle($node["title"]);
628 $item->create();
629 break;
630 }
631
632 // insert item into tree
633 $a_new_obj->insertInTree($item->getId(), $a_target_parent);
634
635 // handle childs
636 $this->copyTreeContent($a_new_obj, $item->getId(), $node["child"]);
637 }
638 }
639
645 public function exportXML($a_mode = "")
646 {
647 if (in_array($a_mode, array("master", "masternomedia"))) {
648 include_once("./Services/Export/classes/class.ilExport.php");
649 $exp = new ilExport();
650 $conf = $exp->getConfig("Modules/MediaPool");
651 $conf->setMasterLanguageOnly(true, ($a_mode == "master"));
652 $exp->exportObject($this->getType(), $this->getId(), "4.4.0");
653 }
654 }
655}
An exception for terminatinating execution or to throw for unit testing.
static _searchKeywords($a_query, $a_type, $a_rbac_id=0)
Search for objects by keywords.
static lookupForeignId($a_id)
Lookup Foreign Id.
Class ilMediaPoolPage.
Class ilObjFolder.
Class ilObjMediaObject.
Media pool object.
getDefaultWidth()
Get default width.
static _getPoolTree($a_obj_id)
Get Pool Tree.
static isItemIdInTree($a_pool_id, $a_item_id)
Check wheter a mep item id is in the media pool.
static getAllMobIds($a_id)
insertInTree($a_obj_id, $a_parent="")
Insert into tree.
getDefaultHeight()
Get default height.
setDefaultWidth($a_val)
Set default width.
exportXML($a_mode="")
Export.
copyTreeContent($a_new_obj, $a_target_parent, $a_source_parent)
Copy tree content.
getChilds($obj_id="", $a_type="")
get childs of node
& getTree()
get media pool folder tree
getMediaObjects($a_title_filter="", $a_format_filter="", $a_keyword_filter='', $a_caption_filter)
Get media objects.
setDefaultHeight($a_val)
Set default height.
getPoolTree()
Get pool tree.
createFolder($a_title, $a_parent=0)
Create a new folder.
deleteChild($obj_id)
Delete a child of media tree.
getForTranslation()
Get for translation.
createMepTree()
Create media pool tree.
create()
create new media pool
read()
Read pool data.
static isForeignIdInTree($a_pool_id, $a_foreign_id)
Check whether foreign id is in tree.
setForTranslation($a_val)
Set for translation.
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone media pool.
getChildsExceptFolders($obj_id="")
get childs of node
getUsedFormats()
Get used formats.
__construct($a_id=0, $a_call_by_reference=true)
Constructor @access public.
update()
update object data
Class ilObject Basic functions for all objects.
getType()
get object type @access public
getDescription()
get object description
getId()
get object id @access public
static _lookupType($a_id, $a_reference=false)
lookup object type
getTitle()
get object title @access public
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
$key
Definition: croninfo.php:18
$formats
Definition: date.php:77
update($pash, $contents, Config $config)
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
$mobs
$a_type
Definition: workflow.php:92