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