ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilClassificationBlockGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
27 {
28  protected \ILIAS\Container\Classification\ClassificationManager $classification;
31  protected ilTree $tree;
32  protected string $parent_obj_type;
33  protected int $parent_obj_id;
34  protected int $parent_ref_id;
35  protected array $providers;
36  protected array $item_list_gui;
37  protected static array $providers_cache;
38 
39  public function __construct()
40  {
41  global $DIC;
42 
43  $service = $DIC->container()->internal();
44 
45  $domain = $service->domain();
46  $gui = $service->gui();
47 
48  $this->lng = $domain->lng();
49  $this->obj_definition = $domain->objectDefinition();
50  $this->tree = $domain->repositoryTree();
51  $this->access = $domain->access();
52 
53  $this->ctrl = $gui->ctrl();
54 
56 
57  $this->parent_ref_id = $this->requested_ref_id;
58  $this->parent_obj_id = ilObject::_lookupObjId($this->parent_ref_id);
59  $this->parent_obj_type = ilObject::_lookupType($this->parent_obj_id);
60 
61  $this->lng->loadLanguageModule("classification");
62  $this->setTitle($this->lng->txt("clsfct_block_title"));
63 
64  $this->cl_request = $gui->classification()->standardRequest();
65 
66  $this->classification = $domain->classification($this->parent_ref_id);
67  }
68 
69  public function getBlockType(): string
70  {
71  return 'clsfct';
72  }
73 
74  protected function isRepositoryObject(): bool
75  {
76  return false;
77  }
78 
79  public function executeCommand(): void
80  {
81  $ilCtrl = $this->ctrl;
82 
83  $cmd = $ilCtrl->getCmd();
84  $next_class = $ilCtrl->getNextClass($this);
85 
86  switch ($next_class) {
87  default:
88  // explorer call
89  if ($ilCtrl->isAsynch() && $cmd != "getAjax" && $cmd != "filterContainer") {
90  $this->getHTML();
91  } else {
92  $this->$cmd();
93  }
94  break;
95  }
96  }
97 
98  public static function getScreenMode(): string
99  {
100  global $DIC;
101 
102  $ilCtrl = $DIC->ctrl();
103 
104  if ($ilCtrl->isAsynch()) {
105  return "";
106  }
107 
108  switch ($ilCtrl->getCmd()) {
109  case "filterContainer":
110  return IL_SCREEN_CENTER;
111  }
112  return "";
113  }
114 
115  public function getHTML(): string
116  {
118  $ilCtrl = $this->ctrl;
119 
120  if (!$ilCtrl->isAsynch()) {
121  // $this->repo->unsetAll();
122  }
123 
124  $this->initProviders();
125 
126  if (!$this->validate()) {
127  return "";
128  }
129 
130  $tpl->addJavaScript("Services/Container/Classification/js/ilClassification.js");
131 
132  return parent::getHTML();
133  }
134 
135  public function getAjax(): void
136  {
138 
139  $this->initProviders(true);
140 
141  echo $this->getHTML();
142  echo $tpl->getOnLoadCodeForAsynch();
143 
144  exit();
145  }
146 
147  protected function getLegacyContent(): string
148  {
150 
151  $ilCtrl = $this->ctrl;
152 
153  $html = array();
154  foreach ($this->providers as $provider) {
155  $provider->render($html, $this);
156  }
157 
158  // $this->tpl->setVariable("BLOCK_ROW", "");
159 
160  $ajax_block_id = "block_" . $this->getBlockType() . "_0";
161  $ajax_block_url = $ilCtrl->getLinkTarget($this, "getAjax", "", true, false);
162  $ajax_content_id = "il_center_col";
163  $ajax_content_url = $ilCtrl->getLinkTarget($this, "filterContainer", "", true, false);
164 
165  $tabs = new ilTabsGUI();
166  $tabs->setBackTarget($this->lng->txt("clsfct_back_to_cat"), $ilCtrl->getLinkTarget($this, "returnToParent"));
167  $tabs->addTab("sel_objects", $this->lng->txt("clsfct_selected_objects"), "#");
168  $tabs_html = $tabs->getHTML();
169 
170 
171  // #15008 - always load regardless of content (because of redraw)
172  $tpl->addOnLoadCode('il.Classification.setAjax("' . $ajax_block_id . '", "' .
173  $ajax_block_url . '", "' . $ajax_content_id . '", "' . $ajax_content_url . '", ' . json_encode($tabs_html) . ');');
174 
175  $overall_html = "";
176  if (sizeof($html)) {
177  $btpl = new ilTemplate("tpl.classification_block.html", true, true, "Services/Container/Classification");
178 
179  foreach ($html as $item) {
180  $btpl->setCurrentBlock("provider_chunk_bl");
181  $btpl->setVariable("TITLE", $item["title"]);
182  $btpl->setVariable("CHUNK", $item["html"]);
183  $btpl->parseCurrentBlock();
184  }
185 
186  $overall_html .= $btpl->get();
187  //$this->tpl->setVariable("DATA", $btpl->get());
188  }
189  return $overall_html;
190  }
191 
192  protected function returnToParent(): void
193  {
194  $this->classification->clearSelection();
195  $this->ctrl->returnToParent($this);
196  }
197 
198  protected function validate(): bool
199  {
200  return sizeof($this->providers);
201  }
202 
203  protected function filterContainer(): void
204  {
205  $objDefinition = $this->obj_definition;
206  $lng = $this->lng;
207  $tree = $this->tree;
208  $ilAccess = $this->access;
210 
211  $this->initProviders();
212 
213  // empty selection is invalid
214  if ($this->classification->isEmptySelection()) {
215  exit();
216  }
217 
218  $all_matching_provider_object_ids = null;
219  $no_provider = true;
220  foreach ($this->providers as $provider) {
221  $id = get_class($provider);
222  $current = $this->classification->getSelectionOfProvider($id);
223  if ($current) {
224  $no_provider = false;
225  // combine providers AND
226  $provider_object_ids = $provider->getFilteredObjects();
227  if (isset($all_matching_provider_object_ids)) {
228  $all_matching_provider_object_ids = array_intersect($all_matching_provider_object_ids, $provider_object_ids);
229  } else {
230  $all_matching_provider_object_ids = $provider_object_ids;
231  }
232  }
233  }
234  $has_content = false;
235 
236 
237  $ltpl = new ilTemplate("tpl.classification_object_list.html", true, true, "Services/Container/Classification");
238 
239  if (isset($all_matching_provider_object_ids) && sizeof($all_matching_provider_object_ids)) {
240  $fields = array(
241  "object_reference.ref_id"
242  ,"object_data.obj_id"
243  ,"object_data.type"
244  ,"object_data.title"
245  ,"object_data.description"
246  );
247  // see #28883 (tags + filter still work on current level only)
248  // see also JF comment on https://docu.ilias.de/goto.php?target=wiki_1357_Tagging_in_Categories
249  $matching = $tree->getSubTreeFilteredByObjIds(
250  $this->parent_ref_id,
251  $all_matching_provider_object_ids,
252  $fields
253  );
254  //$matching = $this->getSubItemIds($all_matching_provider_object_ids);
255  if (sizeof($matching)) {
256  $valid_objects = array();
257 
259 
260  foreach ($matching as $item) {
261  if ($item["ref_id"] != $this->parent_ref_id &&
262  !$tree->isDeleted($item["ref_id"]) &&
263  $ilAccess->checkAccess("visible", "", $item["ref_id"])) {
264  // group all valid items in blocks
265  // by their parent group/course or category
266  $block_ref_id = 0;
267  $block_title = "";
268  foreach ($tree->getPathFull($item["ref_id"]) as $p) {
269  if (in_array($p["type"], array("root", "cat", "crs", "grp"))) {
270  $block_ref_id = $p["ref_id"];
271  $block_title = $p["title"];
272  }
273  }
274  if ($block_ref_id > 0) {
275  if (!isset($valid_objects[$block_ref_id])) {
276  $valid_objects[$block_ref_id] = array(
277  "title" => $block_title,
278  "items" => array()
279  );
280  }
281  $valid_objects[$block_ref_id]["items"][] = $item;
282  }
283 
284  $preloader->addItem($item["obj_id"], $item["type"], $item["ref_id"]);
285  }
286  }
287  $valid_objects = ilArrayUtil::sortArray($valid_objects, "title", "asc", false, true);
288  if (sizeof($valid_objects)) {
289  $has_content = true;
290 
291  $preloader->preload();
292 
293  $this->item_list_gui = array();
294  foreach ($valid_objects as $block) {
295  $items = ilArrayUtil::sortArray($block["items"], "title", "asc", false, true);
296  foreach ($items as $obj) {
297  $type = $obj["type"];
298 
299  // get list gui class for each object type
300  if (empty($this->item_list_gui[$type])) {
301  $class = $objDefinition->getClassName($type);
302  $location = $objDefinition->getLocation($type);
303 
304  $full_class = "ilObj" . $class . "ListGUI";
305 
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])) {
368  $this->parent_ref_id,
369  $this->parent_obj_id,
370  $this->parent_obj_type
371  );
372  }
373  $this->providers = self::$providers_cache[$this->parent_ref_id];
374  if ($a_check_post && !$this->cl_request->getRedraw()) {
375  foreach ($this->providers as $provider) {
376  $id = get_class($provider);
377  $current = $provider->importPostData(
378  $this->classification->getSelectionOfProvider($id)
379  );
380  if (is_array($current) || $current) {
381  $this->classification->setSelectionOfProvider($id, $current);
382  }
383  }
384  }
385 
386  foreach ($this->providers as $provider) {
387  $id = get_class($provider);
388  $current = $this->classification->getSelectionOfProvider($id);
389  if ($current) {
390  $provider->setSelection($current);
391  }
392  }
393  }
394 
395  protected function toggle(): void
396  {
397  $this->initProviders(true);
398  $this->ctrl->returnToParent($this);
399  }
400 
406  protected function getSubItemIds(array $obj_ids): array
407  {
408  $tree = $this->tree;
409  if (ilObject::_lookupType($this->parent_ref_id, true) == "cat") {
410  $matching = array_filter($tree->getChilds($this->parent_ref_id), function ($item) use ($obj_ids) {
411  return in_array($item["obj_id"], $obj_ids);
412  });
413  } else {
414  $fields = array(
415  "object_reference.ref_id"
416  ,"object_data.obj_id"
417  ,"object_data.type"
418  ,"object_data.title"
419  ,"object_data.description"
420  );
421  $matching = $tree->getSubTreeFilteredByObjIds($this->parent_ref_id, $obj_ids, $fields);
422  }
423 
424  return $matching;
425  }
426 }
getSubItemIds(array $obj_ids)
Get sub item ids depending on container type that match the preselected object ids.
ILIAS Container Classification ClassificationManager $classification
exit
Definition: login.php:29
static getSystemMessageHTML(string $a_txt, string $a_type="info")
Get HTML for a system message.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
ilLanguage $lng
getCmd(string $fallback_command=null)
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
getChilds(int $a_node_id, string $a_order="", string $a_direction="ASC")
get child nodes of given node
isDeleted(int $a_node_id)
This is a wrapper for isSaved() with a more useful name.
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...
static _lookupObjId(int $ref_id)
Classification block, displayed in different contexts, e.g.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$provider
Definition: ltitoken.php:83
parses the objects.xml it handles the xml-description of all ilias objects
ilGlobalTemplateInterface $main_tpl
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
__construct(VocabulariesInterface $vocabularies)
ilTemplate $tpl
const IL_SCREEN_CENTER
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initProviders(bool $a_check_post=false)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setTitle(string $a_title)
This class represents a block method of a block.
ilAccessHandler $access
static _lookupType(int $id, bool $reference=false)
static getValidProviders(int $a_parent_ref_id, int $a_parent_obj_id, string $a_parent_obj_type)
Get all valid providers (for parent container)
$service
Definition: ltiservices.php:43
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)