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