ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
16{
20 protected $access;
21
22
26 public function __construct($a_parent_obj, $a_parent_cmd, $a_page, $a_incl_hist)
27 {
28 global $DIC;
29
30 $this->ctrl = $DIC->ctrl();
31 $this->lng = $DIC->language();
32 $this->access = $DIC->access();
33 $ilCtrl = $DIC->ctrl();
34 $lng = $DIC->language();
35 $ilAccess = $DIC->access();
36 $lng = $DIC->language();
37 $this->repo_tree = $DIC->repositoryTree();
38
39 parent::__construct($a_parent_obj, $a_parent_cmd);
40 $this->page = $a_page;
41 $this->incl_hist = $a_incl_hist;
42 $this->addColumn("", "", "1"); // checkbox
43 $this->setEnableHeader(false);
44 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
45 $this->setRowTemplate("tpl.mep_page_usage_row.html", "Modules/MediaPool");
46 $this->getItems();
47 $this->setTitle($lng->txt("cont_mob_usages"));
48 }
49
53 public function getItems()
54 {
55 $usages = $this->page->getUsages($this->incl_hist);
56
57 $clip_cnt = 0;
58 $to_del = array();
59 $agg_usages = array();
60 foreach ($usages as $k => $usage) {
61 $usage["trash"] = false;
62 if (is_int(strpos($usage["type"], ":"))) {
63 $us_arr = explode(":", $usage["type"]);
64
65 // try to figure out object id of pages
66 if ($us_arr[1] == "pg") {
67 $page_obj = ilPageObjectFactory::getInstance($us_arr[0], $usage["id"]);
68 $usage["page"] = $page_obj;
69 $repo_tree = $this->repo_tree;
70 $ref_ids = array_filter(ilObject::_getAllReferences($page_obj->getRepoObjId()), function ($ref_id) use ($repo_tree) {
71 return $repo_tree->isInTree($ref_id);
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 // usages in clipboards
95 if ($clip_cnt > 0) {
96 $agg_usages[] = array("type" => "clip", "cnt" => $clip_cnt);
97 }
98 $this->setData($agg_usages);
99 }
100
105 protected function fillRow($a_set)
106 {
109 $ilAccess = $this->access;
110
111 $usage = $a_set;
112
113 //var_dump($usage);
114
115 if (is_int(strpos($usage["type"], ":"))) {
116 $us_arr = explode(":", $usage["type"]);
117 $usage["type"] = $us_arr[1];
118 $cont_type = $us_arr[0];
119 }
120 //var_dump($usage);
121
122 include_once('./Services/Link/classes/class.ilLink.php');
123
124 switch ($usage["type"]) {
125 case "pg":
126 include_once("./Services/COPage/classes/class.ilPageObjectFactory.php");
127 $page_obj = $usage["page"];
128 $item = array();
129
130 //$this->tpl->setVariable("TXT_OBJECT", $usage["type"].":".$usage["id"]);
131 switch ($cont_type) {
132 case "lm":
133 require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
134 require_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
135 require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
136 $lm_obj = new ilObjLearningModule($page_obj->getParentId(), false);
137 $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type);
138 $item["obj_title"] = $lm_obj->getTitle();
139 $item["sub_txt"] = $this->lng->txt("pg");
140 $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
141 $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
142 if ($ref_id > 0) {
143 $item["obj_link"] = ilLink::_getStaticLink($page_obj->getId() . "_" . $ref_id, "pg");
144 }
145 break;
146
147 case "wpg":
148 require_once("./Modules/Wiki/classes/class.ilWikiPage.php");
149 $item["obj_type_txt"] = $this->lng->txt("obj_wiki");
150 $item["obj_title"] = ilObject::_lookupTitle($page_obj->getParentId());
151 $item["sub_txt"] = $this->lng->txt("pg");
152 $item["sub_title"] = ilWikiPage::lookupTitle($page_obj->getId());
153 $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
154 if ($ref_id > 0) {
155 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "wiki");
156 }
157 break;
158
159 case "gdf":
160 require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
161 require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
162 $term_id = ilGlossaryDefinition::_lookupTermId($page_obj->getId());
163 $glo_id = ilGlossaryTerm::_lookGlossaryId($term_id);
164 $item["obj_type_txt"] = $this->lng->txt("obj_glo");
165 $item["obj_title"] = ilObject::_lookupTitle($glo_id);
166 $item["sub_txt"] = $this->lng->txt("cont_term");
167 $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id);
168 $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
169 if ($ref_id > 0) {
170 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo");
171 }
172 break;
173
174 case "cont":
175 $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type);
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, $cont_type);
180 }
181 break;
182 }
183
184 if ($usage["trash"]) {
185 $item["obj_title"] .= " (" . $lng->txt("trash") . ")";
186 }
187
188 break;
189
190 case "mep":
191 $item["obj_type_txt"] = $this->lng->txt("obj_mep");
192 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
193 $ref_id = $this->getFirstWritableRefId($usage["id"]);
194 if ($ref_id > 0) {
195 $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep");
196 }
197 break;
198
199 case "map":
200 $item["obj_type_txt"] = $this->lng->txt("obj_mob");
201 $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
202 $item["sub_txt"] = $this->lng->txt("cont_link_area");
203 break;
204 }
205
206 // show versions
207 if (is_array($usage["versions"]) && is_object($usage["page"])) {
208 $ver = $sep = "";
209
210 if (count($usage["versions"]) > 5) {
211 $ver .= "..., ";
212 $cnt = count($usage["versions"]) - 5;
213 for ($i = 0; $i < $cnt; $i++) {
214 unset($usage["versions"][$i]);
215 }
216 }
217 foreach ($usage["versions"] as $version) {
218 if ($version["hist_nr"] == 0) {
219 $version["hist_nr"] = $this->lng->txt("cont_current_version");
220 }
221 $ver .= $sep . $version["hist_nr"];
222 if ($version["lang"] != "") {
223 $ver .= "/" . $version["lang"];
224 }
225 $sep = ", ";
226 }
227
228 $this->tpl->setCurrentBlock("versions");
229 $this->tpl->setVariable("TXT_VERSIONS", $this->lng->txt("cont_versions"));
230 $this->tpl->setVariable("VAL_VERSIONS", $ver);
231 $this->tpl->parseCurrentBlock();
232 }
233
234
235 if ($item["obj_type_txt"] != "") {
236 $this->tpl->setCurrentBlock("type");
237 $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("type"));
238 $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]);
239 $this->tpl->parseCurrentBlock();
240 }
241
242 if ($usage["type"] != "clip") {
243 if ($item["obj_link"]) {
244 $this->tpl->setCurrentBlock("linked_item");
245 $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"]);
246 $this->tpl->setVariable("HREF_LINK", $item["obj_link"]);
247 $this->tpl->parseCurrentBlock();
248 } else {
249 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"]);
250 }
251
252 if ($item["sub_txt"] != "") {
253 $this->tpl->setVariable("SEP", ", ");
254 $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]);
255 if ($item["sub_title"] != "") {
256 $this->tpl->setVariable("SEP2", ": ");
257 $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]);
258 }
259 }
260 } else {
261 $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1") .
262 " " . $usage["cnt"] . " " . $this->lng->txt("cont_users_have_mob_in_clip2"));
263 }
264 }
265
266 public function getFirstWritableRefId($a_obj_id)
267 {
268 $ilAccess = $this->access;
269
270 $ref_ids = ilObject::_getAllReferences($a_obj_id);
271 foreach ($ref_ids as $ref_id) {
272 if ($ilAccess->checkAccess("write", "", $ref_id)) {
273 return $ref_id;
274 }
275 }
276 return 0;
277 }
278}
$version
Definition: build.php:27
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.
$i
Definition: disco.tpl.php:19
global $ilCtrl
Definition: ilias.php:18
global $DIC
Definition: saml.php:7