ILIAS  Release_4_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 
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 
121  {
122  $this->setSelectAllCheckbox("id");
123  }
124 
125  if ($this->current_folder != $this->tree->getRootId() && !$this->all_objects)
126  {
127  $ilCtrl->setParameter($this->parent_obj, $this->folder_par,
128  $this->tree->getParentId($this->current_folder));
129  $this->addHeaderCommand($ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd),
130  $lng->txt("mep_parent_folder"));
131  $ilCtrl->setParameter($this->parent_obj, $this->folder_par,
132  $this->current_folder);
133  }
134 
135  }
136 
142  function setInsertCommand($a_val)
143  {
144  $this->insert_command = $a_val;
145  }
146 
152  function getInsertCommand()
153  {
154  return $this->insert_command;
155  }
156 
160  function initFilter()
161  {
162  global $lng, $rbacreview, $ilUser;
163 
164  // title/description
165  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
166  $ti = new ilTextInputGUI($lng->txt("title"), "title");
167  $ti->setMaxLength(64);
168  $ti->setSize(20);
169  $this->addFilterItem($ti);
170  $ti->readFromSession();
171  $this->filter["title"] = $ti->getValue();
172 
173  // format
174  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
175  $options = array(
176  "" => $lng->txt("mep_all"),
177  );
178  $formats = $this->media_pool->getUsedFormats();
179  $options = array_merge($options, $formats);
180  $si = new ilSelectInputGUI($this->lng->txt("mep_format"), "format");
181  $si->setOptions($options);
182  $this->addFilterItem($si);
183  $si->readFromSession();
184  $this->filter["format"] = $si->getValue();
185 
186  }
187 
193  function setMode($a_mode)
194  {
195  $this->mode = $a_mode;
196  }
197 
203  function getMode()
204  {
205  return $this->mode;
206  }
207 
211  function getItems()
212  {
213  if (!$this->all_objects)
214  {
215  $fobjs = $this->media_pool->getChilds($this->current_folder, "fold");
216  $f2objs = array();
217  foreach ($fobjs as $obj)
218  {
219  $f2objs[$obj["title"].":".$obj["child"]] = $obj;
220  }
221  ksort($f2objs);
222 
223  // get current media objects / pages
225  {
226  $mobjs = $this->media_pool->getChilds($this->current_folder, "mob");
227  }
229  {
230  $mobjs = $this->media_pool->getChilds($this->current_folder, "pg");
231  }
232  else
233  {
234  $mobjs = $this->media_pool->getChildsExceptFolders($this->current_folder);
235  }
236  $m2objs = array();
237  foreach ($mobjs as $obj)
238  {
239  $m2objs[$obj["title"].":".$obj["child"]] = $obj;
240  }
241  ksort($m2objs);
242 
243  // merge everything together
244  $objs = array_merge($f2objs, $m2objs);
245  }
246  else
247  {
248  $objs = $this->media_pool->getMediaObjects($this->filter["title"],
249  $this->filter["format"]);
250  }
251 //var_dump($objs);
252  $this->setData($objs);
253  }
254 
261  function prepareOutput()
262  {
263  global $lng;
264 
267  {
268  $this->addMultiCommand($this->getInsertCommand(), $lng->txt("insert"));
269  $this->addCommandButton("cancelCreate", $lng->txt("cancel"));
270  }
271  }
272 
277  protected function fillRow($a_set)
278  {
279  global $lng, $ilCtrl, $ilAccess;
280 
281  $this->tpl->setCurrentBlock("link");
282 
283  switch($a_set["type"])
284  {
285  case "fold":
286  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
287  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $a_set["obj_id"]);
288  $this->tpl->setVariable("LINK_VIEW",
289  $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd));
290  $this->tpl->parseCurrentBlock();
291 
292  if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
294  {
295  $this->tpl->setCurrentBlock("edit");
296  $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit"));
297  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $a_set["obj_id"]);
298  $this->tpl->setVariable("EDIT_LINK",
299  $ilCtrl->getLinkTarget($this->parent_obj, "editFolder"));
300  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $_GET[$this->folder_par]);
301  $this->tpl->parseCurrentBlock();
302  }
303 
304  $this->tpl->setCurrentBlock("tbl_content");
305  $this->tpl->setVariable("IMG", ilUtil::img(ilUtil::getImagePath("icon_".$a_set["type"].".gif")));
306  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder);
307  break;
308 
309  case "pg":
310  $this->tpl->setVariable("TXT_NO_LINK_TITLE", $a_set["title"]);
311 
312  if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
314  {
315  $this->tpl->setCurrentBlock("edit");
316  $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit"));
317  $ilCtrl->setParameterByClass("ilmediapoolpagegui", "mepitem_id", $a_set["child"]);
318  $this->tpl->setVariable("EDIT_LINK",
319  $ilCtrl->getLinkTargetByClass("ilmediapoolpagegui", "edit"));
320  $this->tpl->parseCurrentBlock();
321  }
322 
323  $this->tpl->setCurrentBlock("tbl_content");
324  $this->tpl->setVariable("IMG", ilUtil::img(ilUtil::getImagePath("icon_pg.gif")));
325  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder);
326  break;
327 
328  case "mob":
331  {
332  $this->tpl->setVariable("TXT_NO_LINK_TITLE", $a_set["title"]);
333  }
334  else
335  {
336  $this->tpl->setVariable("TXT_TITLE", $a_set["title"]);
337  $this->tpl->touchBlock("nf");
338  $ilCtrl->setParameterByClass("ilobjmediaobjectgui", "mepitem_id", $a_set["child"]);
339  $ilCtrl->setParameter($this->parent_obj, "mob_id", $a_set["foreign_id"]);
340  $this->tpl->setVariable("LINK_VIEW",
341  $ilCtrl->getLinkTarget($this->parent_obj, "showMedia"));
342  }
343 
344  // edit link
345  if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) &&
347  {
348  $this->tpl->setCurrentBlock("edit");
349  $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit"));
350  $this->tpl->setVariable("EDIT_LINK",
351  $ilCtrl->getLinkTargetByClass("ilobjmediaobjectgui", "edit"));
352  $this->tpl->parseCurrentBlock();
353  }
354 
355  $this->tpl->setCurrentBlock("link");
356  $this->tpl->setCurrentBlock("tbl_content");
357 
358  // output thumbnail (or mob icon)
359  if (ilObject::_lookupType($a_set["foreign_id"]) == "mob")
360  {
361  $mob = new ilObjMediaObject($a_set["foreign_id"]);
362  $med = $mob->getMediaItem("Standard");
363  $target = $med->getThumbnailTarget();
364  if ($target != "")
365  {
366  $this->tpl->setVariable("IMG", ilUtil::img($target));
367  }
368  else
369  {
370  $this->tpl->setVariable("IMG",
371  ilUtil::img(ilUtil::getImagePath("icon_".$a_set["type"].".gif")));
372  }
373  if (ilUtil::deducibleSize($med->getFormat()) &&
374  $med->getLocationType() == "Reference")
375  {
376  $size = @getimagesize($med->getLocation());
377  if ($size[0] > 0 && $size[1] > 0)
378  {
379  $wr = $size[0] / 80;
380  $hr = $size[1] / 80;
381  $r = max($wr, hr);
382  $w = (int) ($size[0]/$r);
383  $h = (int) ($size[1]/$r);
384  $this->tpl->setVariable("IMG",
385  ilUtil::img($med->getLocation(), "", $w, $h));
386  }
387  }
388 
389  // output media info
390  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
391  $this->tpl->setVariable("MEDIA_INFO",
393  $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder);
394  }
395  break;
396  }
397 
398  if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()))
399  {
400  if (($this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT ||
401  ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT && $a_set["type"] == "mob") ||
402  ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT_CONTENT && $a_set["type"] == "pg")
403  ))
404  {
405  $this->tpl->setCurrentBlock("chbox");
406  $this->tpl->setVariable("CHECKBOX_ID", $a_set["child"]);
407  $this->tpl->parseCurrentBlock();
408  $this->tpl->setCurrentBlock("tbl_content");
409  }
410  else if ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT_SINGLE && $a_set["type"] == "mob")
411  {
412  $this->tpl->setCurrentBlock("radio");
413  $this->tpl->setVariable("RADIO_ID", $a_set["child"]);
414  $this->tpl->parseCurrentBlock();
415  $this->tpl->setCurrentBlock("tbl_content");
416  }
417  }
418  }
419 
420 // cmd=listMedia&cmdClass=ilobjmediapoolgui&cmdNode=5i:5k&baseClass=ilMediaPoolPresentationGUI&item_id=28
421 // item_id=28&obj_id=28&cmd=listMedia&cmdClass=ilobjmediapoolgui&cmdNode=5i:5k&baseClass=ilMediaPoolPresentationGUI
422 }
423 ?>