ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 "wpg":
134 require_once("./Modules/Wiki/classes/class.ilWikiPage.php");
135 $item["obj_type_txt"] = $this->lng->txt("obj_wiki");
136 $item["obj_title"] = ilObject::_lookupTitle($page_obj->getParentId());
137 $item["sub_txt"] = $this->lng->txt("pg");
138 $item["sub_title"] = ilWikiPage::lookupTitle($page_obj->getId());
139 $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
140 if ($ref_id > 0)
141 {
142 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "wiki");
143 }
144 break;
145
146 case "gdf":
147 require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
148 require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
149 $term_id = ilGlossaryDefinition::_lookupTermId($page_obj->getId());
150 $glo_id = ilGlossaryTerm::_lookGlossaryId($term_id);
151 $item["obj_type_txt"] = $this->lng->txt("obj_glo");
152 $item["obj_title"] = ilObject::_lookupTitle($glo_id);
153 $item["sub_txt"] = $this->lng->txt("cont_term");
154 $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id);
155 $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
156 if ($ref_id > 0)
157 {
158 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo");
159 }
160 break;
161
162 case "cont":
163 $otype = ilObject::_lookupType($page_obj->getId());
164 $item["obj_type_txt"] = $this->lng->txt("obj_".$otype);
165 $item["obj_title"] = ilObject::_lookupTitle($page_obj->getId());
166 $ref_id = $this->getFirstWritableRefId($page_obj->getId());
167 if ($ref_id > 0)
168 {
169 $item["obj_link"] = ilLink::_getStaticLink($ref_id, $otype);
170 }
171 break;
172
173 default:
174 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
176 if ($oid > 0)
177 {
178 $type = ilObject::_lookupType($oid);
179 $item["obj_type_txt"] = $this->lng->txt("obj_".$type);
180 $item["obj_title"] = ilObject::_lookupTitle($oid);
181 $ref_id = $this->getFirstWritableRefId($oid);
182 if ($ref_id > 0)
183 {
184 $item["obj_link"] = ilLink::_getStaticLink($ref_id, $type);
185 }
186 }
187 break;
188 }
189 break;
190
191 case "mep":
192 $item["obj_type_txt"] = $this->lng->txt("obj_mep");
193 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
194 $ref_id = $this->getFirstWritableRefId($usage["id"]);
195 if ($ref_id > 0)
196 {
197 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep");
198 }
199 break;
200
201 case "map":
202 $item["obj_type_txt"] = $this->lng->txt("obj_mob");
203 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
204 $item["sub_txt"] = $this->lng->txt("cont_link_area");
205 break;
206 }
207
208 // show versions
209 if ($this->include_hist)
210 {
211 $ver = "";
212 if (is_array($usage["hist_nr"]) &&
213 (count($usage["hist_nr"]) > 1 || $usage["hist_nr"][0] > 0))
214 {
215 asort($usage["hist_nr"]);
216 $ver = $sep = "";
217 if ($usage["hist_nr"][0] == 0)
218 {
219 array_shift($usage["hist_nr"]);
220 $usage["hist_nr"][] = 0;
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
232 foreach ($usage["hist_nr"] as $nr)
233 {
234 if ($nr > 0)
235 {
236 $ver.= $sep.$nr;
237 }
238 else
239 {
240 $ver.= $sep.$this->lng->txt("cont_current_version");
241 }
242 $sep = ", ";
243 }
244
245 }
246 $this->tpl->setCurrentBlock("versions");
247 $this->tpl->setVariable("VAL_VERSIONS", $ver);
248 $this->tpl->parseCurrentBlock();
249 }
250
251 if ($item["obj_type_txt"] != "")
252 {
253 $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]);
254 }
255
256 if ($usage["type"] != "clip")
257 {
258 if ($item["obj_link"])
259 {
260 $this->tpl->setCurrentBlock("linked_item");
261 $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"]);
262 $this->tpl->setVariable("HREF_LINK", $item["obj_link"]);
263 $this->tpl->parseCurrentBlock();
264 }
265 else
266 {
267 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"]);
268 }
269
270 if ($item["sub_txt"] != "")
271 {
272 $this->tpl->setVariable("SEP", ", ");
273 $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]);
274 if ($item["sub_title"] != "")
275 {
276 $this->tpl->setVariable("SEP2", ": ");
277 $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]);
278 }
279 }
280
281 }
282 else
283 {
284 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1").
285 " ".$usage["cnt"]." ".$this->lng->txt("cont_users_have_mob_in_clip2"));
286
287 }
288 }
289
290 function getFirstWritableRefId($a_obj_id)
291 {
292 global $ilAccess;
293
294 $ref_ids = ilObject::_getAllReferences($a_obj_id);
295 foreach ($ref_ids as $ref_id)
296 {
297 if ($ilAccess->checkAccess("write", "", $ref_id))
298 {
299 return $ref_id;
300 }
301 }
302 return 0;
303 }
304}
305?>
An exception for terminatinating execution or to throw for unit testing.
static _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 ilObjLearningModule.
static 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:17
$ref_id
Definition: sahs_server.php:39