ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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 $clip_cnt = 0;
60 $agg_usages = array();
61 foreach ($usages as $k => $usage) {
62 $usage["trash"] = false;
63 if (is_int(strpos($usage["type"], ":"))) {
64 $us_arr = explode(":", $usage["type"]);
65
66 // try to figure out object id of pages
67 if ($us_arr[1] === "pg") {
68 $page_obj = ilPageObjectFactory::getInstance($us_arr[0], $usage["id"]);
69 $usage["page"] = $page_obj;
71 $ref_ids = array_filter(
72 ilObject::_getAllReferences($page_obj->getRepoObjId()),
73 static function ($ref_id) use ($repo_tree): bool {
75 }
76 );
77 $usage["ref_ids"] = $ref_ids;
78 if (count($ref_ids) === 0) {
79 $usage["trash"] = true;
80 }
81 }
82 }
83
84 if ($usage["type"] === "clip") {
85 $clip_cnt++;
86 } elseif ($this->incl_hist || !$usage["trash"]) {
87 if (empty($agg_usages[$usage["type"] . ":" . $usage["id"]])) {
88 $agg_usages[$usage["type"] . ":" . $usage["id"]] = $usage;
89 }
90 $agg_usages[$usage["type"] . ":" . $usage["id"]]["versions"][] =
91 ["hist_nr" => $usage["hist_nr"] ?? 0,
92 "lang" => $usage["lang"] ?? ""
93 ];
94 }
95 }
96
97 // usages in clipboards
98 if ($clip_cnt > 0) {
99 $agg_usages[] = array("type" => "clip", "cnt" => $clip_cnt);
100 }
101 $this->setData($agg_usages);
102 }
103
104 protected function fillRow(array $a_set): void
105 {
107 $usage = $a_set;
108 $cont_type = "";
109 $item = null;
110
111 if (is_int(strpos($usage["type"], ":"))) {
112 $us_arr = explode(":", $usage["type"]);
113 $usage["type"] = $us_arr[1];
114 $cont_type = $us_arr[0];
115 }
116
117 switch ($usage["type"]) {
118 case "pg":
119 $page_obj = $usage["page"];
120 $item = array();
121
122 switch ($cont_type) {
123 case "lm":
124 $lm_obj = new ilObjLearningModule($page_obj->getParentId(), false);
125 $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type);
126 $item["obj_title"] = $lm_obj->getTitle();
127 $item["sub_txt"] = $this->lng->txt("pg");
128 $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
129 $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
130 if ($ref_id > 0) {
131 $item["obj_link"] = ilLink::_getLink(null, "pg", [], $page_obj->getId() . "_" . $ref_id);
132 }
133 break;
134
135 case "wpg":
136 $item["obj_type_txt"] = $this->lng->txt("obj_wiki");
137 $item["obj_title"] = ilObject::_lookupTitle($page_obj->getParentId());
138 $item["sub_txt"] = $this->lng->txt("pg");
139 $item["sub_title"] = ilWikiPage::lookupTitle($page_obj->getId());
140 $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
141 if ($ref_id > 0) {
142 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "wiki");
143 }
144 break;
145
146 case "term":
147 $term_id = $page_obj->getId();
148 $glo_id = ilGlossaryTerm::_lookGlossaryID($term_id);
149 $item["obj_type_txt"] = $this->lng->txt("obj_glo");
150 $item["obj_title"] = ilObject::_lookupTitle($glo_id);
151 $item["sub_txt"] = $this->lng->txt("cont_term");
152 $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id);
153 $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
154 if ($ref_id > 0) {
155 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo");
156 }
157 break;
158
159 case "cont":
160 $type = ilObject::_lookupType($page_obj->getId());
161 $item["obj_type_txt"] = $this->lng->txt("obj_" . $type);
162 $item["obj_title"] = ilObject::_lookupTitle($page_obj->getId());
163 $ref_id = $this->getFirstWritableRefId($page_obj->getId());
164 if ($ref_id > 0) {
165 $item["obj_link"] = ilLink::_getStaticLink($ref_id, $type);
166 }
167 break;
168
169 case "copa":
170 $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type);
171 $item["obj_title"] = ilObject::_lookupTitle($page_obj->getId());
172 $ref_id = $this->getFirstWritableRefId($page_obj->getId());
173 if ($ref_id > 0) {
174 $item["obj_link"] = ilLink::_getStaticLink($ref_id, $cont_type);
175 }
176 break;
177 }
178
179 if ($usage["trash"]) {
180 $item["obj_title"] .= " (" . $lng->txt("trash") . ")";
181 }
182
183 break;
184
185 case "mep":
186 $item["obj_type_txt"] = $this->lng->txt("obj_mep");
187 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
188 $ref_id = $this->getFirstWritableRefId($usage["id"]);
189 if ($ref_id > 0) {
190 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep");
191 }
192 break;
193
194 case "map":
195 $item["obj_type_txt"] = $this->lng->txt("obj_mob");
196 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
197 $item["sub_txt"] = $this->lng->txt("cont_link_area");
198 break;
199 }
200
201 // show versions
202 if (is_array($usage["versions"] ?? null) && is_object($usage["page"] ?? null)) {
203 $ver = $sep = "";
204
205 if (count($usage["versions"]) > 5) {
206 $ver .= "..., ";
207 $cnt = count($usage["versions"]) - 5;
208 for ($i = 0; $i < $cnt; $i++) {
209 unset($usage["versions"][$i]);
210 }
211 }
212 foreach ($usage["versions"] as $version) {
213 if ($version["hist_nr"] == 0) {
214 $version["hist_nr"] = $this->lng->txt("cont_current_version");
215 }
216 $ver .= $sep . $version["hist_nr"];
217 if ($version["lang"] != "") {
218 $ver .= "/" . $version["lang"];
219 }
220 $sep = ", ";
221 }
222
223 $this->tpl->setCurrentBlock("versions");
224 $this->tpl->setVariable("TXT_VERSIONS", $this->lng->txt("cont_versions"));
225 $this->tpl->setVariable("VAL_VERSIONS", $ver);
226 $this->tpl->parseCurrentBlock();
227 }
228
229 if (($item["obj_type_txt"] ?? "") != "") {
230 $this->tpl->setCurrentBlock("type");
231 $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("type"));
232 $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]);
233 $this->tpl->parseCurrentBlock();
234 }
235
236 if ($usage["type"] !== "clip") {
237 if ($item["obj_link"] ?? false) {
238 $this->tpl->setCurrentBlock("linked_item");
239 $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"] ?? "");
240 $this->tpl->setVariable("HREF_LINK", $item["obj_link"] ?? "");
241 $this->tpl->parseCurrentBlock();
242 } else {
243 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"] ?? "");
244 }
245
246 if (($item["sub_txt"] ?? "") != "") {
247 $this->tpl->setVariable("SEP", ", ");
248 $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]);
249 if ($item["sub_title"] != "") {
250 $this->tpl->setVariable("SEP2", ": ");
251 $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]);
252 }
253 }
254 } else {
255 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1") .
256 " " . $usage["cnt"] . " " . $this->lng->txt("cont_users_have_mob_in_clip2"));
257 }
258 }
259
260 public function getFirstWritableRefId(int $a_obj_id): int
261 {
262 $ilAccess = $this->access;
263
264 $ref_ids = ilObject::_getAllReferences($a_obj_id);
265 foreach ($ref_ids as $ref_id) {
266 if ($ilAccess->checkAccess("write", "", $ref_id)) {
267 return $ref_id;
268 }
269 }
270 return 0;
271 }
272}
$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 _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="-")
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