ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilMediaPoolTableGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 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
41 public function __construct(
42 $a_parent_obj,
43 $a_parent_cmd,
44 $a_media_pool,
45 $a_folder_par = "obj_id",
47 $a_all_objects = false,
48 $a_parent_tpl = null
49 ) {
50 global $DIC;
51
52 $this->ctrl = $DIC->ctrl();
53 $this->lng = $DIC->language();
54 $this->access = $DIC->access();
55 $this->rbacreview = $DIC->rbac()->review();
56 $this->user = $DIC->user();
57
58 $ilCtrl = $DIC->ctrl();
59 $ilAccess = $DIC->access();
60 $lng = $DIC->language();
61
62 if ($a_parent_tpl == null) {
63 $a_parent_tpl = $GLOBALS["tpl"];
64 }
65 $this->parent_tpl = $a_parent_tpl;
66 if ($a_all_objects) {
67 $this->setId("mepall" . $a_parent_obj->object->getId());
68 } else {
69 if (is_object($a_parent_obj->object)) {
70 $this->setId("mepfold" . $a_parent_obj->object->getId());
71 }
72 }
73
74 parent::__construct($a_parent_obj, $a_parent_cmd);
75 $this->setMode($a_mode);
76 $this->all_objects = $a_all_objects;
77 $lng->loadLanguageModule("mep");
78
79 $this->media_pool = $a_media_pool;
80 $this->tree = ilObjMediaPool::_getPoolTree($this->media_pool->getId());
81 $this->folder_par = $a_folder_par;
82
83 if ($this->all_objects) {
84 $this->setExternalSorting(true);
85 $this->initFilter();
86 }
87 // folder determination
88 if ($_GET[$this->folder_par] > 0) {
89 $this->current_folder = $_GET[$this->folder_par];
90 } elseif ($_SESSION["mep_pool_folder"] > 0 && $this->tree->isInTree($_SESSION["mep_pool_folder"])) {
91 $this->current_folder = $_SESSION["mep_pool_folder"];
92 } else {
93 $this->current_folder = $this->tree->getRootId();
94 }
95 $_SESSION["mep_pool_folder"] = $this->current_folder;
96
97 $this->addColumn("", "", "1"); // checkbox
98 $this->addColumn($lng->txt("mep_thumbnail"), "", "1");
99 $this->addColumn($lng->txt("mep_title_and_description"), "", "100%");
100 $this->setEnableHeader(true);
101 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
102 $this->setRowTemplate("tpl.mep_list_row.html", "Modules/MediaPool");
103 $this->getItems();
104
105 // title
106 if ($this->current_folder != $this->tree->getRootId() && !$this->all_objects) {
107 $node = $this->tree->getNodeData($this->current_folder);
108 $this->setTitle(
109 $lng->txt("mep_choose_from_folder") . ": " . $node["title"],
110 "icon_fold.svg",
111 $node["title"]
112 );
113 } else {
114 $this->setTitle(
115 $lng->txt("mep_choose_from_mep") . ": " .
116 ilObject::_lookupTitle($this->media_pool->getId()),
117 "icon_mep.svg",
118 ilObject::_lookupTitle($this->media_pool->getId())
119 );
120 }
121
122 // action commands
123 if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
124 $this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT) {
125 $this->addMultiCommand("copyToClipboard", $lng->txt("cont_copy_to_clipboard"));
126 $this->addMultiCommand("confirmRemove", $lng->txt("remove"));
127
128 if (!$this->all_objects) {
129 /* $this->addCommandButton("createFolderForm", $lng->txt("mep_create_folder"));
130 $this->addCommandButton("createMediaObject", $lng->txt("mep_create_mob"));
131
132 $mset = new ilSetting("mobs");
133 if ($mset->get("mep_activate_pages"))
134 {
135 $this->addCommandButton("createMediaPoolPage", $lng->txt("mep_create_content_snippet"));
136 }*/
137 }
138 }
139
141 // ... even more coupling with ilpcmediaobjectgui
142 $this->addMultiCommand("selectObjectReference", $lng->txt("cont_select"));
143 }
144
146 $ilAccess->checkAccess("write", "", $this->media_pool->getRefId())) {
147 $this->setSelectAllCheckbox("id");
148 }
149 }
150
156 public function setInsertCommand($a_val)
157 {
158 $this->insert_command = $a_val;
159 }
160
166 public function getInsertCommand()
167 {
169 }
170
177 public function getHTML()
178 {
179 $html = parent::getHTML();
180 include_once("./Modules/MediaPool/classes/class.ilObjMediaPoolGUI.php");
181 $html.= ilObjMediaPoolGUI::getPreviewModalHTML($this->media_pool->getRefId(), $this->parent_tpl);
182 return $html;
183 }
184
185
189 public function initFilter()
190 {
194
195 // title/description
196 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
197 $ti = new ilTextInputGUI($lng->txt("title"), "title");
198 $ti->setMaxLength(64);
199 $ti->setSize(20);
200 $this->addFilterItem($ti);
201 $ti->readFromSession();
202 $this->filter["title"] = $ti->getValue();
203
204 // keyword
205 $GLOBALS['lng']->loadLanguageModule('meta');
206 $ke = new ilTextInputGUI($lng->txt('meta_keyword'), 'keyword');
207 $ke->setMaxLength(64);
208 $ke->setSize(20);
209 $this->addFilterItem($ke);
210 $ke->readFromSession();
211 $this->filter['keyword'] = $ke->getValue();
212
213 // Caption
214 $ca = new ilTextInputGUI($lng->txt('cont_caption'), 'caption');
215 $ca->setMaxLength(64);
216 $ca->setSize(20);
217 $this->addFilterItem($ca);
218 $ca->readFromSession();
219 $this->filter['caption'] = $ca->getValue();
220
221 // format
222 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
223 $options = array(
224 "" => $lng->txt("mep_all"),
225 );
226 $formats = $this->media_pool->getUsedFormats();
227 $options = array_merge($options, $formats);
228 $si = new ilSelectInputGUI($this->lng->txt("mep_format"), "format");
229 $si->setOptions($options);
230 $this->addFilterItem($si);
231 $si->readFromSession();
232 $this->filter["format"] = $si->getValue();
233 }
234
240 public function setMode($a_mode)
241 {
242 $this->mode = $a_mode;
243 }
244
250 public function getMode()
251 {
252 return $this->mode;
253 }
254
258 public function getItems()
259 {
260 if (!$this->all_objects) {
261 $fobjs = $this->media_pool->getChilds($this->current_folder, "fold");
262 $f2objs = array();
263 foreach ($fobjs as $obj) {
264 $f2objs[$obj["title"] . ":" . $obj["child"]] = $obj;
265 }
266 ksort($f2objs);
267
268 // get current media objects / pages
270 $mobjs = $this->media_pool->getChilds($this->current_folder, "mob");
272 $mobjs = $this->media_pool->getChilds($this->current_folder, "pg");
273 } else {
274 $mobjs = $this->media_pool->getChildsExceptFolders($this->current_folder);
275 }
276 $m2objs = array();
277 foreach ($mobjs as $obj) {
278 $m2objs[$obj["title"] . ":" . $obj["child"]] = $obj;
279 }
280 ksort($m2objs);
281
282 // merge everything together
283 $objs = array_merge($f2objs, $m2objs);
284 } else {
285 $objs = $this->media_pool->getMediaObjects(
286 $this->filter["title"],
287 $this->filter["format"],
288 $this->filter['keyword'],
289 $this->filter['caption']
290 );
291 }
292 //var_dump($objs);
293 $this->setData($objs);
294 }
295
302 public function prepareOutput()
303 {
305
308 $this->addMultiCommand($this->getInsertCommand(), $lng->txt("insert"));
309 $this->addCommandButton("cancelCreate", $lng->txt("cancel"));
310 }
311 }
312
317 protected function fillRow($a_set)
318 {
321 $ilAccess = $this->access;
322
323 $this->tpl->setCurrentBlock("link");
324
325 switch ($a_set["type"]) {
326 case "fold":
327 $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
328 $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $a_set["obj_id"]);
329 $this->tpl->setVariable(
330 "LINK_VIEW",
331 $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd)
332 );
333 $this->tpl->parseCurrentBlock();
334
335 if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
336 $this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT) {
337 $this->tpl->setCurrentBlock("edit");
338 $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit"));
339 $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $a_set["obj_id"]);
340 $this->tpl->setVariable(
341 "EDIT_LINK",
342 $ilCtrl->getLinkTarget($this->parent_obj, "editFolder")
343 );
344 $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $_GET[$this->folder_par]);
345 $this->tpl->parseCurrentBlock();
346 }
347
348 $this->tpl->setCurrentBlock("tbl_content");
349 $this->tpl->setVariable("IMG", ilUtil::img(ilUtil::getImagePath("icon_" . $a_set["type"] . ".svg")));
350 $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder);
351 break;
352
353 case "pg":
356 $this->tpl->setVariable("TXT_NO_LINK_TITLE", $a_set["title"]);
357 } else {
358 $this->tpl->setVariable("ONCLICK", "il.MediaPool.preview('" . $a_set["child"] . "'); return false;");
359 $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
360 $ilCtrl->setParameterByClass("ilobjmediapoolgui", "mepitem_id", $a_set["child"]);
361 }
362
363 if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
364 $this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT) {
365 $this->tpl->setCurrentBlock("edit");
366 $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit"));
367 $ilCtrl->setParameterByClass("ilmediapoolpagegui", "mepitem_id", $a_set["child"]);
368 $this->tpl->setVariable(
369 "EDIT_LINK",
370 $ilCtrl->getLinkTargetByClass("ilmediapoolpagegui", "edit")
371 );
372 $this->tpl->parseCurrentBlock();
373 }
374
375 $this->tpl->setCurrentBlock("tbl_content");
376 $this->tpl->setVariable("IMG", ilUtil::img(ilUtil::getImagePath("icon_pg.svg")));
377 $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder);
378 break;
379
380 case "mob":
381 $this->tpl->setVariable("ONCLICK", "il.MediaPool.preview('" . $a_set["child"] . "'); return false;");
382 $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
383 $ilCtrl->setParameterByClass("ilobjmediaobjectgui", "mepitem_id", $a_set["child"]);
384 $ilCtrl->setParameter($this->parent_obj, "mob_id", $a_set["foreign_id"]);
385
386 // edit link
387 if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
388 $this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT) {
389 $this->tpl->setCurrentBlock("edit");
390 $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit"));
391 $this->tpl->setVariable(
392 "EDIT_LINK",
393 $ilCtrl->getLinkTargetByClass("ilobjmediaobjectgui", "edit")
394 );
395 $this->tpl->parseCurrentBlock();
396 }
397
398 $this->tpl->setCurrentBlock("link");
399 $this->tpl->setCurrentBlock("tbl_content");
400
401 // output thumbnail (or mob icon)
402 if (ilObject::_lookupType($a_set["foreign_id"]) == "mob") {
403 $mob = new ilObjMediaObject($a_set["foreign_id"]);
404 $med = $mob->getMediaItem("Standard");
405 $target = "";
406 if ($med) {
407 $target = $med->getThumbnailTarget();
408 }
409 if ($target != "") {
410 $this->tpl->setVariable("IMG", ilUtil::img($target));
411 } else {
412 $this->tpl->setVariable(
413 "IMG",
414 ilUtil::img(ilUtil::getImagePath("icon_" . $a_set["type"] . ".svg"))
415 );
416 }
417 if ($med && ilUtil::deducibleSize($med->getFormat()) &&
418 $med->getLocationType() == "Reference") {
419 $size = @getimagesize($med->getLocation());
420 if ($size[0] > 0 && $size[1] > 0) {
421 $wr = $size[0] / 80;
422 $hr = $size[1] / 80;
423 $r = max($wr, $hr);
424 $w = (int) ($size[0]/$r);
425 $h = (int) ($size[1]/$r);
426 $this->tpl->setVariable(
427 "IMG",
428 ilUtil::img($med->getLocation(), "", $w, $h)
429 );
430 }
431 }
432
433 // output media info
434 include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
435 $this->tpl->setVariable(
436 "MEDIA_INFO",
438 );
439 $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder);
440 }
441 break;
442 }
443
444 if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId())) {
445 if ((
447 ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT && $a_set["type"] == "mob") ||
448 ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT_CONTENT && $a_set["type"] == "pg")
449 )) {
450 $this->tpl->setCurrentBlock("chbox");
451 $this->tpl->setVariable("CHECKBOX_ID", $a_set["child"]);
452 $this->tpl->parseCurrentBlock();
453 $this->tpl->setCurrentBlock("tbl_content");
454 } elseif ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT_SINGLE && $a_set["type"] == "mob") {
455 $this->tpl->setCurrentBlock("radio");
456 $this->tpl->setVariable("RADIO_ID", $a_set["child"]);
457 $this->tpl->parseCurrentBlock();
458 $this->tpl->setCurrentBlock("tbl_content");
459 }
460 }
461 }
462
469 public function render()
470 {
473
474 $mtpl = new ilTemplate("tpl.media_sel_table.html", true, true, "Modules/MediaPool");
475
476 $pre = "";
477 if ($this->current_folder != $this->tree->getRootId() && !$this->all_objects) {
478 $path = $this->tree->getPathFull($this->current_folder);
479
480 include_once("./Services/Locator/classes/class.ilLocatorGUI.php");
481 $loc = new ilLocatorGUI();
482 foreach ($path as $p) {
483 $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $p["child"]);
484 $title = $p["title"];
485 if ($this->tree->getRootId() == $p["child"]) {
486 $title = ilObject::_lookupTitle($this->media_pool->getId());
487 }
488 $loc->addItem(
489 $title,
490 $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd)
491 );
492 }
493 $ilCtrl->setParameter(
494 $this->parent_obj,
495 $this->folder_par,
496 $this->current_folder
497 );
498
499 $mtpl->setCurrentBlock("loc");
500 $mtpl->setVariable("LOC", $loc->getHTML());
501 $mtpl->parseCurrentBlock();
502 }
503
504 $mtpl->setVariable("TABLE", parent::render());
505
506 return $mtpl->get();
507 }
508}
user()
Definition: user.php:4
$size
Definition: RandomTest.php:84
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
$_GET["client_id"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
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.
__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.
setData($a_data)
set table data @access public
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.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
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.
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="", $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
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilCtrl
Definition: ilias.php:18
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18