ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMediaPoolPageUsagesTableGUI.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_page)
41  {
42  global $ilCtrl, $lng, $ilAccess, $lng;
43 
44  parent::__construct($a_parent_obj, $a_parent_cmd);
45  $this->page = $a_page;
46 
47  $this->addColumn("", "", "1"); // checkbox
48  $this->setEnableHeader(false);
49  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
50  $this->setRowTemplate("tpl.mep_page_usage_row.html", "Modules/MediaPool");
51  $this->getItems();
52  $this->setTitle($lng->txt("cont_mob_usages"));
53  }
54 
58  function getItems()
59  {
60  $usages = $this->page->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  $lm_obj =& new ilObjLearningModule($page_obj->getParentId(), false);
134  $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
135  $item["obj_title"] = $lm_obj->getTitle();
136  $item["sub_txt"] = $this->lng->txt("pg");
137  $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
138  $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
139  if ($ref_id > 0)
140  {
141  $item["obj_link"] = ilLink::_getStaticLink($page_obj->getId()."_".$ref_id, "pg");
142  }
143  break;
144 
145  case "dbk":
146  require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
147  require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
148  require_once("./Modules/LearningModule/classes/class.ilObjDlBook.php");
149  $lm_obj =& new ilObjDlBook($page_obj->getParentId(), false);
150  $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
151  $item["obj_title"] = $lm_obj->getTitle();
152  $item["sub_txt"] = $this->lng->txt("pg");
153  $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
154  $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
155  if ($ref_id > 0)
156  {
157  $item["obj_link"] = ilLink::_getStaticLink($page_obj->getId()."_".$ref_id, "pg");
158  }
159  break;
160 
161  case "gdf":
162  require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
163  require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
164  $term_id = ilGlossaryDefinition::_lookupTermId($page_obj->getId());
165  $glo_id = ilGlossaryTerm::_lookGlossaryId($term_id);
166  $item["obj_type_txt"] = $this->lng->txt("obj_glo");
167  $item["obj_title"] = ilObject::_lookupTitle($glo_id);
168  $item["sub_txt"] = $this->lng->txt("cont_term");
169  $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id);
170  $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
171  if ($ref_id > 0)
172  {
173  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo");
174  }
175  break;
176 
177  case "fold":
178  case "root":
179  case "crs":
180  case "grp":
181  case "cat":
182  $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
183  $item["obj_title"] = ilObject::_lookupTitle($page_obj->getId());
184  $ref_id = $this->getFirstWritableRefId($page_obj->getId());
185  if ($ref_id > 0)
186  {
187  $item["obj_link"] = ilLink::_getStaticLink($ref_id, $cont_type);
188  }
189  break;
190  }
191  break;
192 
193  case "mep":
194  $item["obj_type_txt"] = $this->lng->txt("obj_mep");
195  $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
196  $ref_id = $this->getFirstWritableRefId($usage["id"]);
197  if ($ref_id > 0)
198  {
199  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep");
200  }
201  break;
202 
203  case "map":
204  $item["obj_type_txt"] = $this->lng->txt("obj_mob");
205  $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
206  $item["sub_txt"] = $this->lng->txt("cont_link_area");
207  break;
208  }
209 
210  // show versions
211  if (is_array($usage["hist_nr"]) &&
212  (count($usage["hist_nr"]) > 1 || $usage["hist_nr"][0] > 0))
213  {
214  asort($usage["hist_nr"]);
215  $ver = $sep = "";
216  if ($usage["hist_nr"][0] == 0)
217  {
218  array_shift($usage["hist_nr"]);
219  $usage["hist_nr"][] = 0;
220  }
221 
222  if (count($usage["hist_nr"]) > 5)
223  {
224  $ver.= "..., ";
225  $cnt = count($usage["hist_nr"]) - 5;
226  for ($i = 0; $i < $cnt; $i++)
227  {
228  unset($usage["hist_nr"][$i]);
229  }
230  }
231  foreach ($usage["hist_nr"] as $nr)
232  {
233  if ($nr > 0)
234  {
235  $ver.= $sep.$nr;
236  }
237  else
238  {
239  $ver.= $sep.$this->lng->txt("cont_current_version");
240  }
241  $sep = ", ";
242  }
243 
244  $this->tpl->setCurrentBlock("versions");
245  $this->tpl->setVariable("TXT_VERSIONS", $this->lng->txt("cont_versions"));
246  $this->tpl->setVariable("VAL_VERSIONS", $ver);
247  $this->tpl->parseCurrentBlock();
248  }
249 
250  if ($item["obj_type_txt"] != "")
251  {
252  $this->tpl->setCurrentBlock("type");
253  $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("type"));
254  $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]);
255  $this->tpl->parseCurrentBlock();
256  }
257 
258  if ($usage["type"] != "clip")
259  {
260  if ($item["obj_link"])
261  {
262  $this->tpl->setCurrentBlock("linked_item");
263  $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"]);
264  $this->tpl->setVariable("HREF_LINK", $item["obj_link"]);
265  $this->tpl->parseCurrentBlock();
266  }
267  else
268  {
269  $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"]);
270  }
271 
272  if ($item["sub_txt"] != "")
273  {
274  $this->tpl->setVariable("SEP", ", ");
275  $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]);
276  if ($item["sub_title"] != "")
277  {
278  $this->tpl->setVariable("SEP2", ": ");
279  $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]);
280  }
281  }
282 
283  }
284  else
285  {
286  $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1").
287  " ".$usage["cnt"]." ".$this->lng->txt("cont_users_have_mob_in_clip2"));
288 
289  }
290  }
291 
292  function getFirstWritableRefId($a_obj_id)
293  {
294  global $ilAccess;
295 
296  $ref_ids = ilObject::_getAllReferences($a_obj_id);
297  foreach ($ref_ids as $ref_id)
298  {
299  if ($ilAccess->checkAccess("write", "", $ref_id))
300  {
301  return $ref_id;
302  }
303  }
304  return 0;
305  }
306 }
307 ?>