ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 {
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 {
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
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($this->parent_ref_id, $all_matching_provider_object_ids,
252 $fields);
253 //$matching = $this->getSubItemIds($all_matching_provider_object_ids);
254 if (sizeof($matching)) {
255 $valid_objects = array();
256
257 // :TODO: not sure if this makes sense...
258 include_once "Services/Object/classes/class.ilObjectListGUIPreloader.php";
260
261 foreach ($matching as $item) {
262 if ($item["ref_id"] != $this->parent_ref_id &&
263 !$tree->isDeleted($item["ref_id"]) &&
264 $ilAccess->checkAccess("visible", "", $item["ref_id"])) {
265 // group all valid items in blocks
266 // by their parent group/course or category
267 $block_ref_id = 0;
268 $block_title = "";
269 foreach ($tree->getPathFull($item["ref_id"]) as $p) {
270 if (in_array($p["type"], array("root", "cat", "crs", "grp"))) {
271 $block_ref_id = $p["ref_id"];
272 $block_title = $p["title"];
273 }
274 }
275 if ($block_ref_id > 0) {
276 if (!is_array($valid_objects[$block_ref_id])) {
277 $valid_objects[$block_ref_id] = array(
278 "title" => $block_title,
279 "items" => array()
280 );
281 }
282 $valid_objects[$block_ref_id]["items"][] = $item;
283 }
284
285 $preloader->addItem($item["obj_id"], $item["type"], $item["ref_id"]);
286 }
287 }
288 $valid_objects = ilUtil::sortArray($valid_objects, "title", "asc", false, true);
289 if (sizeof($valid_objects)) {
290 $has_content = true;
291
292 $preloader->preload();
293
294 $this->item_list_gui = array();
295 foreach ($valid_objects as $block) {
296 $items = ilUtil::sortArray($block["items"], "title", "asc", false, true);
297 foreach ($items as $obj) {
298 $type = $obj["type"];
299
300 // get list gui class for each object type
301 if (empty($this->item_list_gui[$type])) {
302 $class = $objDefinition->getClassName($type);
303 $location = $objDefinition->getLocation($type);
304
305 $full_class = "ilObj" . $class . "ListGUI";
306
307 include_once($location . "/class." . $full_class . ".php");
308 $this->item_list_gui[$type] = new $full_class();
309 $this->item_list_gui[$type]->enableDelete(false);
310 $this->item_list_gui[$type]->enablePath(
311 true,
312 $this->parent_ref_id,
314 );
315 $this->item_list_gui[$type]->enableLinkedPath(true);
316 $this->item_list_gui[$type]->enableCut(false);
317 $this->item_list_gui[$type]->enableCopy(false);
318 $this->item_list_gui[$type]->enableSubscribe(false);
319 $this->item_list_gui[$type]->enableLink(false);
320 $this->item_list_gui[$type]->enableIcon(true);
321
322 // :TOOD: for each item or just for each list?
323 foreach ($this->providers as $provider) {
324 $provider->initListGUI($this->item_list_gui[$type]);
325 }
326 }
327
328 $html = $this->item_list_gui[$type]->getListItemHTML(
329 $obj["ref_id"],
330 $obj["obj_id"],
331 $obj["title"],
332 $obj["description"]
333 );
334
335 if ($html != "") {
336 $ltpl->setCurrentBlock("res_row");
337 $ltpl->setVariable("RESOURCE_HTML", $html);
338 $ltpl->parseCurrentBlock();
339 }
340 }
341 $ltpl->setCurrentBlock("block");
342 $ltpl->setVariable("BLOCK_TITLE", $block["title"]);
343 $ltpl->parseCurrentBlock();
344 }
345 }
346 }
347 }
348
349 // if nothing has been selected reload to category page
350 if ($no_provider) {
351 echo "<span id='block_" . $this->getBlockType() . "_0_loader'></span>";
352 echo "<script>il.Classification.returnToParent();</script>";
353 exit();
354 }
355
356 if ($has_content) {
357 echo $ltpl->get();
358 } else {
359 //$content_block->setContent($lng->txt("clsfct_content_no_match"));
360 echo ilUtil::getSystemMessageHTML($lng->txt("clsfct_content_no_match"), "info");
361 }
362
363 exit();
364 }
365
366 protected function initProviders($a_check_post = false)
367 {
368 if (!isset(self::$providers_cache[$this->parent_ref_id])) {
369 include_once "Services/Classification/classes/class.ilClassificationProvider.php";
371 $this->parent_ref_id,
372 $this->parent_obj_id,
373 $this->parent_obj_typ
374 );
375 }
376 $this->providers = self::$providers_cache[$this->parent_ref_id];
377 if ($a_check_post && (bool) !$_REQUEST["rdrw"]) {
378 foreach ($this->providers as $provider) {
379 $id = get_class($provider);
380 $current = $provider->importPostData($this->repo->getValueForProvider($id));
381 if (is_array($current) || $current) {
382 $this->repo->setValueForProvider($id, $current);
383 } else {
384 // $this->repo->unsetValueForProvider($id);
385 }
386 }
387 }
388
389 foreach ($this->providers as $provider) {
390 $id = get_class($provider);
391 $current = $this->repo->getValueForProvider($id);
392 if ($current) {
393 $provider->setSelection($current);
394 }
395 }
396 }
397
401 protected function toggle()
402 {
403 $this->initProviders(true);
404 $this->ctrl->returnToParent($this);
405 }
406
407
408 //
409 // New rendering
410 //
411
412 protected $new_rendering = true;
413
414
415
419 protected function getLegacyContent() : string
420 {
421 return $this->fillDataSection();
422 }
423
431 protected function getSubItemIds($obj_ids)
432 {
434 if (ilObject::_lookupType($this->parent_ref_id, true) == "cat") {
435 $matching = array_filter($tree->getChilds($this->parent_ref_id), function ($item) use ($obj_ids) {
436 return in_array($item["obj_id"], $obj_ids);
437 });
438 } else {
439 $fields = array(
440 "object_reference.ref_id"
441 ,"object_data.obj_id"
442 ,"object_data.type"
443 ,"object_data.title"
444 ,"object_data.description"
445 );
446 $matching = $tree->getSubTreeFilteredByObjIds($this->parent_ref_id, $obj_ids, $fields);
447 }
448
449 return $matching;
450 }
451}
$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 $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:29
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type
$DIC
Definition: xapitoken.php:46