ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
4 include_once("Services/Table/classes/class.ilTable2GUI.php");
5 
15 {
16  const IL_MEP_SELECT = "select";
17  const IL_MEP_EDIT = "edit";
18  const IL_MEP_SELECT_CONTENT = "selectc";
19  var $insert_command = "create_mob";
20  const IL_MEP_SELECT_SINGLE = "selectsingle";
21  protected $parent_tpl = null; // parent / global tpl (where we can add javascript)
22 
26  function __construct($a_parent_obj, $a_parent_cmd,
27  $a_media_pool, $a_folder_par = "obj_id",
28  $a_mode = ilMediaPoolTableGUI::IL_MEP_EDIT, $a_all_objects = false, $a_parent_tpl = null)
29  {
30  global $ilCtrl, $lng, $ilAccess, $lng;
31 
32  if ($a_parent_tpl == null)
33  {
34  $a_parent_tpl = $GLOBALS["tpl"];
35  }
36  $this->parent_tpl = $a_parent_tpl;
37  if ($a_all_objects)
38  {
39  $this->setId("mepall".$a_parent_obj->object->getId());
40  }
41  else
42  {
43  if (is_object($a_parent_obj->object))
44  {
45  $this->setId("mepfold".$a_parent_obj->object->getId());
46  }
47  }
48 
49  parent::__construct($a_parent_obj, $a_parent_cmd);
50  $this->setMode($a_mode);
51  $this->all_objects = $a_all_objects;
52  $lng->loadLanguageModule("mep");
53 
54  $this->media_pool = $a_media_pool;
55  $this->tree = ilObjMediaPool::getPoolTree($this->media_pool->getId());
56  $this->folder_par = $a_folder_par;
57 
58  if ($this->all_objects)
59  {
60  $this->setExternalSorting(true);
61  $this->initFilter();
62  }
63  // folder determination
64  if ($_GET[$this->folder_par] > 0)
65  {
66  $this->current_folder = $_GET[$this->folder_par];
67  }
68  else if ($_SESSION["mep_pool_folder"] > 0 && $this->tree->isInTree($_SESSION["mep_pool_folder"]))
69  {
70  $this->current_folder = $_SESSION["mep_pool_folder"];
71  }
72  else
73  {
74  $this->current_folder = $this->tree->getRootId();
75  }
76  $_SESSION["mep_pool_folder"] = $this->current_folder;
77 
78  $this->addColumn("", "", "1"); // checkbox
79  $this->addColumn($lng->txt("mep_thumbnail"), "", "1");
80  $this->addColumn($lng->txt("mep_title_and_description"), "", "100%");
81  $this->setEnableHeader(true);
82  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
83  $this->setRowTemplate("tpl.mep_list_row.html", "Modules/MediaPool");
84  $this->getItems();
85 
86  // title
87  if ($this->current_folder != $this->tree->getRootId() && !$this->all_objects)
88  {
89  $node = $this->tree->getNodeData($this->current_folder);
90  $this->setTitle(
91  $lng->txt("mep_choose_from_folder").": ".$node["title"], "icon_fold.svg",
92  $node["title"]);
93  }
94  else
95  {
96  $this->setTitle(
97  $lng->txt("mep_choose_from_mep").": ".
98  ilObject::_lookupTitle($this->media_pool->getId()),
99  "icon_mep.svg",
100  ilObject::_lookupTitle($this->media_pool->getId()));
101  }
102 
103  // action commands
104  if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
106  {
107  $this->addMultiCommand("copyToClipboard", $lng->txt("cont_copy_to_clipboard"));
108  $this->addMultiCommand("confirmRemove", $lng->txt("remove"));
109 
110  if (!$this->all_objects)
111  {
112 /* $this->addCommandButton("createFolderForm", $lng->txt("mep_create_folder"));
113  $this->addCommandButton("createMediaObject", $lng->txt("mep_create_mob"));
114 
115  $mset = new ilSetting("mobs");
116  if ($mset->get("mep_activate_pages"))
117  {
118  $this->addCommandButton("createMediaPoolPage", $lng->txt("mep_create_content_snippet"));
119  }*/
120  }
121  }
122 
124  {
125  // ... even more coupling with ilpcmediaobjectgui
126  $this->addMultiCommand("selectObjectReference", $lng->txt("cont_select"));
127  }
128 
129  if ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT &&
130  $ilAccess->checkAccess("write", "", $this->media_pool->getRefId()))
131  {
132  $this->setSelectAllCheckbox("id");
133  }
134  }
135 
141  function setInsertCommand($a_val)
142  {
143  $this->insert_command = $a_val;
144  }
145 
151  function getInsertCommand()
152  {
153  return $this->insert_command;
154  }
155 
162  function getHTML()
163  {
164  $html = parent::getHTML();
165  include_once("./Modules/MediaPool/classes/class.ilObjMediaPoolGUI.php");
166  $html.= ilObjMediaPoolGUI::getPreviewModalHTML($this->media_pool->getRefId(), $this->parent_tpl);
167  return $html;
168  }
169 
170 
174  function initFilter()
175  {
176  global $lng, $rbacreview, $ilUser;
177 
178  // title/description
179  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
180  $ti = new ilTextInputGUI($lng->txt("title"), "title");
181  $ti->setMaxLength(64);
182  $ti->setSize(20);
183  $this->addFilterItem($ti);
184  $ti->readFromSession();
185  $this->filter["title"] = $ti->getValue();
186 
187  // keyword
188  $GLOBALS['lng']->loadLanguageModule('meta');
189  $ke = new ilTextInputGUI($lng->txt('meta_keyword'),'keyword');
190  $ke->setMaxLength(64);
191  $ke->setSize(20);
192  $this->addFilterItem($ke);
193  $ke->readFromSession();
194  $this->filter['keyword'] = $ke->getValue();
195 
196  // Caption
197  $ca = new ilTextInputGUI($lng->txt('cont_caption'),'caption');
198  $ca->setMaxLength(64);
199  $ca->setSize(20);
200  $this->addFilterItem($ca);
201  $ca->readFromSession();
202  $this->filter['caption'] = $ca->getValue();
203 
204  // format
205  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
206  $options = array(
207  "" => $lng->txt("mep_all"),
208  );
209  $formats = $this->media_pool->getUsedFormats();
210  $options = array_merge($options, $formats);
211  $si = new ilSelectInputGUI($this->lng->txt("mep_format"), "format");
212  $si->setOptions($options);
213  $this->addFilterItem($si);
214  $si->readFromSession();
215  $this->filter["format"] = $si->getValue();
216 
217  }
218 
224  function setMode($a_mode)
225  {
226  $this->mode = $a_mode;
227  }
228 
234  function getMode()
235  {
236  return $this->mode;
237  }
238 
242  function getItems()
243  {
244  if (!$this->all_objects)
245  {
246  $fobjs = $this->media_pool->getChilds($this->current_folder, "fold");
247  $f2objs = array();
248  foreach ($fobjs as $obj)
249  {
250  $f2objs[$obj["title"].":".$obj["child"]] = $obj;
251  }
252  ksort($f2objs);
253 
254  // get current media objects / pages
256  {
257  $mobjs = $this->media_pool->getChilds($this->current_folder, "mob");
258  }
260  {
261  $mobjs = $this->media_pool->getChilds($this->current_folder, "pg");
262  }
263  else
264  {
265  $mobjs = $this->media_pool->getChildsExceptFolders($this->current_folder);
266  }
267  $m2objs = array();
268  foreach ($mobjs as $obj)
269  {
270  $m2objs[$obj["title"].":".$obj["child"]] = $obj;
271  }
272  ksort($m2objs);
273 
274  // merge everything together
275  $objs = array_merge($f2objs, $m2objs);
276  }
277  else
278  {
279  $objs = $this->media_pool->getMediaObjects(
280  $this->filter["title"],
281  $this->filter["format"],
282  $this->filter['keyword'],
283  $this->filter['caption']
284  );
285  }
286 //var_dump($objs);
287  $this->setData($objs);
288  }
289 
296  function prepareOutput()
297  {
298  global $lng;
299 
302  {
303  $this->addMultiCommand($this->getInsertCommand(), $lng->txt("insert"));
304  $this->addCommandButton("cancelCreate", $lng->txt("cancel"));
305  }
306  }
307 
312  protected function fillRow($a_set)
313  {
314  global $lng, $ilCtrl, $ilAccess;
315 
316  $this->tpl->setCurrentBlock("link");
317 
318  switch($a_set["type"])
319  {
320  case "fold":
321  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
322  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $a_set["obj_id"]);
323  $this->tpl->setVariable("LINK_VIEW",
324  $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd));
325  $this->tpl->parseCurrentBlock();
326 
327  if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
329  {
330  $this->tpl->setCurrentBlock("edit");
331  $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit"));
332  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $a_set["obj_id"]);
333  $this->tpl->setVariable("EDIT_LINK",
334  $ilCtrl->getLinkTarget($this->parent_obj, "editFolder"));
335  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $_GET[$this->folder_par]);
336  $this->tpl->parseCurrentBlock();
337  }
338 
339  $this->tpl->setCurrentBlock("tbl_content");
340  $this->tpl->setVariable("IMG", ilUtil::img(ilUtil::getImagePath("icon_".$a_set["type"].".svg")));
341  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder);
342  break;
343 
344  case "pg":
347  {
348  $this->tpl->setVariable("TXT_NO_LINK_TITLE", $a_set["title"]);
349  }
350  else
351  {
352  $this->tpl->setVariable("ONCLICK", "il.MediaPool.preview('".$a_set["child"]."'); return false;");
353  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
354  $ilCtrl->setParameterByClass("ilobjmediapoolgui", "mepitem_id", $a_set["child"]);
355  }
356 
357  if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
359  {
360  $this->tpl->setCurrentBlock("edit");
361  $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit"));
362  $ilCtrl->setParameterByClass("ilmediapoolpagegui", "mepitem_id", $a_set["child"]);
363  $this->tpl->setVariable("EDIT_LINK",
364  $ilCtrl->getLinkTargetByClass("ilmediapoolpagegui", "edit"));
365  $this->tpl->parseCurrentBlock();
366  }
367 
368  $this->tpl->setCurrentBlock("tbl_content");
369  $this->tpl->setVariable("IMG", ilUtil::img(ilUtil::getImagePath("icon_pg.svg")));
370  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder);
371  break;
372 
373  case "mob":
374  $this->tpl->setVariable("ONCLICK", "il.MediaPool.preview('".$a_set["child"]."'); return false;");
375  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
376  $ilCtrl->setParameterByClass("ilobjmediaobjectgui", "mepitem_id", $a_set["child"]);
377  $ilCtrl->setParameter($this->parent_obj, "mob_id", $a_set["foreign_id"]);
378 
379  // edit link
380  if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
382  {
383  $this->tpl->setCurrentBlock("edit");
384  $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit"));
385  $this->tpl->setVariable("EDIT_LINK",
386  $ilCtrl->getLinkTargetByClass("ilobjmediaobjectgui", "edit"));
387  $this->tpl->parseCurrentBlock();
388  }
389 
390  $this->tpl->setCurrentBlock("link");
391  $this->tpl->setCurrentBlock("tbl_content");
392 
393  // output thumbnail (or mob icon)
394  if (ilObject::_lookupType($a_set["foreign_id"]) == "mob")
395  {
396  $mob = new ilObjMediaObject($a_set["foreign_id"]);
397  $med = $mob->getMediaItem("Standard");
398  $target = "";
399  if ($med)
400  {
401  $target = $med->getThumbnailTarget();
402  }
403  if ($target != "")
404  {
405  $this->tpl->setVariable("IMG", ilUtil::img($target));
406  }
407  else
408  {
409  $this->tpl->setVariable("IMG",
410  ilUtil::img(ilUtil::getImagePath("icon_".$a_set["type"].".svg")));
411  }
412  if ($med && ilUtil::deducibleSize($med->getFormat()) &&
413  $med->getLocationType() == "Reference")
414  {
415  $size = @getimagesize($med->getLocation());
416  if ($size[0] > 0 && $size[1] > 0)
417  {
418  $wr = $size[0] / 80;
419  $hr = $size[1] / 80;
420  $r = max($wr, hr);
421  $w = (int) ($size[0]/$r);
422  $h = (int) ($size[1]/$r);
423  $this->tpl->setVariable("IMG",
424  ilUtil::img($med->getLocation(), "", $w, $h));
425  }
426  }
427 
428  // output media info
429  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
430  $this->tpl->setVariable("MEDIA_INFO",
432  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder);
433  }
434  break;
435  }
436 
437  if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()))
438  {
439  if (($this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT ||
440  ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT && $a_set["type"] == "mob") ||
441  ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT_CONTENT && $a_set["type"] == "pg")
442  ))
443  {
444  $this->tpl->setCurrentBlock("chbox");
445  $this->tpl->setVariable("CHECKBOX_ID", $a_set["child"]);
446  $this->tpl->parseCurrentBlock();
447  $this->tpl->setCurrentBlock("tbl_content");
448  }
449  else if ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT_SINGLE && $a_set["type"] == "mob")
450  {
451  $this->tpl->setCurrentBlock("radio");
452  $this->tpl->setVariable("RADIO_ID", $a_set["child"]);
453  $this->tpl->parseCurrentBlock();
454  $this->tpl->setCurrentBlock("tbl_content");
455  }
456  }
457  }
458 
465  function render()
466  {
467  global $ilCtrl, $lng;
468 
469  $mtpl = new ilTemplate("tpl.media_sel_table.html", true, true, "Modules/MediaPool");
470 
471  $pre = "";
472  if ($this->current_folder != $this->tree->getRootId() && !$this->all_objects)
473  {
474  $path = $this->tree->getPathFull($this->current_folder);
475 
476  include_once("./Services/Locator/classes/class.ilLocatorGUI.php");
477  $loc = new ilLocatorGUI();
478  foreach ($path as $p)
479  {
480  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $p["child"]);
481  $title = $p["title"];
482  if ($this->tree->getRootId() == $p["child"])
483  {
484  $title = ilObject::_lookupTitle($this->media_pool->getId());
485  }
486  $loc->addItem(
487  $title,
488  $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd)
489  );
490  }
491  $ilCtrl->setParameter($this->parent_obj, $this->folder_par,
492  $this->current_folder);
493 
494  $mtpl->setCurrentBlock("loc");
495  $mtpl->setVariable("LOC", $loc->getHTML());
496  $mtpl->parseCurrentBlock();
497  }
498 
499  $mtpl->setVariable("TABLE", parent::render());
500 
501  return $mtpl->get();
502  }
503 }
504 ?>