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