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