ILIAS  release_8 Revision v8.24
class.ilClassificationBlockGUI.php
Go to the documentation of this file.
1<?php
2
17
24{
27 protected ilTree $tree;
28 protected string $parent_obj_type;
29 protected int $parent_obj_id;
30 protected int $parent_ref_id;
31 protected array $providers;
32 protected array $item_list_gui;
33 protected static array $providers_cache;
35
36 public function __construct()
37 {
38 global $DIC;
39
40 $this->lng = $DIC->language();
41 $this->ctrl = $DIC->ctrl();
42 $this->obj_definition = $DIC["objDefinition"];
43 $this->tree = $DIC->repositoryTree();
44 $this->access = $DIC->access();
45 $lng = $DIC->language();
46
48
49 $this->parent_ref_id = $this->requested_ref_id;
50 $this->parent_obj_id = ilObject::_lookupObjId($this->parent_ref_id);
51 $this->parent_obj_type = ilObject::_lookupType($this->parent_obj_id);
52
53 $lng->loadLanguageModule("classification");
54 $this->setTitle($lng->txt("clsfct_block_title"));
55 // @todo: find another solution for this
56 //$this->setFooterInfo($lng->txt("clsfct_block_info"));
57
58 $this->cl_request = new StandardGUIRequest(
59 $DIC->http(),
60 $DIC->refinery()
61 );
62
63 $this->repo = new ilClassificationSessionRepository($this->parent_ref_id);
64 }
65
66 public function getBlockType(): string
67 {
68 return 'clsfct';
69 }
70
71 protected function isRepositoryObject(): bool
72 {
73 return false;
74 }
75
76 public function executeCommand(): void
77 {
78 $ilCtrl = $this->ctrl;
79
80 $cmd = $ilCtrl->getCmd();
81 $next_class = $ilCtrl->getNextClass($this);
82
83 switch ($next_class) {
84 default:
85 // explorer call
86 if ($ilCtrl->isAsynch() && $cmd != "getAjax" && $cmd != "filterContainer") {
87 $this->getHTML();
88 } else {
89 $this->$cmd();
90 }
91 break;
92 }
93 }
94
95 public static function getScreenMode(): string
96 {
97 global $DIC;
98
99 $ilCtrl = $DIC->ctrl();
100
101 if ($ilCtrl->isAsynch()) {
102 return "";
103 }
104
105 switch ($ilCtrl->getCmd()) {
106 case "filterContainer":
107 return IL_SCREEN_CENTER;
108 }
109 return "";
110 }
111
112 public function getHTML(): string
113 {
115 $ilCtrl = $this->ctrl;
116
117 if (!$ilCtrl->isAsynch()) {
118// $this->repo->unsetAll();
119 }
120
121 $this->initProviders();
122
123 if (!$this->validate()) {
124 return "";
125 }
126
127 $tpl->addJavaScript("Services/Classification/js/ilClassification.js");
128
129 return parent::getHTML();
130 }
131
132 public function getAjax(): void
133 {
135
136 $this->initProviders(true);
137
138 echo $this->getHTML();
139 echo $tpl->getOnLoadCodeForAsynch();
140
141 exit();
142 }
143
144 protected function getLegacyContent(): string
145 {
147
148 $ilCtrl = $this->ctrl;
149
150 $html = array();
151 foreach ($this->providers as $provider) {
152 $provider->render($html, $this);
153 }
154
155 // $this->tpl->setVariable("BLOCK_ROW", "");
156
157 $ajax_block_id = "block_" . $this->getBlockType() . "_0";
158 $ajax_block_url = $ilCtrl->getLinkTarget($this, "getAjax", "", true, false);
159 $ajax_content_id = "il_center_col";
160 $ajax_content_url = $ilCtrl->getLinkTarget($this, "filterContainer", "", true, false);
161
162 $tabs = new ilTabsGUI();
163 $tabs->setBackTarget($this->lng->txt("clsfct_back_to_cat"), $ilCtrl->getLinkTarget($this, "returnToParent"));
164 $tabs->addTab("sel_objects", $this->lng->txt("clsfct_selected_objects"), "#");
165 $tabs_html = $tabs->getHTML();
166
167
168 // #15008 - always load regardless of content (because of redraw)
169 $tpl->addOnLoadCode('il.Classification.setAjax("' . $ajax_block_id . '", "' .
170 $ajax_block_url . '", "' . $ajax_content_id . '", "' . $ajax_content_url . '", ' . json_encode($tabs_html) . ');');
171
172 $overall_html = "";
173 if (sizeof($html)) {
174 $btpl = new ilTemplate("tpl.classification_block.html", true, true, "Services/Classification");
175
176 foreach ($html as $item) {
177 $btpl->setCurrentBlock("provider_chunk_bl");
178 $btpl->setVariable("TITLE", $item["title"]);
179 $btpl->setVariable("CHUNK", $item["html"]);
180 $btpl->parseCurrentBlock();
181 }
182
183 $overall_html .= $btpl->get();
184 //$this->tpl->setVariable("DATA", $btpl->get());
185 }
186 return $overall_html;
187 }
188
189 protected function returnToParent(): void
190 {
191 $this->repo->unsetAll(); // this resets, e.g. the taxonomy selection before showing the parent container
192 $this->ctrl->returnToParent($this);
193 }
194
195 protected function validate(): bool
196 {
197 return sizeof($this->providers);
198 }
199
200 protected function filterContainer(): void
201 {
202 $objDefinition = $this->obj_definition;
205 $ilAccess = $this->access;
207
208 $this->initProviders();
209
210 // empty selection is invalid
211 if ($this->repo->isEmpty()) {
212 exit();
213 }
214
215 $all_matching_provider_object_ids = null;
216 $no_provider = true;
217 foreach ($this->providers as $provider) {
218 $id = get_class($provider);
219 $current = $this->repo->getValueForProvider($id);
220 if ($current) {
221 $no_provider = false;
222 // combine providers AND
223 $provider_object_ids = $provider->getFilteredObjects();
224 if (isset($all_matching_provider_object_ids)) {
225 $all_matching_provider_object_ids = array_intersect($all_matching_provider_object_ids, $provider_object_ids);
226 } else {
227 $all_matching_provider_object_ids = $provider_object_ids;
228 }
229 }
230 }
231 $has_content = false;
232
233
234 $ltpl = new ilTemplate("tpl.classification_object_list.html", true, true, "Services/Classification");
235
236 if (isset($all_matching_provider_object_ids) && sizeof($all_matching_provider_object_ids)) {
237 $fields = array(
238 "object_reference.ref_id"
239 ,"object_data.obj_id"
240 ,"object_data.type"
241 ,"object_data.title"
242 ,"object_data.description"
243 );
244 // see #28883 (tags + filter still work on current level only)
245 // see also JF comment on https://docu.ilias.de/goto.php?target=wiki_1357_Tagging_in_Categories
247 $this->parent_ref_id,
248 $all_matching_provider_object_ids,
249 $fields
250 );
251 //$matching = $this->getSubItemIds($all_matching_provider_object_ids);
252 if (sizeof($matching)) {
253 $valid_objects = array();
254
255 // :TODO: not sure if this makes sense...
256 include_once "Services/Object/classes/class.ilObjectListGUIPreloader.php";
258
259 foreach ($matching as $item) {
260 if ($item["ref_id"] != $this->parent_ref_id &&
261 !$tree->isDeleted($item["ref_id"]) &&
262 $ilAccess->checkAccess("visible", "", $item["ref_id"])) {
263 // group all valid items in blocks
264 // by their parent group/course or category
265 $block_ref_id = 0;
266 $block_title = "";
267 foreach ($tree->getPathFull($item["ref_id"]) as $p) {
268 if (in_array($p["type"], array("root", "cat", "crs", "grp"))) {
269 $block_ref_id = $p["ref_id"];
270 $block_title = $p["title"];
271 }
272 }
273 if ($block_ref_id > 0) {
274 if (!isset($valid_objects[$block_ref_id])) {
275 $valid_objects[$block_ref_id] = array(
276 "title" => $block_title,
277 "items" => array()
278 );
279 }
280 $valid_objects[$block_ref_id]["items"][] = $item;
281 }
282
283 $preloader->addItem($item["obj_id"], $item["type"], $item["ref_id"]);
284 }
285 }
286 $valid_objects = ilArrayUtil::sortArray($valid_objects, "title", "asc", false, true);
287 if (sizeof($valid_objects)) {
288 $has_content = true;
289
290 $preloader->preload();
291
292 $this->item_list_gui = array();
293 foreach ($valid_objects as $block) {
294 $items = ilArrayUtil::sortArray($block["items"], "title", "asc", false, true);
295 foreach ($items as $obj) {
296 $type = $obj["type"];
297
298 // get list gui class for each object type
299 if (empty($this->item_list_gui[$type])) {
300 $class = $objDefinition->getClassName($type);
301 $location = $objDefinition->getLocation($type);
302
303 $full_class = "ilObj" . $class . "ListGUI";
304
305 include_once($location . "/class." . $full_class . ".php");
306 $this->item_list_gui[$type] = new $full_class();
307 $this->item_list_gui[$type]->enableDelete(false);
308 $this->item_list_gui[$type]->enablePath(
309 true,
310 $this->parent_ref_id,
312 );
313 $this->item_list_gui[$type]->enableLinkedPath(true);
314 $this->item_list_gui[$type]->enableCut(false);
315 $this->item_list_gui[$type]->enableCopy(false);
316 $this->item_list_gui[$type]->enableSubscribe(false);
317 $this->item_list_gui[$type]->enableLink(false);
318 $this->item_list_gui[$type]->enableIcon(true);
319
320 // :TOOD: for each item or just for each list?
321 foreach ($this->providers as $provider) {
322 $provider->initListGUI($this->item_list_gui[$type]);
323 }
324 }
325
326 $html = $this->item_list_gui[$type]->getListItemHTML(
327 $obj["ref_id"],
328 $obj["obj_id"],
329 $obj["title"],
330 $obj["description"]
331 );
332
333 if ($html != "") {
334 $ltpl->setCurrentBlock("res_row");
335 $ltpl->setVariable("RESOURCE_HTML", $html);
336 $ltpl->parseCurrentBlock();
337 }
338 }
339 $ltpl->setCurrentBlock("block");
340 $ltpl->setVariable("BLOCK_TITLE", $block["title"]);
341 $ltpl->parseCurrentBlock();
342 }
343 }
344 }
345 }
346
347 // if nothing has been selected reload to category page
348 if ($no_provider) {
349 echo "<span id='block_" . $this->getBlockType() . "_0_loader'></span>";
350 echo "<script>il.Classification.returnToParent();</script>";
351 exit();
352 }
353
354 if ($has_content) {
355 echo $ltpl->get();
356 } else {
357 //$content_block->setContent($lng->txt("clsfct_content_no_match"));
358 echo ilUtil::getSystemMessageHTML($lng->txt("clsfct_content_no_match"), "info");
359 }
360
361 exit();
362 }
363
364 protected function initProviders(bool $a_check_post = false): void
365 {
366 if (!isset(self::$providers_cache[$this->parent_ref_id])) {
367 include_once "Services/Classification/classes/class.ilClassificationProvider.php";
369 $this->parent_ref_id,
370 $this->parent_obj_id,
371 $this->parent_obj_type
372 );
373 }
374 $this->providers = self::$providers_cache[$this->parent_ref_id];
375 if ($a_check_post && !$this->cl_request->getRedraw()) {
376 foreach ($this->providers as $provider) {
377 $id = get_class($provider);
378 $current = $provider->importPostData($this->repo->getValueForProvider($id));
379 if (is_array($current) || $current) {
380 $this->repo->setValueForProvider($id, $current);
381 }
382 }
383 }
384
385 foreach ($this->providers as $provider) {
386 $id = get_class($provider);
387 $current = $this->repo->getValueForProvider($id);
388 if ($current) {
389 $provider->setSelection($current);
390 }
391 }
392 }
393
394 protected function toggle(): void
395 {
396 $this->initProviders(true);
397 $this->ctrl->returnToParent($this);
398 }
399
400
401 //
402 // New rendering
403 //
404
405 protected bool $new_rendering = true;
406
412 protected function getSubItemIds(array $obj_ids): array
413 {
415 if (ilObject::_lookupType($this->parent_ref_id, true) == "cat") {
416 $matching = array_filter($tree->getChilds($this->parent_ref_id), function ($item) use ($obj_ids) {
417 return in_array($item["obj_id"], $obj_ids);
418 });
419 } else {
420 $fields = array(
421 "object_reference.ref_id"
422 ,"object_data.obj_id"
423 ,"object_data.type"
424 ,"object_data.title"
425 ,"object_data.description"
426 );
427 $matching = $tree->getSubTreeFilteredByObjIds($this->parent_ref_id, $obj_ids, $fields);
428 }
429
430 return $matching;
431 }
432}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
const IL_SCREEN_CENTER
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
This class represents a block method of a block.
ilAccessHandler $access
ilLanguage $lng
setTitle(string $a_title)
ilTemplate $tpl
ilGlobalTemplateInterface $main_tpl
Classification block, displayed in different contexts, e.g.
ilClassificationSessionRepository $repo
isRepositoryObject()
Returns whether block has a corresponding repository object.
initProviders(bool $a_check_post=false)
getSubItemIds(array $obj_ids)
Get sub item ids depending on container type that match the preselected object ids.
static getValidProviders(int $a_parent_ref_id, int $a_parent_obj_id, string $a_parent_obj_type)
Get all valid providers (for parent container)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getCmd(string $fallback_command=null)
@inheritDoc
loadLanguageModule(string $a_module)
Load language module.
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...
parses the objects.xml it handles the xml-description of all ilias objects
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getPathFull(int $a_endnode_id, int $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...
isDeleted(int $a_node_id)
This is a wrapper for isSaved() with a more useful name.
getChilds(int $a_node_id, string $a_order="", string $a_direction="ASC")
get child nodes of given node
getSubTreeFilteredByObjIds(int $a_node_id, array $a_obj_ids, array $a_fields=[])
get all node ids in the subtree under specified node id, filter by object ids
static getSystemMessageHTML(string $a_txt, string $a_type="info")
Get HTML for a system message.
global $DIC
Definition: feed.php:28
exit
Definition: login.php:28
$provider
Definition: ltitoken.php:83
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type