ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilMediaObjectUsagesTableGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("Services/Table/classes/class.ilTable2GUI.php");
6
16{
17
21 function __construct($a_parent_obj, $a_parent_cmd, $a_media_object,
22 $a_include_hist = false)
23 {
24 global $ilCtrl, $lng, $ilAccess, $lng;
25
26 parent::__construct($a_parent_obj, $a_parent_cmd);
27 $this->media_object = $a_media_object;
28 $this->include_hist = $a_include_hist;
29 $this->addColumn($lng->txt("mob_object"));
30 $this->addColumn($this->lng->txt("type"));
31 if ($a_include_hist)
32 {
33 $this->addColumn($this->lng->txt("cont_versions"));
34 }
35 //$this->setEnableHeader(false);
36 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
37 $this->setRowTemplate("tpl.mob_usage_row.html", "Services/MediaObjects");
38 $this->getItems();
39 $this->setTitle($lng->txt("cont_mob_usages"));
40 }
41
45 function getItems()
46 {
47 $usages = $this->media_object->getUsages($this->include_hist);
48
49 $clip_cnt = 0;
50 $to_del = array();
51 $agg_usages = array();
52 foreach($usages as $k => $usage)
53 {
54 if ($usage["type"] == "clip")
55 {
56 $clip_cnt++;
57 }
58 else
59 {
60 if (empty($agg_usages[$usage["type"].":".$usage["id"]]))
61 {
62 $usage["hist_nr"] = array($usage["hist_nr"]);
63 $agg_usages[$usage["type"].":".$usage["id"]] = $usage;
64 }
65 else
66 {
67 $agg_usages[$usage["type"].":".$usage["id"]]["hist_nr"][] =
68 $usage["hist_nr"];
69 }
70 }
71 }
72
73 // usages in clipboards
74 if ($clip_cnt > 0)
75 {
76 $agg_usages[] = array("type" => "clip", "cnt" => $clip_cnt);
77 }
78
79 $this->setData($agg_usages);
80 }
81
86 protected function fillRow($a_set)
87 {
88 global $lng, $ilCtrl, $ilAccess;
89
90 $usage = $a_set;
91
92//var_dump($usage);
93
94 if(is_int(strpos($usage["type"], ":")))
95 {
96 $us_arr = explode(":", $usage["type"]);
97 $usage["type"] = $us_arr[1];
98 $cont_type = $us_arr[0];
99 }
100
101 include_once('./Services/Link/classes/class.ilLink.php');
102
103 switch($usage["type"])
104 {
105 case "pg":
106 include_once("./Services/COPage/classes/class.ilPageObjectFactory.php");
107 $page_obj = ilPageObjectFactory::getInstance($cont_type, $usage["id"]);
108
109 $item = array();
110
111 //$this->tpl->setVariable("TXT_OBJECT", $usage["type"].":".$usage["id"]);
112 switch ($cont_type)
113 {
114 case "lm":
115 require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
116 require_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
117 require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
118 if (ilObject::_lookupType($page_obj->getParentId()) == "lm")
119 {
120 $lm_obj =& new ilObjLearningModule($page_obj->getParentId(), false);
121 $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
122 $item["obj_title"] = $lm_obj->getTitle();
123 $item["sub_txt"] = $this->lng->txt("pg");
124 $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
125 $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
126 if ($ref_id > 0)
127 {
128 $item["obj_link"] = ilLink::_getStaticLink($page_obj->getId()."_".$ref_id, "pg");
129 }
130 }
131 break;
132
133 case "dbk":
134 require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
135 require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
136 require_once("./Modules/LearningModule/classes/class.ilObjDlBook.php");
137 if (ilObject::_lookupType($page_obj->getParentId()) == "dbk")
138 {
139 $lm_obj =& new ilObjDlBook($page_obj->getParentId(), false);
140 $item["obj_type_txt"] = $this->lng->txt("obj_".$cont_type);
141 $item["obj_title"] = $lm_obj->getTitle();
142 $item["sub_txt"] = $this->lng->txt("pg");
143 $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
144 $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
145 if ($ref_id > 0)
146 {
147 $item["obj_link"] = ilLink::_getStaticLink($page_obj->getId()."_".$ref_id, "pg");
148 }
149 }
150 break;
151
152 case "wpg":
153 require_once("./Modules/Wiki/classes/class.ilWikiPage.php");
154 $item["obj_type_txt"] = $this->lng->txt("obj_wiki");
155 $item["obj_title"] = ilObject::_lookupTitle($page_obj->getParentId());
156 $item["sub_txt"] = $this->lng->txt("pg");
157 $item["sub_title"] = ilWikiPage::lookupTitle($page_obj->getId());
158 $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
159 if ($ref_id > 0)
160 {
161 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "wiki");
162 }
163 break;
164
165 case "gdf":
166 require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
167 require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
168 $term_id = ilGlossaryDefinition::_lookupTermId($page_obj->getId());
169 $glo_id = ilGlossaryTerm::_lookGlossaryId($term_id);
170 $item["obj_type_txt"] = $this->lng->txt("obj_glo");
171 $item["obj_title"] = ilObject::_lookupTitle($glo_id);
172 $item["sub_txt"] = $this->lng->txt("cont_term");
173 $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id);
174 $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
175 if ($ref_id > 0)
176 {
177 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo");
178 }
179 break;
180
181 case "cont":
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 default:
192 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
194 if ($oid > 0)
195 {
196 $type = ilObject::_lookupType($oid);
197 $item["obj_type_txt"] = $this->lng->txt("obj_".$type);
198 $item["obj_title"] = ilObject::_lookupTitle($oid);
199 $ref_id = $this->getFirstWritableRefId($oid);
200 if ($ref_id > 0)
201 {
202 $item["obj_link"] = ilLink::_getStaticLink($ref_id, $type);
203 }
204 }
205 break;
206 }
207 break;
208
209 case "mep":
210 $item["obj_type_txt"] = $this->lng->txt("obj_mep");
211 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
212 $ref_id = $this->getFirstWritableRefId($usage["id"]);
213 if ($ref_id > 0)
214 {
215 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep");
216 }
217 break;
218
219 case "map":
220 $item["obj_type_txt"] = $this->lng->txt("obj_mob");
221 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
222 $item["sub_txt"] = $this->lng->txt("cont_link_area");
223 break;
224 }
225
226 // show versions
227 if ($this->include_hist)
228 {
229 $ver = "";
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 }
264 $this->tpl->setCurrentBlock("versions");
265 $this->tpl->setVariable("VAL_VERSIONS", $ver);
266 $this->tpl->parseCurrentBlock();
267 }
268
269 if ($item["obj_type_txt"] != "")
270 {
271 $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]);
272 }
273
274 if ($usage["type"] != "clip")
275 {
276 if ($item["obj_link"])
277 {
278 $this->tpl->setCurrentBlock("linked_item");
279 $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"]);
280 $this->tpl->setVariable("HREF_LINK", $item["obj_link"]);
281 $this->tpl->parseCurrentBlock();
282 }
283 else
284 {
285 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"]);
286 }
287
288 if ($item["sub_txt"] != "")
289 {
290 $this->tpl->setVariable("SEP", ", ");
291 $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]);
292 if ($item["sub_title"] != "")
293 {
294 $this->tpl->setVariable("SEP2", ": ");
295 $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]);
296 }
297 }
298
299 }
300 else
301 {
302 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1").
303 " ".$usage["cnt"]." ".$this->lng->txt("cont_users_have_mob_in_clip2"));
304
305 }
306 }
307
308 function getFirstWritableRefId($a_obj_id)
309 {
310 global $ilAccess;
311
312 $ref_ids = ilObject::_getAllReferences($a_obj_id);
313 foreach ($ref_ids as $ref_id)
314 {
315 if ($ilAccess->checkAccess("write", "", $ref_id))
316 {
317 return $ref_id;
318 }
319 }
320 return 0;
321 }
322}
323?>
_lookupTermId($a_def_id)
Looks up term id for a definition id.
static _lookGlossaryTerm($term_id)
get glossary term
static _lookupTitle($a_obj_id)
Lookup title.
TableGUI class for media object usages listing.
__construct($a_parent_obj, $a_parent_cmd, $a_media_object, $a_include_hist=false)
Constructor.
fillRow($a_set)
Standard Version of Fill Row.
Class ilObjDlBook.
Class ilObjLearningModule.
getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids=false)
Get's the repository object ID of a parent object, if possible.
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
static getInstance($a_parent_type, $a_id=0, $a_old_nr=0, $a_lang="-")
Get page object instance.
Class ilTable2GUI.
addColumn($a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
setData($a_data)
set table data @access public
setRowTemplate($a_template, $a_template_dir="")
Set row template.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
static lookupTitle($a_page_id)
Checks whether a page with given title exists.
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40
$ref_id
Definition: sahs_server.php:39