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