ILIAS  release_8 Revision v8.24
class.ilTermUsagesTableGUI.php
Go to the documentation of this file.
1<?php
2
23{
24 protected int $term_id;
26
27 public function __construct(
28 object $a_parent_obj,
29 string $a_parent_cmd,
30 int $a_term_id
31 ) {
32 global $DIC;
33
34 $this->ctrl = $DIC->ctrl();
35 $this->lng = $DIC->language();
36 $this->access = $DIC->access();
37 $ilCtrl = $DIC->ctrl();
38 $lng = $DIC->language();
39
40 parent::__construct($a_parent_obj, $a_parent_cmd);
41 $this->term_id = $a_term_id;
42
43 $this->addColumn("", "", "1"); // checkbox
44 $this->setEnableHeader(false);
45 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
46 $this->setRowTemplate("tpl.term_usage_row.html", "Modules/Glossary");
47 $this->getItems();
48 $this->setTitle($lng->txt("cont_usage"));
49 }
50
51 public function getItems(): void
52 {
53 $usages = ilGlossaryTerm::getUsages($this->term_id);
54
55 $agg_usages = array();
56 foreach ($usages as $k => $usage) {
57 if (empty($agg_usages[$usage["type"] . ":" . $usage["id"]])) {
58 $usage["hist_nr"] = array($usage["hist_nr"] ?? 0);
59 $agg_usages[$usage["type"] . ":" . $usage["id"]] = $usage;
60 } else {
61 $agg_usages[$usage["type"] . ":" . $usage["id"]]["hist_nr"][] =
62 $usage["hist_nr"] ?? 0;
63 }
64 }
65
66 $this->setData($agg_usages);
67 }
68
69 protected function fillRow(array $a_set): void
70 {
71 $usage = $a_set;
72
73 $cont_type = "";
74 if (is_int(strpos($usage["type"], ":"))) {
75 $us_arr = explode(":", $usage["type"]);
76 $usage["type"] = $us_arr[1];
77 $cont_type = $us_arr[0];
78 }
79
80 switch ($usage["type"]) {
81 case "pg":
82 $item = array();
83
84 //$this->tpl->setVariable("TXT_OBJECT", $usage["type"].":".$usage["id"]);
85 switch ($cont_type) {
86 case "lm":
87 $page_obj = new ilLMPage($usage["id"]);
88 $lm_obj = new ilObjLearningModule($page_obj->getParentId(), false);
89 $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type);
90 $item["obj_title"] = $lm_obj->getTitle();
91 $item["sub_txt"] = $this->lng->txt("pg");
92 $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
93 $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
94 if ($ref_id > 0) {
95 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "lm");
96 }
97 break;
98
99 case "wpg":
100 $page_obj = new ilWikiPage($usage["id"]);
101 $item["obj_type_txt"] = $this->lng->txt("obj_wiki");
102 $item["obj_title"] = ilObject::_lookupTitle($page_obj->getParentId());
103 $item["sub_txt"] = $this->lng->txt("pg");
104 $item["sub_title"] = ilWikiPage::lookupTitle($page_obj->getId());
105 $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
106 if ($ref_id > 0) {
107 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "wiki");
108 }
109 break;
110
111 case "gdf":
112 $page_obj = new ilGlossaryDefPage($usage["id"]);
113 $term_id = ilGlossaryDefinition::_lookupTermId($page_obj->getId());
115 $item["obj_type_txt"] = $this->lng->txt("obj_glo");
116 $item["obj_title"] = ilObject::_lookupTitle($glo_id);
117 $item["sub_txt"] = $this->lng->txt("cont_term");
118 $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id);
119 $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
120 if ($ref_id > 0) {
121 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo");
122 }
123 break;
124
125 case "fold":
126 case "root":
127 case "crs":
128 case "grp":
129 case "cat":
130 case "cont":
131 $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type);
132 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
133 $ref_id = $this->getFirstWritableRefId($usage["id"]);
134 if ($ref_id > 0) {
135 $item["obj_link"] = ilLink::_getStaticLink($ref_id, $cont_type);
136 }
137 break;
138
139 default:
140 $item["obj_title"] = "Page " . $cont_type . ", " . $usage["id"];
141 break;
142 }
143 break;
144
145 case "mep":
146 $item["obj_type_txt"] = $this->lng->txt("obj_mep");
147 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
148 $ref_id = $this->getFirstWritableRefId($usage["id"]);
149 if ($ref_id > 0) {
150 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep");
151 }
152 break;
153
154 case "map":
155 $item["obj_type_txt"] = $this->lng->txt("obj_mob");
156 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
157 $item["sub_txt"] = $this->lng->txt("cont_link_area");
158 break;
159
160 case "sqst":
161 $item["obj_type_txt"] = $this->lng->txt("cont_sqst");
162 $obj_id = SurveyQuestion::lookupObjFi($usage["id"]);
163 $item["obj_title"] = ilObject::_lookupTitle($obj_id);
164 $item["sub_txt"] = $this->lng->txt("question");
165 $item["sub_title"] = SurveyQuestion::_getTitle($usage["id"]);
166 $ref_id = $this->getFirstWritableRefId($obj_id);
167 if ($ref_id > 0) {
168 $item["obj_link"] = ilLink::_getStaticLink($ref_id);
169 }
170
171 break;
172
173 case "termref":
174 $item["obj_type_txt"] = $this->lng->txt("obj_glo");
175 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
176 $item["sub_txt"] = $this->lng->txt("glo_referenced_term");
177 $ref_id = $this->getFirstWritableRefId($usage["id"]);
178 if ($ref_id > 0) {
179 $item["obj_link"] = ilLink::_getStaticLink($ref_id);
180 }
181 break;
182
183 default:
184 $item["obj_title"] = "Type " . $usage["type"] . ", " . $usage["id"];
185 break;
186 }
187
188 // show versions
189 if (is_array($usage["hist_nr"]) &&
190 (count($usage["hist_nr"]) > 1 || $usage["hist_nr"][0] > 0)) {
191 asort($usage["hist_nr"]);
192 $ver = $sep = "";
193 if ($usage["hist_nr"][0] == 0) {
194 array_shift($usage["hist_nr"]);
195 $usage["hist_nr"][] = 0;
196 }
197 foreach ($usage["hist_nr"] as $nr) {
198 if ($nr > 0) {
199 $ver .= $sep . $nr;
200 } else {
201 $ver .= $sep . $this->lng->txt("cont_current_version");
202 }
203 $sep = ", ";
204 }
205
206 $this->tpl->setCurrentBlock("versions");
207 $this->tpl->setVariable("TXT_VERSIONS", $this->lng->txt("cont_versions"));
208 $this->tpl->setVariable("VAL_VERSIONS", $ver);
209 $this->tpl->parseCurrentBlock();
210 }
211
212 if ($item["obj_type_txt"] != "") {
213 $this->tpl->setCurrentBlock("type");
214 $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("type"));
215 $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]);
216 $this->tpl->parseCurrentBlock();
217 }
218
219 if ($usage["type"] != "clip") {
220 if ($item["obj_link"]) {
221 $this->tpl->setCurrentBlock("linked_item");
222 $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"]);
223 $this->tpl->setVariable("HREF_LINK", $item["obj_link"]);
224 $this->tpl->parseCurrentBlock();
225 } else {
226 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"]);
227 }
228
229 if ($item["sub_txt"] != "") {
230 $this->tpl->setVariable("SEP", ", ");
231 $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]);
232 if ($item["sub_title"] != "") {
233 $this->tpl->setVariable("SEP2", ": ");
234 $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]);
235 }
236 }
237 } else {
238 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1") .
239 " " . $usage["cnt"] . " " . $this->lng->txt("cont_users_have_mob_in_clip2"));
240 }
241 }
242
243 public function getFirstWritableRefId(int $a_obj_id): int
244 {
245 $ilAccess = $this->access;
246
247 $ref_ids = ilObject::_getAllReferences($a_obj_id);
248 foreach ($ref_ids as $ref_id) {
249 if ($ilAccess->checkAccess("write", "", $ref_id)) {
250 return $ref_id;
251 }
252 }
253 return 0;
254 }
255}
static _getTitle(int $question_id)
Returns the question title of a question with a given id.
static lookupObjFi(int $a_qid)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupTermId(int $a_def_id)
Looks up term id for a definition id.
static getUsages(int $a_term_id)
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
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
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, int $a_term_id)
fillRow(array $a_set)
Standard Version of Fill Row.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupTitle(int $a_page_id)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc