ILIAS  eassessment Revision 61809
 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($node["title"], "icon_fold.gif",
85  $node["title"]);
86  }
87  else
88  {
89  $this->setTitle(ilObject::_lookupTitle($this->media_pool->getId()),
90  "icon_mep.gif",
91  ilObject::_lookupTitle($this->media_pool->getId()));
92  }
93 
94  // action commands
95  if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
97  {
98  $this->addMultiCommand("copyToClipboard", $lng->txt("cont_copy_to_clipboard"));
99  $this->addMultiCommand("confirmRemove", $lng->txt("remove"));
100 
101  if (!$this->all_objects)
102  {
103 /* $this->addCommandButton("createFolderForm", $lng->txt("mep_create_folder"));
104  $this->addCommandButton("createMediaObject", $lng->txt("mep_create_mob"));
105 
106  $mset = new ilSetting("mobs");
107  if ($mset->get("mep_activate_pages"))
108  {
109  $this->addCommandButton("createMediaPoolPage", $lng->txt("mep_create_content_snippet"));
110  }*/
111  }
112  }
113 
115  {
116  // ... even more coupling with ilpcmediaobjectgui
117  $this->addMultiCommand("selectObjectReference", $lng->txt("cont_select"));
118  }
119 
120  if ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT &&
121  $ilAccess->checkAccess("write", "", $this->media_pool->getRefId()))
122  {
123  $this->setSelectAllCheckbox("id");
124  }
125 
126  if ($this->current_folder != $this->tree->getRootId() && !$this->all_objects)
127  {
128  $ilCtrl->setParameter($this->parent_obj, $this->folder_par,
129  $this->tree->getParentId($this->current_folder));
130  $this->addHeaderCommand($ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd),
131  $lng->txt("mep_parent_folder"));
132  $ilCtrl->setParameter($this->parent_obj, $this->folder_par,
133  $this->current_folder);
134  }
135 
136  }
137 
143  function setInsertCommand($a_val)
144  {
145  $this->insert_command = $a_val;
146  }
147 
153  function getInsertCommand()
154  {
155  return $this->insert_command;
156  }
157 
161  function initFilter()
162  {
163  global $lng, $rbacreview, $ilUser;
164 
165  // title/description
166  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
167  $ti = new ilTextInputGUI($lng->txt("title"), "title");
168  $ti->setMaxLength(64);
169  $ti->setSize(20);
170  $this->addFilterItem($ti);
171  $ti->readFromSession();
172  $this->filter["title"] = $ti->getValue();
173 
174  // keyword
175  $GLOBALS['lng']->loadLanguageModule('meta');
176  $ke = new ilTextInputGUI($lng->txt('meta_keyword'),'keyword');
177  $ke->setMaxLength(64);
178  $ke->setSize(20);
179  $this->addFilterItem($ke);
180  $ke->readFromSession();
181  $this->filter['keyword'] = $ke->getValue();
182 
183  // Caption
184  $ca = new ilTextInputGUI($lng->txt('cont_caption'),'caption');
185  $ca->setMaxLength(64);
186  $ca->setSize(20);
187  $this->addFilterItem($ca);
188  $ca->readFromSession();
189  $this->filter['caption'] = $ca->getValue();
190 
191  // format
192  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
193  $options = array(
194  "" => $lng->txt("mep_all"),
195  );
196  $formats = $this->media_pool->getUsedFormats();
197  $options = array_merge($options, $formats);
198  $si = new ilSelectInputGUI($this->lng->txt("mep_format"), "format");
199  $si->setOptions($options);
200  $this->addFilterItem($si);
201  $si->readFromSession();
202  $this->filter["format"] = $si->getValue();
203 
204  }
205 
211  function setMode($a_mode)
212  {
213  $this->mode = $a_mode;
214  }
215 
221  function getMode()
222  {
223  return $this->mode;
224  }
225 
229  function getItems()
230  {
231  if (!$this->all_objects)
232  {
233  $fobjs = $this->media_pool->getChilds($this->current_folder, "fold");
234  $f2objs = array();
235  foreach ($fobjs as $obj)
236  {
237  $f2objs[$obj["title"].":".$obj["child"]] = $obj;
238  }
239  ksort($f2objs);
240 
241  // get current media objects / pages
243  {
244  $mobjs = $this->media_pool->getChilds($this->current_folder, "mob");
245  }
247  {
248  $mobjs = $this->media_pool->getChilds($this->current_folder, "pg");
249  }
250  else
251  {
252  $mobjs = $this->media_pool->getChildsExceptFolders($this->current_folder);
253  }
254  $m2objs = array();
255  foreach ($mobjs as $obj)
256  {
257  $m2objs[$obj["title"].":".$obj["child"]] = $obj;
258  }
259  ksort($m2objs);
260 
261  // merge everything together
262  $objs = array_merge($f2objs, $m2objs);
263  }
264  else
265  {
266  $objs = $this->media_pool->getMediaObjects(
267  $this->filter["title"],
268  $this->filter["format"],
269  $this->filter['keyword'],
270  $this->filter['caption']
271  );
272  }
273 //var_dump($objs);
274  $this->setData($objs);
275  }
276 
283  function prepareOutput()
284  {
285  global $lng;
286 
289  {
290  $this->addMultiCommand($this->getInsertCommand(), $lng->txt("insert"));
291  $this->addCommandButton("cancelCreate", $lng->txt("cancel"));
292  }
293  }
294 
299  protected function fillRow($a_set)
300  {
301  global $lng, $ilCtrl, $ilAccess;
302 
303  $this->tpl->setCurrentBlock("link");
304 
305  switch($a_set["type"])
306  {
307  case "fold":
308  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
309  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $a_set["obj_id"]);
310  $this->tpl->setVariable("LINK_VIEW",
311  $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd));
312  $this->tpl->parseCurrentBlock();
313 
314  if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
316  {
317  $this->tpl->setCurrentBlock("edit");
318  $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit"));
319  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $a_set["obj_id"]);
320  $this->tpl->setVariable("EDIT_LINK",
321  $ilCtrl->getLinkTarget($this->parent_obj, "editFolder"));
322  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $_GET[$this->folder_par]);
323  $this->tpl->parseCurrentBlock();
324  }
325 
326  $this->tpl->setCurrentBlock("tbl_content");
327  $this->tpl->setVariable("IMG", ilUtil::img(ilUtil::getImagePath("icon_".$a_set["type"].".gif")));
328  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder);
329  break;
330 
331  case "pg":
332  $this->tpl->setVariable("TXT_NO_LINK_TITLE", $a_set["title"]);
333 
334  if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
336  {
337  $this->tpl->setCurrentBlock("edit");
338  $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit"));
339  $ilCtrl->setParameterByClass("ilmediapoolpagegui", "mepitem_id", $a_set["child"]);
340  $this->tpl->setVariable("EDIT_LINK",
341  $ilCtrl->getLinkTargetByClass("ilmediapoolpagegui", "edit"));
342  $this->tpl->parseCurrentBlock();
343  }
344 
345  $this->tpl->setCurrentBlock("tbl_content");
346  $this->tpl->setVariable("IMG", ilUtil::img(ilUtil::getImagePath("icon_pg.gif")));
347  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder);
348  break;
349 
350  case "mob":
353  {
354  $this->tpl->setVariable("TXT_NO_LINK_TITLE", $a_set["title"]);
355  }
356  else
357  {
358  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
359  $this->tpl->touchBlock("nf");
360  $ilCtrl->setParameterByClass("ilobjmediaobjectgui", "mepitem_id", $a_set["child"]);
361  $ilCtrl->setParameter($this->parent_obj, "mob_id", $a_set["foreign_id"]);
362  $this->tpl->setVariable("LINK_VIEW",
363  $ilCtrl->getLinkTarget($this->parent_obj, "showMedia"));
364  }
365 
366  // edit link
367  if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
369  {
370  $this->tpl->setCurrentBlock("edit");
371  $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit"));
372  $this->tpl->setVariable("EDIT_LINK",
373  $ilCtrl->getLinkTargetByClass("ilobjmediaobjectgui", "edit"));
374  $this->tpl->parseCurrentBlock();
375  }
376 
377  $this->tpl->setCurrentBlock("link");
378  $this->tpl->setCurrentBlock("tbl_content");
379 
380  // output thumbnail (or mob icon)
381  if (ilObject::_lookupType($a_set["foreign_id"]) == "mob")
382  {
383  $mob = new ilObjMediaObject($a_set["foreign_id"]);
384  $med = $mob->getMediaItem("Standard");
385  $target = $med->getThumbnailTarget();
386  if ($target != "")
387  {
388  $this->tpl->setVariable("IMG", ilUtil::img($target));
389  }
390  else
391  {
392  $this->tpl->setVariable("IMG",
393  ilUtil::img(ilUtil::getImagePath("icon_".$a_set["type"].".gif")));
394  }
395  if (ilUtil::deducibleSize($med->getFormat()) &&
396  $med->getLocationType() == "Reference")
397  {
398  $size = @getimagesize($med->getLocation());
399  if ($size[0] > 0 && $size[1] > 0)
400  {
401  $wr = $size[0] / 80;
402  $hr = $size[1] / 80;
403  $r = max($wr, hr);
404  $w = (int) ($size[0]/$r);
405  $h = (int) ($size[1]/$r);
406  $this->tpl->setVariable("IMG",
407  ilUtil::img($med->getLocation(), "", $w, $h));
408  }
409  }
410 
411  // output media info
412  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
413  $this->tpl->setVariable("MEDIA_INFO",
415  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder);
416 
417  // output keywords
418  include_once './Services/MetaData/classes/class.ilMDKeyword.php';
419  if(count($kws = ilMDKeyword::lookupKeywords(0, $a_set['foreign_id'])))
420  {
421  $this->tpl->setCurrentBlock('additional_info');
422  $this->tpl->setVariable('ADD_INFO',$lng->txt('keywords').': '.implode(' ',$kws));
423  $this->tpl->parseCurrentBlock();
424  }
425  // output caption
426  if(strlen($med->getCaption()))
427  {
428  $this->tpl->setCurrentBlock('additional_info');
429  $this->tpl->setVariable('ADD_INFO',$lng->txt('cont_caption').': '.$med->getCaption());
430  $this->tpl->parseCurrentBlock();
431  }
432  }
433  break;
434  }
435 
436  if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()))
437  {
438  if (($this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT ||
439  ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT && $a_set["type"] == "mob") ||
440  ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT_CONTENT && $a_set["type"] == "pg")
441  ))
442  {
443  $this->tpl->setCurrentBlock("chbox");
444  $this->tpl->setVariable("CHECKBOX_ID", $a_set["child"]);
445  $this->tpl->parseCurrentBlock();
446  $this->tpl->setCurrentBlock("tbl_content");
447  }
448  else if ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT_SINGLE && $a_set["type"] == "mob")
449  {
450  $this->tpl->setCurrentBlock("radio");
451  $this->tpl->setVariable("RADIO_ID", $a_set["child"]);
452  $this->tpl->parseCurrentBlock();
453  $this->tpl->setCurrentBlock("tbl_content");
454  }
455  }
456  }
457 
458 // cmd=listMedia&cmdClass=ilobjmediapoolgui&cmdNode=5i:5k&baseClass=ilMediaPoolPresentationGUI&item_id=28
459 // item_id=28&obj_id=28&cmd=listMedia&cmdClass=ilobjmediapoolgui&cmdNode=5i:5k&baseClass=ilMediaPoolPresentationGUI
460 }
461 ?>