ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMediaPoolPageUsagesTableGUI.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
14{
18 protected $access;
19
23 public function __construct($a_parent_obj, $a_parent_cmd, $a_page, $a_incl_hist)
24 {
25 global $DIC;
26
27 $this->ctrl = $DIC->ctrl();
28 $this->lng = $DIC->language();
29 $this->access = $DIC->access();
30 $ilCtrl = $DIC->ctrl();
31 $lng = $DIC->language();
32 $ilAccess = $DIC->access();
33 $lng = $DIC->language();
34 $this->repo_tree = $DIC->repositoryTree();
35
36 parent::__construct($a_parent_obj, $a_parent_cmd);
37 $this->page = $a_page;
38 $this->incl_hist = $a_incl_hist;
39 $this->addColumn("", "", "1"); // checkbox
40 $this->setEnableHeader(false);
41 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
42 $this->setRowTemplate("tpl.mep_page_usage_row.html", "Modules/MediaPool");
43 $this->getItems();
44 $this->setTitle($lng->txt("cont_mob_usages"));
45 }
46
50 public function getItems()
51 {
52 $usages = $this->page->getUsages($this->incl_hist);
53
54 $clip_cnt = 0;
55 $to_del = array();
56 $agg_usages = array();
57 foreach ($usages as $k => $usage) {
58 $usage["trash"] = false;
59 if (is_int(strpos($usage["type"], ":"))) {
60 $us_arr = explode(":", $usage["type"]);
61
62 // try to figure out object id of pages
63 if ($us_arr[1] == "pg") {
64 $page_obj = ilPageObjectFactory::getInstance($us_arr[0], $usage["id"]);
65 $usage["page"] = $page_obj;
66 $repo_tree = $this->repo_tree;
67 $ref_ids = array_filter(
68 ilObject::_getAllReferences($page_obj->getRepoObjId()),
69 function ($ref_id) use ($repo_tree) {
70 return $repo_tree->isInTree($ref_id);
71 }
72 );
73 $usage["ref_ids"] = $ref_ids;
74 if (count($ref_ids) == 0) {
75 $usage["trash"] = true;
76 }
77 }
78 }
79
80 if ($usage["type"] == "clip") {
81 $clip_cnt++;
82 } else {
83 if ($this->incl_hist || !$usage["trash"]) {
84 if (empty($agg_usages[$usage["type"] . ":" . $usage["id"]])) {
85 $agg_usages[$usage["type"] . ":" . $usage["id"]] = $usage;
86 }
87 $agg_usages[$usage["type"] . ":" . $usage["id"]]["versions"][] =
88 ["hist_nr" => $usage["hist_nr"],
89 "lang" => $usage["lang"]
90 ];
91 }
92 }
93 }
94
95 // usages in clipboards
96 if ($clip_cnt > 0) {
97 $agg_usages[] = array("type" => "clip", "cnt" => $clip_cnt);
98 }
99 $this->setData($agg_usages);
100 }
101
106 protected function fillRow($a_set)
107 {
109 $ilCtrl = $this->ctrl;
110 $ilAccess = $this->access;
111
112 $usage = $a_set;
113
114 //var_dump($usage);
115
116 if (is_int(strpos($usage["type"], ":"))) {
117 $us_arr = explode(":", $usage["type"]);
118 $usage["type"] = $us_arr[1];
119 $cont_type = $us_arr[0];
120 }
121 //var_dump($usage);
122
123 include_once('./Services/Link/classes/class.ilLink.php');
124
125 switch ($usage["type"]) {
126 case "pg":
127 include_once("./Services/COPage/classes/class.ilPageObjectFactory.php");
128 $page_obj = $usage["page"];
129 $item = array();
130
131 //$this->tpl->setVariable("TXT_OBJECT", $usage["type"].":".$usage["id"]);
132 switch ($cont_type) {
133 case "lm":
134 require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
135 require_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
136 require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
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($page_obj->getId() . "_" . $ref_id, "pg");
145 }
146 break;
147
148 case "wpg":
149 require_once("./Modules/Wiki/classes/class.ilWikiPage.php");
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 "gdf":
161 $term_id = ilGlossaryDefinition::_lookupTermId($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 $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type);
175 $item["obj_title"] = ilObject::_lookupTitle($page_obj->getId());
176 $ref_id = $this->getFirstWritableRefId($page_obj->getId());
177 if ($ref_id > 0) {
178 $item["obj_link"] = ilLink::_getStaticLink($ref_id, $cont_type);
179 }
180 break;
181 }
182
183 if ($usage["trash"]) {
184 $item["obj_title"] .= " (" . $lng->txt("trash") . ")";
185 }
186
187 break;
188
189 case "mep":
190 $item["obj_type_txt"] = $this->lng->txt("obj_mep");
191 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
192 $ref_id = $this->getFirstWritableRefId($usage["id"]);
193 if ($ref_id > 0) {
194 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep");
195 }
196 break;
197
198 case "map":
199 $item["obj_type_txt"] = $this->lng->txt("obj_mob");
200 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
201 $item["sub_txt"] = $this->lng->txt("cont_link_area");
202 break;
203 }
204
205 // show versions
206 if (is_array($usage["versions"]) && is_object($usage["page"])) {
207 $ver = $sep = "";
208
209 if (count($usage["versions"]) > 5) {
210 $ver .= "..., ";
211 $cnt = count($usage["versions"]) - 5;
212 for ($i = 0; $i < $cnt; $i++) {
213 unset($usage["versions"][$i]);
214 }
215 }
216 foreach ($usage["versions"] as $version) {
217 if ($version["hist_nr"] == 0) {
218 $version["hist_nr"] = $this->lng->txt("cont_current_version");
219 }
220 $ver .= $sep . $version["hist_nr"];
221 if ($version["lang"] != "") {
222 $ver .= "/" . $version["lang"];
223 }
224 $sep = ", ";
225 }
226
227 $this->tpl->setCurrentBlock("versions");
228 $this->tpl->setVariable("TXT_VERSIONS", $this->lng->txt("cont_versions"));
229 $this->tpl->setVariable("VAL_VERSIONS", $ver);
230 $this->tpl->parseCurrentBlock();
231 }
232
233 if ($item["obj_type_txt"] != "") {
234 $this->tpl->setCurrentBlock("type");
235 $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("type"));
236 $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]);
237 $this->tpl->parseCurrentBlock();
238 }
239
240 if ($usage["type"] != "clip") {
241 if ($item["obj_link"]) {
242 $this->tpl->setCurrentBlock("linked_item");
243 $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"]);
244 $this->tpl->setVariable("HREF_LINK", $item["obj_link"]);
245 $this->tpl->parseCurrentBlock();
246 } else {
247 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"]);
248 }
249
250 if ($item["sub_txt"] != "") {
251 $this->tpl->setVariable("SEP", ", ");
252 $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]);
253 if ($item["sub_title"] != "") {
254 $this->tpl->setVariable("SEP2", ": ");
255 $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]);
256 }
257 }
258 } else {
259 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1") .
260 " " . $usage["cnt"] . " " . $this->lng->txt("cont_users_have_mob_in_clip2"));
261 }
262 }
263
264 public function getFirstWritableRefId($a_obj_id)
265 {
266 $ilAccess = $this->access;
267
268 $ref_ids = ilObject::_getAllReferences($a_obj_id);
269 foreach ($ref_ids as $ref_id) {
270 if ($ilAccess->checkAccess("write", "", $ref_id)) {
271 return $ref_id;
272 }
273 }
274 return 0;
275 }
276}
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 pool page usages listing.
fillRow($a_set)
Standard Version of Fill Row.
__construct($a_parent_obj, $a_parent_cmd, $a_page, $a_incl_hist)
Constructor.
Class ilObjLearningModule.
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
static getInstance($a_parent_type, $a_id=0, $a_old_nr=0, $a_lang="-")
Get page object instance.
Class ilTable2GUI.
setEnableHeader($a_enableheader)
Set Enable Header.
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.
global $DIC
Definition: goto.php:24
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc