ILIAS  Release_4_4_x_branch Revision 61816
 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('./Services/Link/classes/class.ilLink.php');
98 
99  switch($usage["type"])
100  {
101  case "pg":
102  include_once("./Services/COPage/classes/class.ilPageObjectFactory.php");
103  $page_obj = ilPageObjectFactory::getInstance($cont_type, $usage["id"]);
104 
105  $item = array();
106 
107  //$this->tpl->setVariable("TXT_OBJECT", $usage["type"].":".$usage["id"]);
108  switch ($cont_type)
109  {
110  case "lm":
111  require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
112  require_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
113  require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
114  if (ilObject::_lookupType($page_obj->getParentId()) == "lm")
115  {
116  $lm_obj =& new ilObjLearningModule($page_obj->getParentId(), false);
117  $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
118  $item["obj_title"] = $lm_obj->getTitle();
119  $item["sub_txt"] = $this->lng->txt("pg");
120  $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
121  $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
122  if ($ref_id > 0)
123  {
124  $item["obj_link"] = ilLink::_getStaticLink($page_obj->getId()."_".$ref_id, "pg");
125  }
126  }
127  break;
128 
129  case "dbk":
130  require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
131  require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
132  require_once("./Modules/LearningModule/classes/class.ilObjDlBook.php");
133  if (ilObject::_lookupType($page_obj->getParentId()) == "dbk")
134  {
135  $lm_obj =& new ilObjDlBook($page_obj->getParentId(), false);
136  $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
137  $item["obj_title"] = $lm_obj->getTitle();
138  $item["sub_txt"] = $this->lng->txt("pg");
139  $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
140  $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
141  if ($ref_id > 0)
142  {
143  $item["obj_link"] = ilLink::_getStaticLink($page_obj->getId()."_".$ref_id, "pg");
144  }
145  }
146  break;
147 
148  case "wpg":
149  require_once("./Modules/Wiki/classes/class.ilWikiPage.php");
150  $item["obj_type_txt"] = $this->lng->txt("obj_wiki");
151  $item["obj_title"] = ilObject::_lookupTitle($page_obj->getParentId());
152  $item["sub_txt"] = $this->lng->txt("pg");
153  $item["sub_title"] = ilWikiPage::lookupTitle($page_obj->getId());
154  $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
155  if ($ref_id > 0)
156  {
157  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "wiki");
158  }
159  break;
160 
161  case "gdf":
162  require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
163  require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
164  $term_id = ilGlossaryDefinition::_lookupTermId($page_obj->getId());
165  $glo_id = ilGlossaryTerm::_lookGlossaryId($term_id);
166  $item["obj_type_txt"] = $this->lng->txt("obj_glo");
167  $item["obj_title"] = ilObject::_lookupTitle($glo_id);
168  $item["sub_txt"] = $this->lng->txt("cont_term");
169  $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id);
170  $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
171  if ($ref_id > 0)
172  {
173  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo");
174  }
175  break;
176 
177  case "cont":
178  $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
179  $item["obj_title"] = ilObject::_lookupTitle($page_obj->getId());
180  $ref_id = $this->getFirstWritableRefId($page_obj->getId());
181  if ($ref_id > 0)
182  {
183  $item["obj_link"] = ilLink::_getStaticLink($ref_id, $cont_type);
184  }
185  break;
186  }
187  break;
188 
189  case "mep":
190  $item["obj_type_txt"] = $this->lng->txt("obj_mep");
191  $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
192  $ref_id = $this->getFirstWritableRefId($usage["id"]);
193  if ($ref_id > 0)
194  {
195  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep");
196  }
197  break;
198 
199  case "map":
200  $item["obj_type_txt"] = $this->lng->txt("obj_mob");
201  $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
202  $item["sub_txt"] = $this->lng->txt("cont_link_area");
203  break;
204  }
205 
206  // show versions
207  if (is_array($usage["hist_nr"]) &&
208  (count($usage["hist_nr"]) > 1 || $usage["hist_nr"][0] > 0))
209  {
210  asort($usage["hist_nr"]);
211  $ver = $sep = "";
212  if ($usage["hist_nr"][0] == 0)
213  {
214  array_shift($usage["hist_nr"]);
215  $usage["hist_nr"][] = 0;
216  }
217  if (count($usage["hist_nr"]) > 5)
218  {
219  $ver.= "..., ";
220  $cnt = count($usage["hist_nr"]) - 5;
221  for ($i = 0; $i < $cnt; $i++)
222  {
223  unset($usage["hist_nr"][$i]);
224  }
225  }
226 
227  foreach ($usage["hist_nr"] as $nr)
228  {
229  if ($nr > 0)
230  {
231  $ver.= $sep.$nr;
232  }
233  else
234  {
235  $ver.= $sep.$this->lng->txt("cont_current_version");
236  }
237  $sep = ", ";
238  }
239 
240  $this->tpl->setCurrentBlock("versions");
241  $this->tpl->setVariable("TXT_VERSIONS", $this->lng->txt("cont_versions"));
242  $this->tpl->setVariable("VAL_VERSIONS", $ver);
243  $this->tpl->parseCurrentBlock();
244  }
245 
246  if ($item["obj_type_txt"] != "")
247  {
248  $this->tpl->setCurrentBlock("type");
249  $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("type"));
250  $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]);
251  $this->tpl->parseCurrentBlock();
252  }
253 
254  if ($usage["type"] != "clip")
255  {
256  if ($item["obj_link"])
257  {
258  $this->tpl->setCurrentBlock("linked_item");
259  $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"]);
260  $this->tpl->setVariable("HREF_LINK", $item["obj_link"]);
261  $this->tpl->parseCurrentBlock();
262  }
263  else
264  {
265  $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"]);
266  }
267 
268  if ($item["sub_txt"] != "")
269  {
270  $this->tpl->setVariable("SEP", ", ");
271  $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]);
272  if ($item["sub_title"] != "")
273  {
274  $this->tpl->setVariable("SEP2", ": ");
275  $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]);
276  }
277  }
278 
279  }
280  else
281  {
282  $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1").
283  " ".$usage["cnt"]." ".$this->lng->txt("cont_users_have_mob_in_clip2"));
284 
285  }
286  }
287 
288  function getFirstWritableRefId($a_obj_id)
289  {
290  global $ilAccess;
291 
292  $ref_ids = ilObject::_getAllReferences($a_obj_id);
293  foreach ($ref_ids as $ref_id)
294  {
295  if ($ilAccess->checkAccess("write", "", $ref_id))
296  {
297  return $ref_id;
298  }
299  }
300  return 0;
301  }
302 }
303 ?>