ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilClassificationBlockGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("Services/Block/classes/class.ilBlockGUI.php");
5
17{
21 protected $obj_definition;
22
26 protected $tree;
27
28 protected $parent_obj_type; // [string]
29 protected $parent_obj_id; // [int]
30 protected $parent_ref_id; // [int]
31 protected $providers; // [array]
32 protected $item_list_gui; // [array]
33
34 protected static $providers_cache; // [array]
35
39 protected $repo;
40
41 public function __construct()
42 {
43 global $DIC;
44
45 $this->lng = $DIC->language();
46 $this->ctrl = $DIC->ctrl();
47 $this->obj_definition = $DIC["objDefinition"];
48 $this->tree = $DIC->repositoryTree();
49 $this->access = $DIC->access();
50 $lng = $DIC->language();
51
53
54 $this->parent_ref_id = (int) $_GET["ref_id"];
55 $this->parent_obj_id = ilObject::_lookupObjId($this->parent_ref_id);
56 $this->parent_obj_type = ilObject::_lookupType($this->parent_obj_id);
57
58 $lng->loadLanguageModule("classification");
59 $this->setTitle($lng->txt("clsfct_block_title"));
60 // @todo: find another solution for this
61 //$this->setFooterInfo($lng->txt("clsfct_block_info"));
62
63 $this->repo = new ilClassificationSessionRepository($this->parent_ref_id);
64 }
65
69 public function getBlockType() : string
70 {
71 return 'clsfct';
72 }
73
77 protected function isRepositoryObject() : bool
78 {
79 return false;
80 }
81
82 public function executeCommand()
83 {
84 $ilCtrl = $this->ctrl;
85
86 $cmd = $ilCtrl->getCmd();
87 $next_class = $ilCtrl->getNextClass($this);
88
89 switch ($next_class) {
90 default:
91 // explorer call
92 if ($ilCtrl->isAsynch() && $cmd != "getAjax" && $cmd != "filterContainer") {
93 $this->getHTML();
94 } else {
95 $this->$cmd();
96 }
97 break;
98 }
99 }
100
101 public static function getScreenMode()
102 {
103 global $DIC;
104
105 $ilCtrl = $DIC->ctrl();
106
107 if ($ilCtrl->isAsynch()) {
108 return;
109 }
110
111 switch ($ilCtrl->getCmd()) {
112 case "filterContainer":
113 return IL_SCREEN_CENTER;
114 }
115 }
116
117 public function getHTML()
118 {
120 $ilCtrl = $this->ctrl;
121
122 if (!$ilCtrl->isAsynch()) {
123// $this->repo->unsetAll();
124 }
125
126 $this->initProviders();
127
128 if (!$this->validate()) {
129 return "";
130 }
131
132 $tpl->addJavaScript("Services/Classification/js/ilClassification.js");
133
134 return parent::getHTML();
135 }
136
137 public function getAjax()
138 {
140
141 $this->initProviders(true);
142
143 echo $this->getHTML();
144 echo $tpl->getOnLoadCodeForAsynch();
145
146 exit();
147 }
148
149 protected function returnToParent()
150 {
151 $this->repo->unsetAll();
152 $this->ctrl->returnToParent($this);
153 }
154
155 public function fillDataSection()
156 {
158
159 $ilCtrl = $this->ctrl;
160
161 $html = array();
162 foreach ($this->providers as $provider) {
163 $provider->render($html, $this);
164 }
165
166 // $this->tpl->setVariable("BLOCK_ROW", "");
167
168 $ajax_block_id = "block_" . $this->getBlockType() . "_0";
169 $ajax_block_url = $ilCtrl->getLinkTarget($this, "getAjax", "", true, false);
170 $ajax_content_id = "il_center_col";
171 $ajax_content_url = $ilCtrl->getLinkTarget($this, "filterContainer", "", true, false);
172
173 $tabs = new ilTabsGUI();
174 $tabs->setBackTarget($this->lng->txt("clsfct_back_to_cat"), $ilCtrl->getLinkTarget($this, "returnToParent"));
175 $tabs->addTab("sel_objects", $this->lng->txt("clsfct_selected_objects"), "#");
176 $tabs_html = $tabs->getHTML();
177
178
179 // #15008 - always load regardless of content (because of redraw)
180 $tpl->addOnLoadCode('il.Classification.setAjax("' . $ajax_block_id . '", "' .
181 $ajax_block_url . '", "' . $ajax_content_id . '", "' . $ajax_content_url . '", ' . json_encode($tabs_html) . ');');
182
183 $overall_html = "";
184 if (sizeof($html)) {
185 $btpl = new ilTemplate("tpl.classification_block.html", true, true, "Services/Classification");
186
187 foreach ($html as $item) {
188 $btpl->setCurrentBlock("provider_chunk_bl");
189 $btpl->setVariable("TITLE", $item["title"]);
190 $btpl->setVariable("CHUNK", $item["html"]);
191 $btpl->parseCurrentBlock();
192 }
193
194 $overall_html .= $btpl->get();
195 //$this->tpl->setVariable("DATA", $btpl->get());
196 }
197 return $overall_html;
198 }
199
200 protected function validate()
201 {
202 return sizeof($this->providers);
203 }
204
205 protected function filterContainer()
206 {
207 $objDefinition = $this->obj_definition;
210 $ilAccess = $this->access;
212
213 $this->initProviders();
214
215 // empty selection is invalid
216 if ($this->repo->isEmpty()) {
217 exit();
218 }
219
220 $all_matching_provider_object_ids = null;
221 $no_provider = true;
222 foreach ($this->providers as $provider) {
223 $id = get_class($provider);
224 $current = $this->repo->getValueForProvider($id);
225 if ($current) {
226 $no_provider = false;
227 // combine providers AND
228 $provider_object_ids = $provider->getFilteredObjects();
229 if (is_array($all_matching_provider_object_ids)) {
230 $all_matching_provider_object_ids = array_intersect($all_matching_provider_object_ids, $provider_object_ids);
231 } else {
232 $all_matching_provider_object_ids = $provider_object_ids;
233 }
234 }
235 }
236 $has_content = false;
237
238
239 $ltpl = new ilTemplate("tpl.classification_object_list.html", true, true, "Services/Classification");
240
241 if (is_array($all_matching_provider_object_ids) && sizeof($all_matching_provider_object_ids)) {
242 $fields = array(
243 "object_reference.ref_id"
244 ,"object_data.obj_id"
245 ,"object_data.type"
246 ,"object_data.title"
247 ,"object_data.description"
248 );
249 // see #28883 (tags + filter still work on current level only)
250 // see also JF comment on https://docu.ilias.de/goto.php?target=wiki_1357_Tagging_in_Categories
251 $matching = $tree->getSubTreeFilteredByObjIds(
252 $this->parent_ref_id,
253 $all_matching_provider_object_ids,
254 $fields
255 );
256 //$matching = $this->getSubItemIds($all_matching_provider_object_ids);
257 if (sizeof($matching)) {
258 $valid_objects = array();
259
260 // :TODO: not sure if this makes sense...
261 include_once "Services/Object/classes/class.ilObjectListGUIPreloader.php";
263
264 foreach ($matching as $item) {
265 if ($item["ref_id"] != $this->parent_ref_id &&
266 !$tree->isDeleted($item["ref_id"]) &&
267 $ilAccess->checkAccess("visible", "", $item["ref_id"])) {
268 // group all valid items in blocks
269 // by their parent group/course or category
270 $block_ref_id = 0;
271 $block_title = "";
272 foreach ($tree->getPathFull($item["ref_id"]) as $p) {
273 if (in_array($p["type"], array("root", "cat", "crs", "grp"))) {
274 $block_ref_id = $p["ref_id"];
275 $block_title = $p["title"];
276 }
277 }
278 if ($block_ref_id > 0) {
279 if (!is_array($valid_objects[$block_ref_id])) {
280 $valid_objects[$block_ref_id] = array(
281 "title" => $block_title,
282 "items" => array()
283 );
284 }
285 $valid_objects[$block_ref_id]["items"][] = $item;
286 }
287
288 $preloader->addItem($item["obj_id"], $item["type"], $item["ref_id"]);
289 }
290 }
291 $valid_objects = ilUtil::sortArray($valid_objects, "title", "asc", false, true);
292 if (sizeof($valid_objects)) {
293 $has_content = true;
294
295 $preloader->preload();
296
297 $this->item_list_gui = array();
298 foreach ($valid_objects as $block) {
299 $items = ilUtil::sortArray($block["items"], "title", "asc", false, true);
300 foreach ($items as $obj) {
301 $type = $obj["type"];
302
303 // get list gui class for each object type
304 if (empty($this->item_list_gui[$type])) {
305 $class = $objDefinition->getClassName($type);
306 $location = $objDefinition->getLocation($type);
307
308 $full_class = "ilObj" . $class . "ListGUI";
309
310 include_once($location . "/class." . $full_class . ".php");
311 $this->item_list_gui[$type] = new $full_class();
312 $this->item_list_gui[$type]->enableDelete(false);
313 $this->item_list_gui[$type]->enablePath(
314 true,
315 $this->parent_ref_id,
317 );
318 $this->item_list_gui[$type]->enableLinkedPath(true);
319 $this->item_list_gui[$type]->enableCut(false);
320 $this->item_list_gui[$type]->enableCopy(false);
321 $this->item_list_gui[$type]->enableSubscribe(false);
322 $this->item_list_gui[$type]->enableLink(false);
323 $this->item_list_gui[$type]->enableIcon(true);
324
325 // :TOOD: for each item or just for each list?
326 foreach ($this->providers as $provider) {
327 $provider->initListGUI($this->item_list_gui[$type]);
328 }
329 }
330
331 $html = $this->item_list_gui[$type]->getListItemHTML(
332 $obj["ref_id"],
333 $obj["obj_id"],
334 $obj["title"],
335 $obj["description"]
336 );
337
338 if ($html != "") {
339 $ltpl->setCurrentBlock("res_row");
340 $ltpl->setVariable("RESOURCE_HTML", $html);
341 $ltpl->parseCurrentBlock();
342 }
343 }
344 $ltpl->setCurrentBlock("block");
345 $ltpl->setVariable("BLOCK_TITLE", $block["title"]);
346 $ltpl->parseCurrentBlock();
347 }
348 }
349 }
350 }
351
352 // if nothing has been selected reload to category page
353 if ($no_provider) {
354 echo "<span id='block_" . $this->getBlockType() . "_0_loader'></span>";
355 echo "<script>il.Classification.returnToParent();</script>";
356 exit();
357 }
358
359 if ($has_content) {
360 echo $ltpl->get();
361 } else {
362 //$content_block->setContent($lng->txt("clsfct_content_no_match"));
363 echo ilUtil::getSystemMessageHTML($lng->txt("clsfct_content_no_match"), "info");
364 }
365
366 exit();
367 }
368
369 protected function initProviders($a_check_post = false)
370 {
371 if (!isset(self::$providers_cache[$this->parent_ref_id])) {
372 include_once "Services/Classification/classes/class.ilClassificationProvider.php";
374 $this->parent_ref_id,
375 $this->parent_obj_id,
376 $this->parent_obj_typ
377 );
378 }
379 $this->providers = self::$providers_cache[$this->parent_ref_id];
380 if ($a_check_post && (bool) !$_REQUEST["rdrw"]) {
381 foreach ($this->providers as $provider) {
382 $id = get_class($provider);
383 $current = $provider->importPostData($this->repo->getValueForProvider($id));
384 if (is_array($current) || $current) {
385 $this->repo->setValueForProvider($id, $current);
386 } else {
387 // $this->repo->unsetValueForProvider($id);
388 }
389 }
390 }
391
392 foreach ($this->providers as $provider) {
393 $id = get_class($provider);
394 $current = $this->repo->getValueForProvider($id);
395 if ($current) {
396 $provider->setSelection($current);
397 }
398 }
399 }
400
404 protected function toggle()
405 {
406 $this->initProviders(true);
407 $this->ctrl->returnToParent($this);
408 }
409
410
411 //
412 // New rendering
413 //
414
415 protected $new_rendering = true;
416
417
418
422 protected function getLegacyContent() : string
423 {
424 return $this->fillDataSection();
425 }
426
434 protected function getSubItemIds($obj_ids)
435 {
437 if (ilObject::_lookupType($this->parent_ref_id, true) == "cat") {
438 $matching = array_filter($tree->getChilds($this->parent_ref_id), function ($item) use ($obj_ids) {
439 return in_array($item["obj_id"], $obj_ids);
440 });
441 } else {
442 $fields = array(
443 "object_reference.ref_id"
444 ,"object_data.obj_id"
445 ,"object_data.type"
446 ,"object_data.title"
447 ,"object_data.description"
448 );
449 $matching = $tree->getSubTreeFilteredByObjIds($this->parent_ref_id, $obj_ids, $fields);
450 }
451
452 return $matching;
453 }
454}
$location
Definition: buildRTE.php:44
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
const IL_SCREEN_CENTER
This class represents a block method of a block.
setTitle($a_title)
Set Title.
Classification block, displayed in different contexts, e.g.
static getScreenMode()
Get Screen Mode for current command.
getSubItemIds($obj_ids)
Get sub item ids depending on container type that match the preselected object ids.
getLegacyContent()
Get legacy content.string
isRepositoryObject()
Returns whether block has a corresponding repository object.bool
fillDataSection()
Standard implementation for row based data.
static getValidProviders($a_parent_ref_id, $a_parent_obj_id, $a_parent_obj_type)
Get all valid providers (for parent container)
Preloader for object list GUIs.
static _lookupObjId($a_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
PathGUI which handles materials assigned to sessions.
Tabs GUI.
special template class to simplify handling of ITX/PEAR
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static getSystemMessageHTML($a_txt, $a_type="info")
Get HTML for a system message.
global $DIC
Definition: goto.php:24
exit
Definition: login.php:29
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type