ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
5 include_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 
38  parent::__construct($a_parent_obj, $a_parent_cmd);
39  $this->page = $a_page;
40  $this->incl_hist = $a_incl_hist;
41  $this->addColumn("", "", "1"); // checkbox
42  $this->setEnableHeader(false);
43  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
44  $this->setRowTemplate("tpl.mep_page_usage_row.html", "Modules/MediaPool");
45  $this->getItems();
46  $this->setTitle($lng->txt("cont_mob_usages"));
47  }
48 
52  public function getItems()
53  {
54  $usages = $this->page->getUsages($this->incl_hist);
55 
56  $clip_cnt = 0;
57  $to_del = array();
58  $agg_usages = array();
59  foreach ($usages as $k => $usage) {
60  if ($usage["type"] == "clip") {
61  $clip_cnt++;
62  } else {
63  if (empty($agg_usages[$usage["type"] . ":" . $usage["id"]])) {
64  $usage["hist_nr"] = array($usage["hist_nr"]);
65  $agg_usages[$usage["type"] . ":" . $usage["id"]] = $usage;
66  } else {
67  $agg_usages[$usage["type"] . ":" . $usage["id"]]["hist_nr"][] =
68  $usage["hist_nr"];
69  }
70  }
71  }
72 
73  // usages in clipboards
74  if ($clip_cnt > 0) {
75  $agg_usages[] = array("type" => "clip", "cnt" => $clip_cnt);
76  }
77 
78  $this->setData($agg_usages);
79  }
80 
85  protected function fillRow($a_set)
86  {
87  $lng = $this->lng;
89  $ilAccess = $this->access;
90 
91  $usage = $a_set;
92 
93  //var_dump($usage);
94 
95  if (is_int(strpos($usage["type"], ":"))) {
96  $us_arr = explode(":", $usage["type"]);
97  $usage["type"] = $us_arr[1];
98  $cont_type = $us_arr[0];
99  }
100  //var_dump($usage);
101 
102  include_once('./Services/Link/classes/class.ilLink.php');
103 
104  switch ($usage["type"]) {
105  case "pg":
106  include_once("./Services/COPage/classes/class.ilPageObjectFactory.php");
107  $page_obj = ilPageObjectFactory::getInstance($cont_type, $usage["id"]);
108  $item = array();
109 
110  //$this->tpl->setVariable("TXT_OBJECT", $usage["type"].":".$usage["id"]);
111  switch ($cont_type) {
112  case "lm":
113  require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
114  require_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
115  require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
116  $lm_obj = new ilObjLearningModule($page_obj->getParentId(), false);
117  $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type);
118  $item["obj_title"] = $lm_obj->getTitle();
119  $item["sub_txt"] = $this->lng->txt("pg");
120  $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId());
121  $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
122  if ($ref_id > 0) {
123  $item["obj_link"] = ilLink::_getStaticLink($page_obj->getId() . "_" . $ref_id, "pg");
124  }
125  break;
126 
127  case "wpg":
128  require_once("./Modules/Wiki/classes/class.ilWikiPage.php");
129  $item["obj_type_txt"] = $this->lng->txt("obj_wiki");
130  $item["obj_title"] = ilObject::_lookupTitle($page_obj->getParentId());
131  $item["sub_txt"] = $this->lng->txt("pg");
132  $item["sub_title"] = ilWikiPage::lookupTitle($page_obj->getId());
133  $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
134  if ($ref_id > 0) {
135  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "wiki");
136  }
137  break;
138 
139  case "gdf":
140  require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
141  require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
142  $term_id = ilGlossaryDefinition::_lookupTermId($page_obj->getId());
143  $glo_id = ilGlossaryTerm::_lookGlossaryId($term_id);
144  $item["obj_type_txt"] = $this->lng->txt("obj_glo");
145  $item["obj_title"] = ilObject::_lookupTitle($glo_id);
146  $item["sub_txt"] = $this->lng->txt("cont_term");
147  $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id);
148  $ref_id = $this->getFirstWritableRefId($page_obj->getParentId());
149  if ($ref_id > 0) {
150  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo");
151  }
152  break;
153 
154  case "cont":
155  $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type);
156  $item["obj_title"] = ilObject::_lookupTitle($page_obj->getId());
157  $ref_id = $this->getFirstWritableRefId($page_obj->getId());
158  if ($ref_id > 0) {
159  $item["obj_link"] = ilLink::_getStaticLink($ref_id, $cont_type);
160  }
161  break;
162  }
163  break;
164 
165  case "mep":
166  $item["obj_type_txt"] = $this->lng->txt("obj_mep");
167  $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
168  $ref_id = $this->getFirstWritableRefId($usage["id"]);
169  if ($ref_id > 0) {
170  $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep");
171  }
172  break;
173 
174  case "map":
175  $item["obj_type_txt"] = $this->lng->txt("obj_mob");
176  $item["obj_title"] = ilObject::_lookupTitle($usage["id"]);
177  $item["sub_txt"] = $this->lng->txt("cont_link_area");
178  break;
179  }
180 
181  // show versions
182  if (is_array($usage["hist_nr"]) &&
183  (count($usage["hist_nr"]) > 1 || $usage["hist_nr"][0] > 0)) {
184  asort($usage["hist_nr"]);
185  $ver = $sep = "";
186  if ($usage["hist_nr"][0] == 0) {
187  array_shift($usage["hist_nr"]);
188  $usage["hist_nr"][] = 0;
189  }
190 
191  if (count($usage["hist_nr"]) > 5) {
192  $ver.= "..., ";
193  $cnt = count($usage["hist_nr"]) - 5;
194  for ($i = 0; $i < $cnt; $i++) {
195  unset($usage["hist_nr"][$i]);
196  }
197  }
198  foreach ($usage["hist_nr"] as $nr) {
199  if ($nr > 0) {
200  $ver.= $sep . $nr;
201  } else {
202  $ver.= $sep . $this->lng->txt("cont_current_version");
203  }
204  $sep = ", ";
205  }
206 
207  $this->tpl->setCurrentBlock("versions");
208  $this->tpl->setVariable("TXT_VERSIONS", $this->lng->txt("cont_versions"));
209  $this->tpl->setVariable("VAL_VERSIONS", $ver);
210  $this->tpl->parseCurrentBlock();
211  }
212 
213  if ($item["obj_type_txt"] != "") {
214  $this->tpl->setCurrentBlock("type");
215  $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("type"));
216  $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]);
217  $this->tpl->parseCurrentBlock();
218  }
219 
220  if ($usage["type"] != "clip") {
221  if ($item["obj_link"]) {
222  $this->tpl->setCurrentBlock("linked_item");
223  $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"]);
224  $this->tpl->setVariable("HREF_LINK", $item["obj_link"]);
225  $this->tpl->parseCurrentBlock();
226  } else {
227  $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"]);
228  }
229 
230  if ($item["sub_txt"] != "") {
231  $this->tpl->setVariable("SEP", ", ");
232  $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]);
233  if ($item["sub_title"] != "") {
234  $this->tpl->setVariable("SEP2", ": ");
235  $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]);
236  }
237  }
238  } else {
239  $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1") .
240  " " . $usage["cnt"] . " " . $this->lng->txt("cont_users_have_mob_in_clip2"));
241  }
242  }
243 
244  public function getFirstWritableRefId($a_obj_id)
245  {
246  $ilAccess = $this->access;
247 
248  $ref_ids = ilObject::_getAllReferences($a_obj_id);
249  foreach ($ref_ids as $ref_id) {
250  if ($ilAccess->checkAccess("write", "", $ref_id)) {
251  return $ref_id;
252  }
253  }
254  return 0;
255  }
256 }
static lookupTitle($a_page_id)
Checks whether a page with given title exists.
Class ilObjLearningModule.
global $DIC
Definition: saml.php:7
static _lookupTitle($a_id)
lookup object title
static _lookupTitle($a_obj_id)
Lookup title.
static _getAllReferences($a_id)
get all reference ids of object
TableGUI class for media pool page usages listing.
__construct($a_parent_obj, $a_parent_cmd, $a_page, $a_incl_hist)
Constructor.
fillRow($a_set)
Standard Version of Fill Row.
static _lookupTermId($a_def_id)
Looks up term id for a definition id.
global $ilCtrl
Definition: ilias.php:18
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
Class ilTable2GUI.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
Create styles array
The data for the language used.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
static getInstance($a_parent_type, $a_id=0, $a_old_nr=0, $a_lang="-")
Get page object instance.
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.
getTitle()
get title of content object
$i
Definition: disco.tpl.php:19
setEnableHeader($a_enableheader)
Set Enable Header.
static _lookGlossaryTerm($term_id)
get glossary term