ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMediaObjectUsagesTableGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once("Services/Table/classes/class.ilTable2GUI.php");
25 
35 {
36 
40  function __construct($a_parent_obj, $a_parent_cmd, $a_media_object)
41  {
42  global $ilCtrl, $lng, $ilAccess, $lng;
43 
44  parent::__construct($a_parent_obj, $a_parent_cmd);
45  $this->media_object = $a_media_object;
46 
47  $this->addColumn("", "", "1"); // checkbox
48  $this->setEnableHeader(false);
49  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
50  $this->setRowTemplate("tpl.mob_usage_row.html", "Services/MediaObjects");
51  $this->getItems();
52  $this->setTitle($lng->txt("cont_mob_usages"));
53  }
54 
58  function getItems()
59  {
60  $usages = $this->media_object->getUsages();
61 
62  $clip_cnt = 0;
63  $to_del = array();
64  $agg_usages = array();
65  foreach($usages as $k => $usage)
66  {
67  if ($usage["type"] == "clip")
68  {
69  $clip_cnt++;
70  }
71  else
72  {
73  if (empty($agg_usages[$usage["type"].":".$usage["id"]]))
74  {
75  $usage["hist_nr"] = array($usage["hist_nr"]);
76  $agg_usages[$usage["type"].":".$usage["id"]] = $usage;
77  }
78  else
79  {
80  $agg_usages[$usage["type"].":".$usage["id"]]["hist_nr"][] =
81  $usage["hist_nr"];
82  }
83  }
84  }
85 
86  // usages in clipboards
87  if ($clip_cnt > 0)
88  {
89  $agg_usages[] = array("type" => "clip", "cnt" => $clip_cnt);
90  }
91 
92  $this->setData($agg_usages);
93  }
94 
99  protected function fillRow($a_set)
100  {
101  global $lng, $ilCtrl, $ilAccess;
102 
103  $usage = $a_set;
104 
105 //var_dump($usage);
106 
107  if(is_int(strpos($usage["type"], ":")))
108  {
109  $us_arr = explode(":", $usage["type"]);
110  $usage["type"] = $us_arr[1];
111  $cont_type = $us_arr[0];
112  }
113 //var_dump($usage);
114 
115  include_once('classes/class.ilLink.php');
116 
117  switch($usage["type"])
118  {
119  case "pg":
120 
121  require_once("./Services/COPage/classes/class.ilPageObject.php");
122  $page_obj = new ilPageObject($cont_type, $usage["id"]);
123 
124  $item = array();
125 
126  //$this->tpl->setVariable("TXT_OBJECT", $usage["type"].":".$usage["id"]);
127  switch ($cont_type)
128  {
129  case "lm":
130  require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
131  require_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
132  require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
133  if (ilObject::_lookupType($page_obj->getParentId()) == "lm")
134  {
135  $lm_obj =& new ilObjLearningModule($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 "dbk":
149  require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
150  require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
151  require_once("./Modules/LearningModule/classes/class.ilObjDlBook.php");
152  if (ilObject::_lookupType($page_obj->getParentId()) == "dbk")
153  {
154  $lm_obj =& new ilObjDlBook($page_obj->getParentId(), false);
155  $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
156  $item["obj_title"] = $lm_obj->getTitle();
157  $item["sub_txt"] = $this->lng->txt("pg");
158  $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
159  $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
160  if ($ref_id > 0)
161  {
162  $item["obj_link"] = ilLink::_getStaticLink($page_obj->getId()."_".$ref_id, "pg");
163  }
164  }
165  break;
166 
167  case "gdf":
168  require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
169  require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
170  $term_id = ilGlossaryDefinition::_lookupTermId($page_obj->getId());
171  $glo_id = ilGlossaryTerm::_lookGlossaryId($term_id);
172  $item["obj_type_txt"] = $this->lng->txt("obj_glo");
173  $item["obj_title"] = ilObject::_lookupTitle($glo_id);
174  $item["sub_txt"] = $this->lng->txt("cont_term");
175  $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id);
176  $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
177  if ($ref_id > 0)
178  {
179  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo");
180  }
181  break;
182 
183  case "fold":
184  case "root":
185  case "crs":
186  case "grp":
187  case "cat":
188  $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
189  $item["obj_title"] = ilObject::_lookupTitle($page_obj->getId());
190  $ref_id = $this->getFirstWritableRefId($page_obj->getId());
191  if ($ref_id > 0)
192  {
193  $item["obj_link"] = ilLink::_getStaticLink($ref_id, $cont_type);
194  }
195  break;
196  }
197  break;
198 
199  case "mep":
200  $item["obj_type_txt"] = $this->lng->txt("obj_mep");
201  $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
202  $ref_id = $this->getFirstWritableRefId($usage["id"]);
203  if ($ref_id > 0)
204  {
205  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep");
206  }
207  break;
208 
209  case "map":
210  $item["obj_type_txt"] = $this->lng->txt("obj_mob");
211  $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
212  $item["sub_txt"] = $this->lng->txt("cont_link_area");
213  break;
214  }
215 
216  // show versions
217  if (is_array($usage["hist_nr"]) &&
218  (count($usage["hist_nr"]) > 1 || $usage["hist_nr"][0] > 0))
219  {
220  asort($usage["hist_nr"]);
221  $ver = $sep = "";
222  if ($usage["hist_nr"][0] == 0)
223  {
224  array_shift($usage["hist_nr"]);
225  $usage["hist_nr"][] = 0;
226  }
227  if (count($usage["hist_nr"]) > 5)
228  {
229  $ver.= "..., ";
230  $cnt = count($usage["hist_nr"]) - 5;
231  for ($i = 0; $i < $cnt; $i++)
232  {
233  unset($usage["hist_nr"][$i]);
234  }
235  }
236 
237  foreach ($usage["hist_nr"] as $nr)
238  {
239  if ($nr > 0)
240  {
241  $ver.= $sep.$nr;
242  }
243  else
244  {
245  $ver.= $sep.$this->lng->txt("cont_current_version");
246  }
247  $sep = ", ";
248  }
249 
250  $this->tpl->setCurrentBlock("versions");
251  $this->tpl->setVariable("TXT_VERSIONS", $this->lng->txt("cont_versions"));
252  $this->tpl->setVariable("VAL_VERSIONS", $ver);
253  $this->tpl->parseCurrentBlock();
254  }
255 
256  if ($item["obj_type_txt"] != "")
257  {
258  $this->tpl->setCurrentBlock("type");
259  $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("type"));
260  $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]);
261  $this->tpl->parseCurrentBlock();
262  }
263 
264  if ($usage["type"] != "clip")
265  {
266  if ($item["obj_link"])
267  {
268  $this->tpl->setCurrentBlock("linked_item");
269  $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"]);
270  $this->tpl->setVariable("HREF_LINK", $item["obj_link"]);
271  $this->tpl->parseCurrentBlock();
272  }
273  else
274  {
275  $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"]);
276  }
277 
278  if ($item["sub_txt"] != "")
279  {
280  $this->tpl->setVariable("SEP", ", ");
281  $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]);
282  if ($item["sub_title"] != "")
283  {
284  $this->tpl->setVariable("SEP2", ": ");
285  $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]);
286  }
287  }
288 
289  }
290  else
291  {
292  $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1").
293  " ".$usage["cnt"]." ".$this->lng->txt("cont_users_have_mob_in_clip2"));
294 
295  }
296  }
297 
298  function getFirstWritableRefId($a_obj_id)
299  {
300  global $ilAccess;
301 
302  $ref_ids = ilObject::_getAllReferences($a_obj_id);
303  foreach ($ref_ids as $ref_id)
304  {
305  if ($ilAccess->checkAccess("write", "", $ref_id))
306  {
307  return $ref_id;
308  }
309  }
310  return 0;
311  }
312 }
313 ?>