ILIAS  Release_4_0_x_branch Revision 61816
 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 "wpg":
168  require_once("./Modules/Wiki/classes/class.ilWikiPage.php");
169  $item["obj_type_txt"] = $this->lng->txt("obj_wiki");
170  $item["obj_title"] = ilObject::_lookupTitle($page_obj->getParentId());
171  $item["sub_txt"] = $this->lng->txt("pg");
172  $item["sub_title"] = ilWikiPage::lookupTitle($page_obj->getId());
173  $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
174  if ($ref_id > 0)
175  {
176  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "wiki");
177  }
178  break;
179 
180  case "gdf":
181  require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
182  require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
183  $term_id = ilGlossaryDefinition::_lookupTermId($page_obj->getId());
184  $glo_id = ilGlossaryTerm::_lookGlossaryId($term_id);
185  $item["obj_type_txt"] = $this->lng->txt("obj_glo");
186  $item["obj_title"] = ilObject::_lookupTitle($glo_id);
187  $item["sub_txt"] = $this->lng->txt("cont_term");
188  $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id);
189  $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
190  if ($ref_id > 0)
191  {
192  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo");
193  }
194  break;
195 
196  case "fold":
197  case "root":
198  case "crs":
199  case "grp":
200  case "cat":
201  $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
202  $item["obj_title"] = ilObject::_lookupTitle($page_obj->getId());
203  $ref_id = $this->getFirstWritableRefId($page_obj->getId());
204  if ($ref_id > 0)
205  {
206  $item["obj_link"] = ilLink::_getStaticLink($ref_id, $cont_type);
207  }
208  break;
209  }
210  break;
211 
212  case "mep":
213  $item["obj_type_txt"] = $this->lng->txt("obj_mep");
214  $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
215  $ref_id = $this->getFirstWritableRefId($usage["id"]);
216  if ($ref_id > 0)
217  {
218  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep");
219  }
220  break;
221 
222  case "map":
223  $item["obj_type_txt"] = $this->lng->txt("obj_mob");
224  $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
225  $item["sub_txt"] = $this->lng->txt("cont_link_area");
226  break;
227  }
228 
229  // show versions
230  if (is_array($usage["hist_nr"]) &&
231  (count($usage["hist_nr"]) > 1 || $usage["hist_nr"][0] > 0))
232  {
233  asort($usage["hist_nr"]);
234  $ver = $sep = "";
235  if ($usage["hist_nr"][0] == 0)
236  {
237  array_shift($usage["hist_nr"]);
238  $usage["hist_nr"][] = 0;
239  }
240  if (count($usage["hist_nr"]) > 5)
241  {
242  $ver.= "..., ";
243  $cnt = count($usage["hist_nr"]) - 5;
244  for ($i = 0; $i < $cnt; $i++)
245  {
246  unset($usage["hist_nr"][$i]);
247  }
248  }
249 
250  foreach ($usage["hist_nr"] as $nr)
251  {
252  if ($nr > 0)
253  {
254  $ver.= $sep.$nr;
255  }
256  else
257  {
258  $ver.= $sep.$this->lng->txt("cont_current_version");
259  }
260  $sep = ", ";
261  }
262 
263  $this->tpl->setCurrentBlock("versions");
264  $this->tpl->setVariable("TXT_VERSIONS", $this->lng->txt("cont_versions"));
265  $this->tpl->setVariable("VAL_VERSIONS", $ver);
266  $this->tpl->parseCurrentBlock();
267  }
268 
269  if ($item["obj_type_txt"] != "")
270  {
271  $this->tpl->setCurrentBlock("type");
272  $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("type"));
273  $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]);
274  $this->tpl->parseCurrentBlock();
275  }
276 
277  if ($usage["type"] != "clip")
278  {
279  if ($item["obj_link"])
280  {
281  $this->tpl->setCurrentBlock("linked_item");
282  $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"]);
283  $this->tpl->setVariable("HREF_LINK", $item["obj_link"]);
284  $this->tpl->parseCurrentBlock();
285  }
286  else
287  {
288  $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"]);
289  }
290 
291  if ($item["sub_txt"] != "")
292  {
293  $this->tpl->setVariable("SEP", ", ");
294  $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]);
295  if ($item["sub_title"] != "")
296  {
297  $this->tpl->setVariable("SEP2", ": ");
298  $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]);
299  }
300  }
301 
302  }
303  else
304  {
305  $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1").
306  " ".$usage["cnt"]." ".$this->lng->txt("cont_users_have_mob_in_clip2"));
307 
308  }
309  }
310 
311  function getFirstWritableRefId($a_obj_id)
312  {
313  global $ilAccess;
314 
315  $ref_ids = ilObject::_getAllReferences($a_obj_id);
316  foreach ($ref_ids as $ref_id)
317  {
318  if ($ilAccess->checkAccess("write", "", $ref_id))
319  {
320  return $ref_id;
321  }
322  }
323  return 0;
324  }
325 }
326 ?>