ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMediaObjectUsagesTableGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected bool $include_hist;
29 protected ilTree $repo_tree;
30
31 public function __construct(
32 object $a_parent_obj,
33 string $a_parent_cmd,
34 ilObjMediaObject $a_media_object,
35 bool $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 $this->repo_tree = $DIC->repositoryTree();
46
47 parent::__construct($a_parent_obj, $a_parent_cmd);
48 $this->media_object = $a_media_object;
49 $this->include_hist = $a_include_hist;
50 $this->addColumn($lng->txt("mob_object"));
51 $this->addColumn($this->lng->txt("type"));
52 $this->addColumn($this->lng->txt("cont_versions"));
53 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
54 $this->setRowTemplate("tpl.mob_usage_row.html", "components/ILIAS/MediaObjects");
55 $this->getItems();
56 $this->setTitle($lng->txt("cont_mob_usages"));
57 }
58
62 public function getItems(): void
63 {
64 $usages = $this->media_object->getUsages($this->include_hist);
65
66 $clip_cnt = 0;
67 $to_del = array();
68 $agg_usages = array();
69 foreach ($usages as $k => $usage) {
70 $usage["trash"] = false;
71 if (is_int(strpos($usage["type"], ":"))) {
72 $us_arr = explode(":", $usage["type"]);
73
74 // try to figure out object id of pages
75 if ($us_arr[1] == "pg") {
76 $page_obj = ilPageObjectFactory::getInstance($us_arr[0], $usage["id"]);
77 $usage["page"] = $page_obj;
79 $ref_ids = array_filter(
80 ilObject::_getAllReferences($page_obj->getRepoObjId()),
81 function ($ref_id) use ($repo_tree) {
83 }
84 );
85 $usage["ref_ids"] = $ref_ids;
86 if (count($ref_ids) == 0) {
87 $usage["trash"] = true;
88 }
89 }
90 }
91
92
93 if ($usage["type"] == "clip") {
94 $clip_cnt++;
95 } else {
96 if ($this->include_hist || !$usage["trash"]) {
97 if (empty($agg_usages[$usage["type"] . ":" . $usage["id"]])) {
98 $agg_usages[$usage["type"] . ":" . $usage["id"]] = $usage;
99 }
100 $agg_usages[$usage["type"] . ":" . $usage["id"]]["versions"][] =
101 ["hist_nr" => $usage["hist_nr"] ?? 0,
102 "lang" => $usage["lang"] ?? ""];
103 }
104 }
105 }
106
107 // usages in clipboards
108 if ($clip_cnt > 0) {
109 $agg_usages[] = array("type" => "clip", "cnt" => $clip_cnt);
110 }
111 $this->setData($agg_usages);
112 }
113
114 protected function fillRow(array $a_set): void
115 {
117 $cont_type = "";
118 $usage = $a_set;
119 $item = [];
120
121 if (is_int(strpos($usage["type"], ":"))) {
122 $us_arr = explode(":", $usage["type"]);
123 $usage["type"] = $us_arr[1];
124 $cont_type = $us_arr[0];
125 }
126
127 switch ($usage["type"]) {
128 case "pg":
129 $page_obj = $usage["page"];
130
131 $item = array();
132
133 //$this->tpl->setVariable("TXT_OBJECT", $usage["type"].":".$usage["id"]);
134 switch ($cont_type) {
135 case "lm":
136 if (ilObject::_lookupType($page_obj->getParentId()) == "lm") {
137 $lm_obj = new ilObjLearningModule($page_obj->getParentId(), false);
138 $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type);
139 $item["obj_title"] = $lm_obj->getTitle();
140 $item["sub_txt"] = $this->lng->txt("pg");
141 $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
142 $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
143 if ($ref_id > 0) {
144 $item["obj_link"] = ilLink::_getStaticLink(null, "pg", "", $page_obj->getId() . "_" . $ref_id);
145 }
146 }
147 break;
148
149 case "wpg":
150 $item["obj_type_txt"] = $this->lng->txt("obj_wiki");
151 $item["obj_title"] = ilObject::_lookupTitle($page_obj->getParentId());
152 $item["sub_txt"] = $this->lng->txt("pg");
153 $item["sub_title"] = ilWikiPage::lookupTitle($page_obj->getId());
154 $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
155 if ($ref_id > 0) {
156 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "wiki");
157 }
158 break;
159
160 case "term":
161 $term_id = $page_obj->getId();
162 $glo_id = ilGlossaryTerm::_lookGlossaryID($term_id);
163 $item["obj_type_txt"] = $this->lng->txt("obj_glo");
164 $item["obj_title"] = ilObject::_lookupTitle($glo_id);
165 $item["sub_txt"] = $this->lng->txt("cont_term");
166 $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id);
167 $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
168 if ($ref_id > 0) {
169 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo");
170 }
171 break;
172
173 case "cont":
174 $otype = ilObject::_lookupType($page_obj->getId());
175 $item["obj_type_txt"] = $this->lng->txt("obj_" . $otype);
176 $item["obj_title"] = ilObject::_lookupTitle($page_obj->getId());
177 $ref_id = $this->getFirstWritableRefId($page_obj->getId());
178 if ($ref_id > 0) {
179 $item["obj_link"] = ilLink::_getStaticLink($ref_id, $otype);
180 }
181 break;
182
183 case "mep":
184 $item["obj_type_txt"] = $this->lng->txt("mep_page_type_mep");
185 $item["sub_txt"] = $this->lng->txt("mep_page_type_mep");
186 $item["sub_title"] = ilMediaPoolItem::lookupTitle($usage["id"]);
187
188 $mep_pools = ilMediaPoolItem::getPoolForItemId($usage["id"]);
189 foreach ($mep_pools as $mep_id) {
190 $ref_ids = ilObject::_getAllReferences($mep_id);
191 $item["obj_title"] = ilObject::_lookupTitle($mep_id);
192 foreach ($ref_ids as $rid) {
193 $item["obj_link"] = ilLink::_getStaticLink($rid, "mep");
194 break;
195 }
196 break;
197 }
198 break;
199
200 default:
202 if ($oid > 0) {
203 $type = ilObject::_lookupType($oid);
204 $item["obj_type_txt"] = $this->lng->txt("obj_" . $type);
205 $item["obj_title"] = ilObject::_lookupTitle($oid);
206 $ref_id = $this->getFirstWritableRefId($oid);
207 if ($ref_id > 0) {
208 $item["obj_link"] = ilLink::_getStaticLink($ref_id, $type);
209 }
210 }
211 break;
212 }
213
214 if ($usage["trash"]) {
215 $item["obj_title"] .= " (" . $lng->txt("trash") . ")";
216 }
217
218 break;
219
220 case "mep":
221 $item["obj_type_txt"] = $this->lng->txt("obj_mep");
222 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
223 $ref_id = $this->getFirstWritableRefId($usage["id"]);
224 if ($ref_id > 0) {
225 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep");
226 }
227 break;
228
229 case "map":
230 $item["obj_type_txt"] = $this->lng->txt("obj_mob");
231 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
232 $item["sub_txt"] = $this->lng->txt("cont_link_area");
233 break;
234
235 case "news":
236 $obj_id = ilNewsItem::_lookupContextObjId($usage["id"]);
237 $obj_type = ilObject::_lookupType($obj_id);
238 $item["obj_type_txt"] = $this->lng->txt("obj_" . $obj_type);
239 $item["obj_title"] = ilObject::_lookupTitle($obj_id);
240 $item["sub_txt"] = $this->lng->txt("news");
241 $ref_id = $this->getFirstWritableRefId($obj_id);
242 if ($ref_id > 0) {
243 $item["obj_link"] = ilLink::_getStaticLink($ref_id, $obj_type);
244 }
245 break;
246 }
247
248 // show versions
249 if (is_array($usage["versions"]) && is_object($usage["page"] ?? null)) {
250 $ver = $sep = "";
251
252 if (count($usage["versions"]) > 5) {
253 $ver .= "..., ";
254 $cnt = count($usage["versions"]) - 5;
255 for ($i = 0; $i < $cnt; $i++) {
256 unset($usage["versions"][$i]);
257 }
258 }
259 foreach ($usage["versions"] as $version) {
260 if ($version["hist_nr"] == 0) {
261 $version["hist_nr"] = $this->lng->txt("cont_current_version");
262 }
263 $ver .= $sep . $version["hist_nr"];
264 if ($version["lang"] != "") {
265 $ver .= "/" . $version["lang"];
266 }
267 $sep = ", ";
268 }
269
270 $this->tpl->setCurrentBlock("versions");
271 $this->tpl->setVariable("VAL_VERSIONS", $ver);
272 } else {
273 $this->tpl->setCurrentBlock("versions");
274 $this->tpl->setVariable("VAL_VERSIONS", " ");
275 }
276 $this->tpl->parseCurrentBlock();
277
278 if (($item["obj_type_txt"] ?? "") != "") {
279 $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]);
280 }
281
282 if (($usage["type"] ?? "") != "clip") {
283 if ($item["obj_link"] ?? false) {
284 $this->tpl->setCurrentBlock("linked_item");
285 $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"]);
286 $this->tpl->setVariable("HREF_LINK", $item["obj_link"]);
287 $this->tpl->parseCurrentBlock();
288 } else {
289 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"]);
290 }
291
292 if (($item["sub_txt"] ?? "") != "") {
293 $this->tpl->setVariable("SEP", ", ");
294 $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]);
295 if (($item["sub_title"] ?? "") != "") {
296 $this->tpl->setVariable("SEP2", ": ");
297 $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]);
298 }
299 }
300 } else {
301 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1") .
302 " " . $usage["cnt"] . " " . $this->lng->txt("cont_users_have_mob_in_clip2"));
303 }
304 }
305
306 public function getFirstWritableRefId(
307 int $a_obj_id
308 ): int {
309 $ilAccess = $this->access;
310
311 $ref_ids = ilObject::_getAllReferences($a_obj_id);
312 foreach ($ref_ids as $ref_id) {
313 if ($ilAccess->checkAccess("write", "", $ref_id)) {
314 return $ref_id;
315 }
316 }
317 return 0;
318 }
319}
$version
Definition: plugin.php:24
static _lookGlossaryTerm(int $term_id)
get glossary term
static _lookGlossaryID(int $term_id)
get glossary id form term id
static _lookupTitle(int $a_obj_id)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(object $a_parent_obj, string $a_parent_cmd, ilObjMediaObject $a_media_object, bool $a_include_hist=false)
fillRow(array $a_set)
Standard Version of Fill Row.
static getPoolForItemId(int $a_id)
static lookupTitle(int $a_id)
static _lookupContextObjId(int $a_news_id)
Context Object ID.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getParentObjectIdForUsage(array $a_usage, bool $a_include_all_access_obj_ids=false)
Get's the repository object ID of a parent object, if possible see ilWebAccessChecker.
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
static getInstance(string $a_parent_type, int $a_id=0, int $a_old_nr=0, string $a_lang="-")
Get page object instance.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setData(array $a_data)
Set table data.
ilLanguage $lng
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
isInTree(?int $a_node_id)
get all information of a node.
static lookupTitle(int $a_page_id, string $lang="-")
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26