ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMediaPoolPageUsagesTableGUI.php
Go to the documentation of this file.
1<?php
2
24{
25 protected bool $incl_hist = false;
27 protected ilTree $repo_tree;
29
30 public function __construct(
31 object $a_parent_obj,
32 string $a_parent_cmd,
33 ilMediaPoolPage $a_page,
34 bool $a_incl_hist
35 ) {
36 global $DIC;
37
38 $this->ctrl = $DIC->ctrl();
39 $this->lng = $DIC->language();
40 $this->access = $DIC->access();
41 $ilCtrl = $DIC->ctrl();
42 $lng = $DIC->language();
43 $this->repo_tree = $DIC->repositoryTree();
44
45 parent::__construct($a_parent_obj, $a_parent_cmd);
46 $this->page = $a_page;
47 $this->incl_hist = $a_incl_hist;
48 $this->addColumn("", "", "1"); // checkbox
49 $this->setEnableHeader(false);
50 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
51 $this->setRowTemplate("tpl.mep_page_usage_row.html", "components/ILIAS/MediaPool");
52 $this->getItems();
53 $this->setTitle($lng->txt("cont_mob_usages"));
54 }
55
56 public function getItems(): void
57 {
58 $usages = $this->page->getUsages($this->incl_hist);
59
60 $clip_cnt = 0;
61 $agg_usages = array();
62 foreach ($usages as $k => $usage) {
63 $usage["trash"] = false;
64 if (is_int(strpos($usage["type"], ":"))) {
65 $us_arr = explode(":", $usage["type"]);
66
67 // try to figure out object id of pages
68 if ($us_arr[1] === "pg") {
69 $page_obj = ilPageObjectFactory::getInstance($us_arr[0], $usage["id"]);
70 $usage["page"] = $page_obj;
72 $ref_ids = array_filter(
73 ilObject::_getAllReferences($page_obj->getRepoObjId()),
74 static function ($ref_id) use ($repo_tree): bool {
76 }
77 );
78 $usage["ref_ids"] = $ref_ids;
79 if (count($ref_ids) === 0) {
80 $usage["trash"] = true;
81 }
82 }
83 }
84
85 if ($usage["type"] === "clip") {
86 $clip_cnt++;
87 } elseif ($this->incl_hist || !$usage["trash"]) {
88 if (empty($agg_usages[$usage["type"] . ":" . $usage["id"]])) {
89 $agg_usages[$usage["type"] . ":" . $usage["id"]] = $usage;
90 }
91 $agg_usages[$usage["type"] . ":" . $usage["id"]]["versions"][] =
92 ["hist_nr" => $usage["hist_nr"] ?? 0,
93 "lang" => $usage["lang"] ?? ""
94 ];
95 }
96 }
97
98 // usages in clipboards
99 if ($clip_cnt > 0) {
100 $agg_usages[] = array("type" => "clip", "cnt" => $clip_cnt);
101 }
102 $this->setData($agg_usages);
103 }
104
105 protected function fillRow(array $a_set): void
106 {
108 $usage = $a_set;
109 $cont_type = "";
110 $item = null;
111
112 if (is_int(strpos($usage["type"], ":"))) {
113 $us_arr = explode(":", $usage["type"]);
114 $usage["type"] = $us_arr[1];
115 $cont_type = $us_arr[0];
116 }
117
118 switch ($usage["type"]) {
119 case "pg":
120 $page_obj = $usage["page"];
121 $item = array();
122
123 switch ($cont_type) {
124 case "lm":
125 $lm_obj = new ilObjLearningModule($page_obj->getParentId(), false);
126 $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type);
127 $item["obj_title"] = $lm_obj->getTitle();
128 $item["sub_txt"] = $this->lng->txt("pg");
129 $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
130 $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
131 if ($ref_id > 0) {
132 $item["obj_link"] = ilLink::_getLink(null, "pg", [], $page_obj->getId() . "_" . $ref_id);
133 }
134 break;
135
136 case "wpg":
137 $item["obj_type_txt"] = $this->lng->txt("obj_wiki");
138 $item["obj_title"] = ilObject::_lookupTitle($page_obj->getParentId());
139 $item["sub_txt"] = $this->lng->txt("pg");
140 $item["sub_title"] = ilWikiPage::lookupTitle($page_obj->getId());
141 $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
142 if ($ref_id > 0) {
143 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "wiki");
144 }
145 break;
146
147 case "term":
148 $term_id = $page_obj->getId();
149 $glo_id = ilGlossaryTerm::_lookGlossaryID($term_id);
150 $item["obj_type_txt"] = $this->lng->txt("obj_glo");
151 $item["obj_title"] = ilObject::_lookupTitle($glo_id);
152 $item["sub_txt"] = $this->lng->txt("cont_term");
153 $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id);
154 $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
155 if ($ref_id > 0) {
156 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo");
157 }
158 break;
159
160 case "cont":
161 case "copa":
162 $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type);
163 $item["obj_title"] = ilObject::_lookupTitle($page_obj->getId());
164 $ref_id = $this->getFirstWritableRefId($page_obj->getId());
165 if ($ref_id > 0) {
166 $item["obj_link"] = ilLink::_getStaticLink($ref_id, $cont_type);
167 }
168 break;
169 }
170
171 if ($usage["trash"]) {
172 $item["obj_title"] .= " (" . $lng->txt("trash") . ")";
173 }
174
175 break;
176
177 case "mep":
178 $item["obj_type_txt"] = $this->lng->txt("obj_mep");
179 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
180 $ref_id = $this->getFirstWritableRefId($usage["id"]);
181 if ($ref_id > 0) {
182 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep");
183 }
184 break;
185
186 case "map":
187 $item["obj_type_txt"] = $this->lng->txt("obj_mob");
188 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
189 $item["sub_txt"] = $this->lng->txt("cont_link_area");
190 break;
191 }
192
193 // show versions
194 if (is_array($usage["versions"] ?? null) && is_object($usage["page"] ?? null)) {
195 $ver = $sep = "";
196
197 if (count($usage["versions"]) > 5) {
198 $ver .= "..., ";
199 $cnt = count($usage["versions"]) - 5;
200 for ($i = 0; $i < $cnt; $i++) {
201 unset($usage["versions"][$i]);
202 }
203 }
204 foreach ($usage["versions"] as $version) {
205 if ($version["hist_nr"] == 0) {
206 $version["hist_nr"] = $this->lng->txt("cont_current_version");
207 }
208 $ver .= $sep . $version["hist_nr"];
209 if ($version["lang"] != "") {
210 $ver .= "/" . $version["lang"];
211 }
212 $sep = ", ";
213 }
214
215 $this->tpl->setCurrentBlock("versions");
216 $this->tpl->setVariable("TXT_VERSIONS", $this->lng->txt("cont_versions"));
217 $this->tpl->setVariable("VAL_VERSIONS", $ver);
218 $this->tpl->parseCurrentBlock();
219 }
220
221 if (($item["obj_type_txt"] ?? "") != "") {
222 $this->tpl->setCurrentBlock("type");
223 $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("type"));
224 $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]);
225 $this->tpl->parseCurrentBlock();
226 }
227
228 if ($usage["type"] !== "clip") {
229 if ($item["obj_link"] ?? false) {
230 $this->tpl->setCurrentBlock("linked_item");
231 $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"] ?? "");
232 $this->tpl->setVariable("HREF_LINK", $item["obj_link"] ?? "");
233 $this->tpl->parseCurrentBlock();
234 } else {
235 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"] ?? "");
236 }
237
238 if (($item["sub_txt"] ?? "") != "") {
239 $this->tpl->setVariable("SEP", ", ");
240 $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]);
241 if ($item["sub_title"] != "") {
242 $this->tpl->setVariable("SEP2", ": ");
243 $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]);
244 }
245 }
246 } else {
247 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1") .
248 " " . $usage["cnt"] . " " . $this->lng->txt("cont_users_have_mob_in_clip2"));
249 }
250 }
251
252 public function getFirstWritableRefId(int $a_obj_id): int
253 {
254 $ilAccess = $this->access;
255
256 $ref_ids = ilObject::_getAllReferences($a_obj_id);
257 foreach ($ref_ids as $ref_id) {
258 if ($ilAccess->checkAccess("write", "", $ref_id)) {
259 return $ref_id;
260 }
261 }
262 return 0;
263 }
264}
$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...
fillRow(array $a_set)
Standard Version of Fill Row.
__construct(object $a_parent_obj, string $a_parent_cmd, ilMediaPoolPage $a_page, bool $a_incl_hist)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
setEnableHeader(bool $a_enableheader)
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