ILIAS  Release_3_10_x_branch Revision 61812
 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 
65  $agg_usages = array();
66  foreach($usages as $k => $usage)
67  {
68  if ($usage["type"] == "clip")
69  {
70  $clip_cnt++;
71  }
72  else
73  {
74  if (empty($agg_usages[$usage["type"].":".$usage["id"]]))
75  {
76  $usage["hist_nr"] = array($usage["hist_nr"]);
77  $agg_usages[$usage["type"].":".$usage["id"]] = $usage;
78  }
79  else
80  {
81  $agg_usages[$usage["type"].":".$usage["id"]]["hist_nr"][] =
82  $usage["hist_nr"];
83  }
84  }
85  }
86 
87  // usages in clipboards
88  if ($clip_cnt > 0)
89  {
90  $agg_usages[] = array("type" => "clip", "cnt" => $clip_cnt);
91  }
92 
93  $this->setData($agg_usages);
94  }
95 
100  protected function fillRow($a_set)
101  {
102  global $lng, $ilCtrl, $ilAccess;
103 
104  $usage = $a_set;
105 
106 //var_dump($usage);
107 
108  if(is_int(strpos($usage["type"], ":")))
109  {
110  $us_arr = explode(":", $usage["type"]);
111  $usage["type"] = $us_arr[1];
112  $cont_type = $us_arr[0];
113  }
114 //var_dump($usage);
115 
116  include_once('classes/class.ilLink.php');
117 
118  switch($usage["type"])
119  {
120  case "pg":
121 
122  require_once("./Services/COPage/classes/class.ilPageObject.php");
123  $page_obj = new ilPageObject($cont_type, $usage["id"]);
124 
125  $item = array();
126 
127  //$this->tpl->setVariable("TXT_OBJECT", $usage["type"].":".$usage["id"]);
128  switch ($cont_type)
129  {
130  case "lm":
131  require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
132  require_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
133  require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
134  $lm_obj =& new ilObjLearningModule($page_obj->getParentId(), false);
135  $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
136  $item["obj_title"] = $lm_obj->getTitle();
137  $item["sub_txt"] = $this->lng->txt("pg");
138  $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
139  $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
140  if ($ref_id > 0)
141  {
142  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "lm");
143  }
144  break;
145 
146  case "dbk":
147  require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
148  require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
149  require_once("./Modules/LearningModule/classes/class.ilObjDlBook.php");
150  $lm_obj =& new ilObjDlBook($page_obj->getParentId(), false);
151  $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
152  $item["obj_title"] = $lm_obj->getTitle();
153  $item["sub_txt"] = $this->lng->txt("pg");
154  $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
155  $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
156  if ($ref_id > 0)
157  {
158  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "lm");
159  }
160  break;
161 
162  case "wpg":
163  require_once("./Modules/Wiki/classes/class.ilWikiPage.php");
164  $item["obj_type_txt"] = $this->lng->txt("obj_wiki");
165  $item["obj_title"] = ilObject::_lookupTitle($page_obj->getParentId());
166  $item["sub_txt"] = $this->lng->txt("pg");
167  $item["sub_title"] = ilWikiPage::lookupTitle($page_obj->getId());
168  $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
169  if ($ref_id > 0)
170  {
171  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "wiki");
172  }
173  break;
174 
175  case "gdf":
176  require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
177  require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
178  $term_id = ilGlossaryDefinition::_lookupTermId($page_obj->getId());
179  $glo_id = ilGlossaryTerm::_lookGlossaryId($term_id);
180  $item["obj_type_txt"] = $this->lng->txt("obj_glo");
181  $item["obj_title"] = ilObject::_lookupTitle($glo_id);
182  $item["sub_txt"] = $this->lng->txt("cont_term");
183  $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id);
184  $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
185  if ($ref_id > 0)
186  {
187  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo");
188  }
189  break;
190 
191  case "fold":
192  case "root":
193  case "crs":
194  case "grp":
195  case "cat":
196  $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
197  $item["obj_title"] = ilObject::_lookupTitle($page_obj->getId());
198  $ref_id = $this->getFirstWritableRefId($page_obj->getId());
199  if ($ref_id > 0)
200  {
201  $item["obj_link"] = ilLink::_getStaticLink($ref_id, $cont_type);
202  }
203  break;
204  }
205  break;
206 
207  case "mep":
208  $item["obj_type_txt"] = $this->lng->txt("obj_mep");
209  $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
210  $ref_id = $this->getFirstWritableRefId($usage["id"]);
211  if ($ref_id > 0)
212  {
213  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep");
214  }
215  break;
216 
217  case "map":
218  $item["obj_type_txt"] = $this->lng->txt("obj_mob");
219  $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
220  $item["sub_txt"] = $this->lng->txt("cont_link_area");
221  break;
222  }
223 
224  // show versions
225  if (is_array($usage["hist_nr"]) &&
226  (count($usage["hist_nr"]) > 1 || $usage["hist_nr"][0] > 0))
227  {
228  asort($usage["hist_nr"]);
229  $ver = $sep = "";
230  if ($usage["hist_nr"][0] == 0)
231  {
232  array_shift($usage["hist_nr"]);
233  $usage["hist_nr"][] = 0;
234  }
235  foreach ($usage["hist_nr"] as $nr)
236  {
237  if ($nr > 0)
238  {
239  $ver.= $sep.$nr;
240  }
241  else
242  {
243  $ver.= $sep.$this->lng->txt("cont_current_version");
244  }
245  $sep = ", ";
246  }
247 
248  $this->tpl->setCurrentBlock("versions");
249  $this->tpl->setVariable("TXT_VERSIONS", $this->lng->txt("cont_versions"));
250  $this->tpl->setVariable("VAL_VERSIONS", $ver);
251  $this->tpl->parseCurrentBlock();
252  }
253 
254  if ($item["obj_type_txt"] != "")
255  {
256  $this->tpl->setCurrentBlock("type");
257  $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("type"));
258  $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]);
259  $this->tpl->parseCurrentBlock();
260  }
261 
262  if ($usage["type"] != "clip")
263  {
264  if ($item["obj_link"])
265  {
266  $this->tpl->setCurrentBlock("linked_item");
267  $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"]);
268  $this->tpl->setVariable("HREF_LINK", $item["obj_link"]);
269  $this->tpl->parseCurrentBlock();
270  }
271  else
272  {
273  $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"]);
274  }
275 
276  if ($item["sub_txt"] != "")
277  {
278  $this->tpl->setVariable("SEP", ", ");
279  $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]);
280  if ($item["sub_title"] != "")
281  {
282  $this->tpl->setVariable("SEP2", ": ");
283  $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]);
284  }
285  }
286 
287  }
288  else
289  {
290  $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1").
291  " ".$usage["cnt"]." ".$this->lng->txt("cont_users_have_mob_in_clip2"));
292 
293  }
294  }
295 
296  function getFirstWritableRefId($a_obj_id)
297  {
298  global $ilAccess;
299 
300  $ref_ids = ilObject::_getAllReferences($a_obj_id);
301  foreach ($ref_ids as $ref_id)
302  {
303  if ($ilAccess->checkAccess("write", "", $ref_id))
304  {
305  return $ref_id;
306  }
307  }
308  return 0;
309  }
310 }
311 ?>