ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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{
20 protected $ctrl;
21
25 protected $access;
26
27
31 public function __construct(
32 $a_parent_obj,
33 $a_parent_cmd,
34 $a_media_object,
35 $a_include_hist = false
36 ) {
37 global $DIC;
38
39 $this->ctrl = $DIC->ctrl();
40 $this->lng = $DIC->language();
41 $this->access = $DIC->access();
42 $ilCtrl = $DIC->ctrl();
43 $lng = $DIC->language();
44
45 parent::__construct($a_parent_obj, $a_parent_cmd);
46 $this->media_object = $a_media_object;
47 $this->include_hist = $a_include_hist;
48 $this->addColumn($lng->txt("mob_object"));
49 $this->addColumn($this->lng->txt("type"));
50 if ($a_include_hist) {
51 $this->addColumn($this->lng->txt("cont_versions"));
52 }
53 //$this->setEnableHeader(false);
54 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
55 $this->setRowTemplate("tpl.mob_usage_row.html", "Services/MediaObjects");
56 $this->getItems();
57 $this->setTitle($lng->txt("cont_mob_usages"));
58 }
59
63 public function getItems()
64 {
65 $usages = $this->media_object->getUsages($this->include_hist);
66
67 $clip_cnt = 0;
68 $to_del = array();
69 $agg_usages = array();
70 foreach ($usages as $k => $usage) {
71 if ($usage["type"] == "clip") {
72 $clip_cnt++;
73 } else {
74 if (empty($agg_usages[$usage["type"] . ":" . $usage["id"]])) {
75 $usage["hist_nr"] = array($usage["hist_nr"]);
76 $agg_usages[$usage["type"] . ":" . $usage["id"]] = $usage;
77 } else {
78 $agg_usages[$usage["type"] . ":" . $usage["id"]]["hist_nr"][] =
79 $usage["hist_nr"];
80 }
81 }
82 }
83
84 // usages in clipboards
85 if ($clip_cnt > 0) {
86 $agg_usages[] = array("type" => "clip", "cnt" => $clip_cnt);
87 }
88
89 $this->setData($agg_usages);
90 }
91
96 protected function fillRow($a_set)
97 {
100 $ilAccess = $this->access;
101
102 $usage = $a_set;
103
104 //var_dump($usage);
105
106 if (is_int(strpos($usage["type"], ":"))) {
107 $us_arr = explode(":", $usage["type"]);
108 $usage["type"] = $us_arr[1];
109 $cont_type = $us_arr[0];
110 }
111
112 include_once('./Services/Link/classes/class.ilLink.php');
113
114 switch ($usage["type"]) {
115 case "pg":
116 include_once("./Services/COPage/classes/class.ilPageObjectFactory.php");
117 $page_obj = ilPageObjectFactory::getInstance($cont_type, $usage["id"]);
118
119 $item = array();
120
121 //$this->tpl->setVariable("TXT_OBJECT", $usage["type"].":".$usage["id"]);
122 switch ($cont_type) {
123 case "lm":
124 require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
125 require_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
126 require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
127 if (ilObject::_lookupType($page_obj->getParentId()) == "lm") {
128 $lm_obj = new ilObjLearningModule($page_obj->getParentId(), false);
129 $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type);
130 $item["obj_title"] = $lm_obj->getTitle();
131 $item["sub_txt"] = $this->lng->txt("pg");
132 $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
133 $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
134 if ($ref_id > 0) {
135 $item["obj_link"] = ilLink::_getStaticLink($page_obj->getId() . "_" . $ref_id, "pg");
136 }
137 }
138 break;
139
140 case "wpg":
141 require_once("./Modules/Wiki/classes/class.ilWikiPage.php");
142 $item["obj_type_txt"] = $this->lng->txt("obj_wiki");
143 $item["obj_title"] = ilObject::_lookupTitle($page_obj->getParentId());
144 $item["sub_txt"] = $this->lng->txt("pg");
145 $item["sub_title"] = ilWikiPage::lookupTitle($page_obj->getId());
146 $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
147 if ($ref_id > 0) {
148 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "wiki");
149 }
150 break;
151
152 case "gdf":
153 require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
154 require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
155 $term_id = ilGlossaryDefinition::_lookupTermId($page_obj->getId());
156 $glo_id = ilGlossaryTerm::_lookGlossaryId($term_id);
157 $item["obj_type_txt"] = $this->lng->txt("obj_glo");
158 $item["obj_title"] = ilObject::_lookupTitle($glo_id);
159 $item["sub_txt"] = $this->lng->txt("cont_term");
160 $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id);
161 $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
162 if ($ref_id > 0) {
163 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo");
164 }
165 break;
166
167 case "cont":
168 $otype = ilObject::_lookupType($page_obj->getId());
169 $item["obj_type_txt"] = $this->lng->txt("obj_" . $otype);
170 $item["obj_title"] = ilObject::_lookupTitle($page_obj->getId());
171 $ref_id = $this->getFirstWritableRefId($page_obj->getId());
172 if ($ref_id > 0) {
173 $item["obj_link"] = ilLink::_getStaticLink($ref_id, $otype);
174 }
175 break;
176
177 default:
178 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
180 if ($oid > 0) {
182 $item["obj_type_txt"] = $this->lng->txt("obj_" . $type);
183 $item["obj_title"] = ilObject::_lookupTitle($oid);
184 $ref_id = $this->getFirstWritableRefId($oid);
185 if ($ref_id > 0) {
186 $item["obj_link"] = ilLink::_getStaticLink($ref_id, $type);
187 }
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 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep");
199 }
200 break;
201
202 case "map":
203 $item["obj_type_txt"] = $this->lng->txt("obj_mob");
204 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
205 $item["sub_txt"] = $this->lng->txt("cont_link_area");
206 break;
207 }
208
209 // show versions
210 if ($this->include_hist) {
211 $ver = "";
212 if (is_array($usage["hist_nr"]) &&
213 (count($usage["hist_nr"]) > 1 || $usage["hist_nr"][0] > 0)) {
214 asort($usage["hist_nr"]);
215 $ver = $sep = "";
216 if ($usage["hist_nr"][0] == 0) {
217 array_shift($usage["hist_nr"]);
218 $usage["hist_nr"][] = 0;
219 }
220 if (count($usage["hist_nr"]) > 5) {
221 $ver.= "..., ";
222 $cnt = count($usage["hist_nr"]) - 5;
223 for ($i = 0; $i < $cnt; $i++) {
224 unset($usage["hist_nr"][$i]);
225 }
226 }
227
228 foreach ($usage["hist_nr"] as $nr) {
229 if ($nr > 0) {
230 $ver.= $sep . $nr;
231 } else {
232 $ver.= $sep . $this->lng->txt("cont_current_version");
233 }
234 $sep = ", ";
235 }
236 }
237 $this->tpl->setCurrentBlock("versions");
238 $this->tpl->setVariable("VAL_VERSIONS", $ver);
239 $this->tpl->parseCurrentBlock();
240 }
241
242 if ($item["obj_type_txt"] != "") {
243 $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]);
244 }
245
246 if ($usage["type"] != "clip") {
247 if ($item["obj_link"]) {
248 $this->tpl->setCurrentBlock("linked_item");
249 $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"]);
250 $this->tpl->setVariable("HREF_LINK", $item["obj_link"]);
251 $this->tpl->parseCurrentBlock();
252 } else {
253 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"]);
254 }
255
256 if ($item["sub_txt"] != "") {
257 $this->tpl->setVariable("SEP", ", ");
258 $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]);
259 if ($item["sub_title"] != "") {
260 $this->tpl->setVariable("SEP2", ": ");
261 $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]);
262 }
263 }
264 } else {
265 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1") .
266 " " . $usage["cnt"] . " " . $this->lng->txt("cont_users_have_mob_in_clip2"));
267 }
268 }
269
270 public function getFirstWritableRefId($a_obj_id)
271 {
272 $ilAccess = $this->access;
273
274 $ref_ids = ilObject::_getAllReferences($a_obj_id);
275 foreach ($ref_ids as $ref_id) {
276 if ($ilAccess->checkAccess("write", "", $ref_id)) {
277 return $ref_id;
278 }
279 }
280 return 0;
281 }
282}
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.
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.
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.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
static lookupTitle($a_page_id)
Checks whether a page with given title exists.
$i
Definition: disco.tpl.php:19
global $ilCtrl
Definition: ilias.php:18
$type
global $DIC
Definition: saml.php:7