ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMediaPoolTableGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("Services/Table/classes/class.ilTable2GUI.php");
5
15{
19 protected $access;
20
24 protected $rbacreview;
25
29 protected $user;
30
31 const IL_MEP_SELECT = "select";
32 const IL_MEP_EDIT = "edit";
33 const IL_MEP_SELECT_CONTENT = "selectc";
34 public $insert_command = "create_mob";
35 const IL_MEP_SELECT_SINGLE = "selectsingle";
36 protected $parent_tpl = null; // parent / global tpl (where we can add javascript)
37
42
46 public function __construct(
47 $a_parent_obj,
48 $a_parent_cmd,
49 $a_media_pool,
50 $a_folder_par = "obj_id",
52 $a_all_objects = false,
53 $a_parent_tpl = null
54 ) {
55 global $DIC;
56
57 $this->ctrl = $DIC->ctrl();
58 $this->lng = $DIC->language();
59 $this->access = $DIC->access();
60 $this->rbacreview = $DIC->rbac()->review();
61 $this->user = $DIC->user();
62
63 $ilCtrl = $DIC->ctrl();
64 $ilAccess = $DIC->access();
65 $lng = $DIC->language();
66
67 if ($a_parent_tpl == null) {
68 $a_parent_tpl = $GLOBALS["tpl"];
69 }
70 $this->parent_tpl = $a_parent_tpl;
71 if ($a_all_objects) {
72 $this->setId("mepall");
73 if (is_object($a_parent_obj->object)) {
74 $this->setId("mepall" . $a_parent_obj->object->getId());
75 }
76 } else {
77 $this->setId("mepfold");
78 if (is_object($a_parent_obj->object)) {
79 $this->setId("mepfold" . $a_parent_obj->object->getId());
80 }
81 }
82
83 parent::__construct($a_parent_obj, $a_parent_cmd);
84 $this->setMode($a_mode);
85 $this->all_objects = $a_all_objects;
86 $lng->loadLanguageModule("mep");
87
88 $this->media_pool = $a_media_pool;
89 $this->tree = ilObjMediaPool::_getPoolTree($this->media_pool->getId());
90 $this->folder_par = $a_folder_par;
91
92 if ($this->all_objects) {
93 $this->setExternalSorting(true);
94 $this->initFilter();
95 }
96 // folder determination
97 if ($_GET[$this->folder_par] > 0) {
98 $this->current_folder = $_GET[$this->folder_par];
99 } elseif ($_SESSION["mep_pool_folder"] > 0 && $this->tree->isInTree($_SESSION["mep_pool_folder"])) {
100 $this->current_folder = $_SESSION["mep_pool_folder"];
101 } else {
102 $this->current_folder = $this->tree->getRootId();
103 }
104 $_SESSION["mep_pool_folder"] = $this->current_folder;
105
106 // standard columns
107 $this->addColumn("", "", "1"); // checkbox
108 $this->addColumn($lng->txt("mep_thumbnail"), "", "1");
109 $this->addColumn($lng->txt("mep_title_and_description"));
110 $this->setEnableHeader(true);
111 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
112 $this->setRowTemplate("tpl.mep_list_row.html", "Modules/MediaPool");
113
114 if ($this->showAdvMetadata()) {
115 // adv metadata init (adds filter)
116 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordGUI.php');
117 $this->adv_filter_record_gui = new ilAdvancedMDRecordGUI(ilAdvancedMDRecordGUI::MODE_FILTER, 'mep', $this->media_pool->getId(), 'mob');
118 $this->adv_filter_record_gui->setTableGUI($this);
119 $this->adv_filter_record_gui->parse();
120
121 // adv metadata columns
122 $adv_th_record_gui = new ilAdvancedMDRecordGUI(ilAdvancedMDRecordGUI::MODE_TABLE_HEAD, 'mep', $this->media_pool->getId(), 'mob');
123 $adv_th_record_gui->setTableGUI($this);
124 $adv_th_record_gui->parse();
125 if ($a_mode == self::IL_MEP_SELECT) {
126 $this->setFilterCommand("insert_applyFilter");
127 $this->setResetCommand("insert_resetFilter");
128 }
129 }
130
131 // actions column
132 $this->addColumn($lng->txt("actions"));
133
134 // get items
135 $this->getItems();
136
137 // title
138 if ($a_mode != ilMediaPoolTableGUI::IL_MEP_EDIT) {
139 if ($this->current_folder != $this->tree->getRootId() && !$this->all_objects) {
140 $node = $this->tree->getNodeData($this->current_folder);
141 $this->setTitle(
142 $lng->txt("mep_choose_from_folder") . ": " . $node["title"],
143 "icon_fold.svg",
144 $node["title"]
145 );
146 } else {
147 $this->setTitle(
148 $lng->txt("mep_choose_from_mep") . ": " .
149 ilObject::_lookupTitle($this->media_pool->getId()),
150 "icon_mep.svg",
151 ilObject::_lookupTitle($this->media_pool->getId())
152 );
153 }
154 }
155
156 // action commands
157 if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
158 $this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT) {
159 $this->addMultiCommand("copyToClipboard", $lng->txt("cont_copy_to_clipboard"));
160 $this->addMultiCommand("confirmRemove", $lng->txt("remove"));
161
162 if (!$this->all_objects) {
163 /* $this->addCommandButton("createFolderForm", $lng->txt("mep_create_folder"));
164 $this->addCommandButton("createMediaObject", $lng->txt("mep_create_mob"));
165
166 $mset = new ilSetting("mobs");
167 if ($mset->get("mep_activate_pages"))
168 {
169 $this->addCommandButton("createMediaPoolPage", $lng->txt("mep_create_content_snippet"));
170 }*/
171 }
172 }
173
175 // ... even more coupling with ilpcmediaobjectgui
176 $this->addMultiCommand("selectObjectReference", $lng->txt("cont_select"));
177 }
178
180 $ilAccess->checkAccess("write", "", $this->media_pool->getRefId())) {
181 $this->setSelectAllCheckbox("id");
182 }
183 }
184
189 protected function showAdvMetadata()
190 {
191 if ($this->all_objects) {
192 return true;
193 }
194
195 return false;
196 }
197
198
204 protected function getAdvMDRecordGUI()
205 {
207 }
208
214 public function setInsertCommand($a_val)
215 {
216 $this->insert_command = $a_val;
217 }
218
224 public function getInsertCommand()
225 {
227 }
228
235 public function getHTML()
236 {
237 $html = parent::getHTML();
238 include_once("./Modules/MediaPool/classes/class.ilObjMediaPoolGUI.php");
239 $html .= ilObjMediaPoolGUI::getPreviewModalHTML($this->media_pool->getRefId(), $this->parent_tpl);
240 return $html;
241 }
242
243
247 public function initFilter()
248 {
252
253 // title/description
254 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
255 $ti = new ilTextInputGUI($lng->txt("title"), "title");
256 $ti->setMaxLength(64);
257 $ti->setSize(20);
258 $this->addFilterItem($ti);
259 $ti->readFromSession();
260 $this->filter["title"] = $ti->getValue();
261
262 // keyword
263 $GLOBALS['lng']->loadLanguageModule('meta');
264 $ke = new ilTextInputGUI($lng->txt('meta_keyword'), 'keyword');
265 $ke->setMaxLength(64);
266 $ke->setSize(20);
267 $this->addFilterItem($ke);
268 $ke->readFromSession();
269 $this->filter['keyword'] = $ke->getValue();
270
271 // Caption
272 $ca = new ilTextInputGUI($lng->txt('cont_caption'), 'caption');
273 $ca->setMaxLength(64);
274 $ca->setSize(20);
275 $this->addFilterItem($ca);
276 $ca->readFromSession();
277 $this->filter['caption'] = $ca->getValue();
278
279 // format
280 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
281 $options = array(
282 "" => $lng->txt("mep_all"),
283 );
284 $formats = $this->media_pool->getUsedFormats();
285 $options = array_merge($options, $formats);
286 $si = new ilSelectInputGUI($this->lng->txt("mep_format"), "format");
287 $si->setOptions($options);
288 $this->addFilterItem($si);
289 $si->readFromSession();
290 $this->filter["format"] = $si->getValue();
291 }
292
298 public function setMode($a_mode)
299 {
300 $this->mode = $a_mode;
301 }
302
308 public function getMode()
309 {
310 return $this->mode;
311 }
312
316 public function getItems()
317 {
318 if (!$this->all_objects) {
319 $fobjs = $this->media_pool->getChilds($this->current_folder, "fold");
320 $f2objs = array();
321 foreach ($fobjs as $obj) {
322 $f2objs[$obj["title"] . ":" . $obj["child"]] = $obj;
323 }
324 ksort($f2objs);
325
326 // get current media objects / pages
328 $mobjs = $this->media_pool->getChilds($this->current_folder, "mob");
330 $mobjs = $this->media_pool->getChilds($this->current_folder, "pg");
331 } else {
332 $mobjs = $this->media_pool->getChildsExceptFolders($this->current_folder);
333 }
334 $m2objs = array();
335 foreach ($mobjs as $obj) {
336 $m2objs[$obj["title"] . ":" . $obj["child"]] = $obj;
337 }
338 ksort($m2objs);
339
340 // merge everything together
341 $objs = array_merge($f2objs, $m2objs);
342 } else {
343 $objs = $this->media_pool->getMediaObjects(
344 $this->filter["title"],
345 $this->filter["format"],
346 $this->filter['keyword'],
347 $this->filter['caption']
348 );
349 }
350
351 // add advanced metadata
352 if ($this->showAdvMetadata()) {
353 include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php");
355 $this->media_pool->getRefId(),
356 "mep",
357 "mob",
358 0,
359 "mob",
360 $objs,
361 "",
362 "foreign_id",
363 $this->adv_filter_record_gui->getFilterElements()
364 );
365 }
366 //echo ("<br>".$this->media_pool->getRefId());
367 //var_dump($objs); exit;
368 $this->setData($objs);
369 }
370
377 public function prepareOutput()
378 {
380
383 $this->addMultiCommand($this->getInsertCommand(), $lng->txt("insert"));
384 $this->addCommandButton("cancelCreate", $lng->txt("cancel"));
385 }
386 }
387
392 protected function fillRow($a_set)
393 {
396 $ilAccess = $this->access;
397
398 $this->tpl->setCurrentBlock("link");
399
400 // adv metadata columns
401 if ($this->showAdvMetadata()) {
402 $adv_cell_record_gui = new ilAdvancedMDRecordGUI(ilAdvancedMDRecordGUI::MODE_TABLE_CELLS, 'mep', $this->media_pool->getId(), 'mob');
403 $adv_cell_record_gui->setTableGUI($this);
404 $adv_cell_record_gui->setRowData($a_set);
405 $this->tpl->setVariable("ADV_CELLS", $adv_cell_record_gui->parse());
406 }
407
408
409 switch ($a_set["type"]) {
410 case "fold":
411 $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
412 $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $a_set["obj_id"]);
413 $this->tpl->setVariable(
414 "LINK_VIEW",
415 $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd)
416 );
417 $this->tpl->parseCurrentBlock();
418
419 if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
420 $this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT) {
421 $this->tpl->setCurrentBlock("edit");
422 $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit"));
423 $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $a_set["obj_id"]);
424 $this->tpl->setVariable(
425 "EDIT_LINK",
426 $ilCtrl->getLinkTarget($this->parent_obj, "editFolder")
427 );
428 $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $_GET[$this->folder_par]);
429 $this->tpl->parseCurrentBlock();
430 }
431
432 $this->tpl->setCurrentBlock("tbl_content");
433 $this->tpl->setVariable("IMG", ilUtil::img(ilUtil::getImagePath("icon_" . $a_set["type"] . ".svg")));
434 $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder);
435 break;
436
437 case "pg":
440 $this->tpl->setVariable("TXT_NO_LINK_TITLE", $a_set["title"]);
441 } else {
442 $this->tpl->setVariable("ONCLICK", "il.MediaPool.preview('" . $a_set["child"] . "'); return false;");
443 $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
444 $ilCtrl->setParameterByClass("ilobjmediapoolgui", "mepitem_id", $a_set["child"]);
445 }
446
447 if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
448 $this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT) {
449 $this->tpl->setCurrentBlock("edit");
450 $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit"));
451 $ilCtrl->setParameterByClass("ilmediapoolpagegui", "mepitem_id", $a_set["child"]);
452 $this->tpl->setVariable(
453 "EDIT_LINK",
454 $ilCtrl->getLinkTargetByClass("ilmediapoolpagegui", "edit")
455 );
456 $this->tpl->parseCurrentBlock();
457 }
458
459 $this->tpl->setCurrentBlock("tbl_content");
460 $this->tpl->setVariable("IMG", ilUtil::img(ilUtil::getImagePath("icon_pg.svg")));
461 $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder);
462 break;
463
464 case "mob":
465 $this->tpl->setVariable("ONCLICK", "il.MediaPool.preview('" . $a_set["child"] . "'); return false;");
466 $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
467 $ilCtrl->setParameterByClass("ilobjmediaobjectgui", "mepitem_id", $a_set["child"]);
468 $ilCtrl->setParameter($this->parent_obj, "mob_id", $a_set["foreign_id"]);
469
470 // edit link
471 if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
472 $this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT) {
473 $this->tpl->setCurrentBlock("edit");
474 $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit"));
475 $this->tpl->setVariable(
476 "EDIT_LINK",
477 $ilCtrl->getLinkTargetByClass("ilobjmediaobjectgui", "edit")
478 );
479 $this->tpl->parseCurrentBlock();
480 }
481
482 $this->tpl->setCurrentBlock("link");
483 $this->tpl->setCurrentBlock("tbl_content");
484
485 // output thumbnail (or mob icon)
486 if (ilObject::_lookupType($a_set["foreign_id"]) == "mob") {
487 $mob = new ilObjMediaObject($a_set["foreign_id"]);
488 $med = $mob->getMediaItem("Standard");
489 $target = "";
490 if ($med) {
491 $target = $med->getThumbnailTarget();
492 }
493 if ($target != "") {
494 $this->tpl->setVariable("IMG", ilUtil::img($target));
495 } else {
496 $this->tpl->setVariable(
497 "IMG",
498 ilUtil::img(ilUtil::getImagePath("icon_" . $a_set["type"] . ".svg"))
499 );
500 }
501 if ($med && ilUtil::deducibleSize($med->getFormat()) &&
502 $med->getLocationType() == "Reference") {
503 $size = @getimagesize($med->getLocation());
504 if ($size[0] > 0 && $size[1] > 0) {
505 $wr = $size[0] / 80;
506 $hr = $size[1] / 80;
507 $r = max($wr, $hr);
508 $w = (int) ($size[0] / $r);
509 $h = (int) ($size[1] / $r);
510 $this->tpl->setVariable(
511 "IMG",
512 ilUtil::img($med->getLocation(), "", $w, $h)
513 );
514 }
515 }
516
517 // output media info
518 include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
519 $this->tpl->setVariable(
520 "MEDIA_INFO",
522 );
523 $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder);
524 }
525 break;
526 }
527
528 if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId())) {
529 if ((
531 ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT && $a_set["type"] == "mob") ||
532 ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT_CONTENT && $a_set["type"] == "pg")
533 )) {
534 $this->tpl->setCurrentBlock("chbox");
535 $this->tpl->setVariable("CHECKBOX_ID", $a_set["child"]);
536 $this->tpl->parseCurrentBlock();
537 $this->tpl->setCurrentBlock("tbl_content");
538 } elseif ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT_SINGLE && $a_set["type"] == "mob") {
539 $this->tpl->setCurrentBlock("radio");
540 $this->tpl->setVariable("RADIO_ID", $a_set["child"]);
541 $this->tpl->parseCurrentBlock();
542 $this->tpl->setCurrentBlock("tbl_content");
543 }
544 }
545 }
546
553 public function render()
554 {
557
558 $mtpl = new ilTemplate("tpl.media_sel_table.html", true, true, "Modules/MediaPool");
559
560 $pre = "";
561 if ($this->current_folder != $this->tree->getRootId() && !$this->all_objects) {
562 $path = $this->tree->getPathFull($this->current_folder);
563
564 include_once("./Services/Locator/classes/class.ilLocatorGUI.php");
565 $loc = new ilLocatorGUI();
566 foreach ($path as $p) {
567 $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $p["child"]);
568 $title = $p["title"];
569 if ($this->tree->getRootId() == $p["child"]) {
570 $title = ilObject::_lookupTitle($this->media_pool->getId());
571 }
572 $loc->addItem(
573 $title,
574 $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd)
575 );
576 }
577 $ilCtrl->setParameter(
578 $this->parent_obj,
579 $this->folder_par,
580 $this->current_folder
581 );
582
583 $mtpl->setCurrentBlock("loc");
584 $mtpl->setVariable("LOC", $loc->getHTML());
585 $mtpl->parseCurrentBlock();
586 }
587
588 $mtpl->setVariable("TABLE", parent::render());
589
590 return $mtpl->get();
591 }
592}
user()
Definition: user.php:4
$size
Definition: RandomTest.php:84
$path
Definition: aliased.php:25
$_GET["client_id"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
static queryForRecords($adv_rec_obj_ref_id, $adv_rec_obj_type, $adv_rec_obj_subtype, $a_obj_id, $a_subtype, $a_records, $a_obj_id_key, $a_obj_subid_key, array $a_amet_filter=null)
Query data for given object records.
locator handling class
TableGUI class for recent changes in wiki.
fillRow($a_set)
Standard Version of Fill Row.
getInsertCommand()
Get inser command.
setInsertCommand($a_val)
Set inser command.
getItems()
Get items of current folder.
getAdvMDRecordGUI()
needed for advmd filter handling
showAdvMetadata()
Show adv metadata.
__construct( $a_parent_obj, $a_parent_cmd, $a_media_pool, $a_folder_par="obj_id", $a_mode=ilMediaPoolTableGUI::IL_MEP_EDIT, $a_all_objects=false, $a_parent_tpl=null)
Constructor.
static _getMediaInfoHTML(&$a_mob)
get media info as html
Class ilObjMediaObject.
static getPreviewModalHTML($a_mpool_ref_id, $a_tpl)
Get preview modal html.
static _getPoolTree($a_obj_id)
Get Pool Tree.
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a selection list property in a property form.
Class ilTable2GUI.
setEnableHeader($a_enableheader)
Set Enable Header.
setExternalSorting($a_val)
Set external sorting.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
setData($a_data)
set table data @access public
setResetCommand($a_val, $a_caption=null)
Set reset filter command.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addMultiCommand($a_cmd, $a_text)
Add Command button.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setFilterCommand($a_val, $a_caption=null)
Set filter command.
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
static img($a_src, $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static deducibleSize($a_mime)
checks if mime type is provided by getimagesize()
$formats
Definition: date.php:77
$html
Definition: example_001.php:87
$h
$w
$r
Definition: example_031.php:79
global $ilCtrl
Definition: ilias.php:18
$target
Definition: test.php:19
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18