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