ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMediaObjectUsagesTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("Services/Table/classes/class.ilTable2GUI.php");
6 
16 {
17 
21  function __construct($a_parent_obj, $a_parent_cmd, $a_media_object,
22  $a_include_hist = false)
23  {
24  global $ilCtrl, $lng, $ilAccess, $lng;
25 
26  parent::__construct($a_parent_obj, $a_parent_cmd);
27  $this->media_object = $a_media_object;
28  $this->include_hist = $a_include_hist;
29  $this->addColumn("", "", "1"); // checkbox
30  $this->setEnableHeader(false);
31  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
32  $this->setRowTemplate("tpl.mob_usage_row.html", "Services/MediaObjects");
33  $this->getItems();
34  $this->setTitle($lng->txt("cont_mob_usages"));
35  }
36 
40  function getItems()
41  {
42  $usages = $this->media_object->getUsages($this->include_hist);
43 
44  $clip_cnt = 0;
45  $to_del = array();
46  $agg_usages = array();
47  foreach($usages as $k => $usage)
48  {
49  if ($usage["type"] == "clip")
50  {
51  $clip_cnt++;
52  }
53  else
54  {
55  if (empty($agg_usages[$usage["type"].":".$usage["id"]]))
56  {
57  $usage["hist_nr"] = array($usage["hist_nr"]);
58  $agg_usages[$usage["type"].":".$usage["id"]] = $usage;
59  }
60  else
61  {
62  $agg_usages[$usage["type"].":".$usage["id"]]["hist_nr"][] =
63  $usage["hist_nr"];
64  }
65  }
66  }
67 
68  // usages in clipboards
69  if ($clip_cnt > 0)
70  {
71  $agg_usages[] = array("type" => "clip", "cnt" => $clip_cnt);
72  }
73 
74  $this->setData($agg_usages);
75  }
76 
81  protected function fillRow($a_set)
82  {
83  global $lng, $ilCtrl, $ilAccess;
84 
85  $usage = $a_set;
86 
87 //var_dump($usage);
88 
89  if(is_int(strpos($usage["type"], ":")))
90  {
91  $us_arr = explode(":", $usage["type"]);
92  $usage["type"] = $us_arr[1];
93  $cont_type = $us_arr[0];
94  }
95 //var_dump($usage);
96 
97  include_once('classes/class.ilLink.php');
98 
99  switch($usage["type"])
100  {
101  case "pg":
102 
103  require_once("./Services/COPage/classes/class.ilPageObject.php");
104  $page_obj = new ilPageObject($cont_type, $usage["id"]);
105 
106  $item = array();
107 
108  //$this->tpl->setVariable("TXT_OBJECT", $usage["type"].":".$usage["id"]);
109  switch ($cont_type)
110  {
111  case "lm":
112  require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
113  require_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
114  require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
115  if (ilObject::_lookupType($page_obj->getParentId()) == "lm")
116  {
117  $lm_obj =& new ilObjLearningModule($page_obj->getParentId(), false);
118  $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
119  $item["obj_title"] = $lm_obj->getTitle();
120  $item["sub_txt"] = $this->lng->txt("pg");
121  $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
122  $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
123  if ($ref_id > 0)
124  {
125  $item["obj_link"] = ilLink::_getStaticLink($page_obj->getId()."_".$ref_id, "pg");
126  }
127  }
128  break;
129 
130  case "dbk":
131  require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
132  require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
133  require_once("./Modules/LearningModule/classes/class.ilObjDlBook.php");
134  if (ilObject::_lookupType($page_obj->getParentId()) == "dbk")
135  {
136  $lm_obj =& new ilObjDlBook($page_obj->getParentId(), false);
137  $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
138  $item["obj_title"] = $lm_obj->getTitle();
139  $item["sub_txt"] = $this->lng->txt("pg");
140  $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
141  $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
142  if ($ref_id > 0)
143  {
144  $item["obj_link"] = ilLink::_getStaticLink($page_obj->getId()."_".$ref_id, "pg");
145  }
146  }
147  break;
148 
149  case "wpg":
150  require_once("./Modules/Wiki/classes/class.ilWikiPage.php");
151  $item["obj_type_txt"] = $this->lng->txt("obj_wiki");
152  $item["obj_title"] = ilObject::_lookupTitle($page_obj->getParentId());
153  $item["sub_txt"] = $this->lng->txt("pg");
154  $item["sub_title"] = ilWikiPage::lookupTitle($page_obj->getId());
155  $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
156  if ($ref_id > 0)
157  {
158  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "wiki");
159  }
160  break;
161 
162  case "gdf":
163  require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
164  require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
165  $term_id = ilGlossaryDefinition::_lookupTermId($page_obj->getId());
166  $glo_id = ilGlossaryTerm::_lookGlossaryId($term_id);
167  $item["obj_type_txt"] = $this->lng->txt("obj_glo");
168  $item["obj_title"] = ilObject::_lookupTitle($glo_id);
169  $item["sub_txt"] = $this->lng->txt("cont_term");
170  $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id);
171  $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
172  if ($ref_id > 0)
173  {
174  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo");
175  }
176  break;
177 
178  case "fold":
179  case "root":
180  case "crs":
181  case "grp":
182  case "cat":
183  $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
184  $item["obj_title"] = ilObject::_lookupTitle($page_obj->getId());
185  $ref_id = $this->getFirstWritableRefId($page_obj->getId());
186  if ($ref_id > 0)
187  {
188  $item["obj_link"] = ilLink::_getStaticLink($ref_id, $cont_type);
189  }
190  break;
191  }
192  break;
193 
194  case "mep":
195  $item["obj_type_txt"] = $this->lng->txt("obj_mep");
196  $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
197  $ref_id = $this->getFirstWritableRefId($usage["id"]);
198  if ($ref_id > 0)
199  {
200  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep");
201  }
202  break;
203 
204  case "map":
205  $item["obj_type_txt"] = $this->lng->txt("obj_mob");
206  $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
207  $item["sub_txt"] = $this->lng->txt("cont_link_area");
208  break;
209  }
210 
211  // show versions
212  if (is_array($usage["hist_nr"]) &&
213  (count($usage["hist_nr"]) > 1 || $usage["hist_nr"][0] > 0))
214  {
215  asort($usage["hist_nr"]);
216  $ver = $sep = "";
217  if ($usage["hist_nr"][0] == 0)
218  {
219  array_shift($usage["hist_nr"]);
220  $usage["hist_nr"][] = 0;
221  }
222  if (count($usage["hist_nr"]) > 5)
223  {
224  $ver.= "..., ";
225  $cnt = count($usage["hist_nr"]) - 5;
226  for ($i = 0; $i < $cnt; $i++)
227  {
228  unset($usage["hist_nr"][$i]);
229  }
230  }
231 
232  foreach ($usage["hist_nr"] as $nr)
233  {
234  if ($nr > 0)
235  {
236  $ver.= $sep.$nr;
237  }
238  else
239  {
240  $ver.= $sep.$this->lng->txt("cont_current_version");
241  }
242  $sep = ", ";
243  }
244 
245  $this->tpl->setCurrentBlock("versions");
246  $this->tpl->setVariable("TXT_VERSIONS", $this->lng->txt("cont_versions"));
247  $this->tpl->setVariable("VAL_VERSIONS", $ver);
248  $this->tpl->parseCurrentBlock();
249  }
250 
251  if ($item["obj_type_txt"] != "")
252  {
253  $this->tpl->setCurrentBlock("type");
254  $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("type"));
255  $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]);
256  $this->tpl->parseCurrentBlock();
257  }
258 
259  if ($usage["type"] != "clip")
260  {
261  if ($item["obj_link"])
262  {
263  $this->tpl->setCurrentBlock("linked_item");
264  $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"]);
265  $this->tpl->setVariable("HREF_LINK", $item["obj_link"]);
266  $this->tpl->parseCurrentBlock();
267  }
268  else
269  {
270  $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"]);
271  }
272 
273  if ($item["sub_txt"] != "")
274  {
275  $this->tpl->setVariable("SEP", ", ");
276  $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]);
277  if ($item["sub_title"] != "")
278  {
279  $this->tpl->setVariable("SEP2", ": ");
280  $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]);
281  }
282  }
283 
284  }
285  else
286  {
287  $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1").
288  " ".$usage["cnt"]." ".$this->lng->txt("cont_users_have_mob_in_clip2"));
289 
290  }
291  }
292 
293  function getFirstWritableRefId($a_obj_id)
294  {
295  global $ilAccess;
296 
297  $ref_ids = ilObject::_getAllReferences($a_obj_id);
298  foreach ($ref_ids as $ref_id)
299  {
300  if ($ilAccess->checkAccess("write", "", $ref_id))
301  {
302  return $ref_id;
303  }
304  }
305  return 0;
306  }
307 }
308 ?>