ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 include_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 
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 
47  parent::__construct();
48 
49  $this->parent_ref_id = (int) $_GET["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  $this->setFooterInfo($lng->txt("clsfct_block_info"));
56  }
57 
61  public function getBlockType() : string
62  {
63  return 'clsfct';
64  }
65 
69  protected function isRepositoryObject() : bool
70  {
71  return false;
72  }
73 
74  public function executeCommand()
75  {
77 
78  $cmd = $ilCtrl->getCmd();
79  $next_class = $ilCtrl->getNextClass($this);
80 
81  switch ($next_class) {
82  default:
83  // explorer call
84  if ($ilCtrl->isAsynch() && $cmd != "getAjax" && $cmd != "filterContainer") {
85  $this->getHTML();
86  } else {
87  $this->$cmd();
88  }
89  break;
90  }
91  }
92 
93  public static function getScreenMode()
94  {
95  global $DIC;
96 
97  $ilCtrl = $DIC->ctrl();
98 
99  if ($ilCtrl->isAsynch()) {
100  return;
101  }
102 
103  switch ($ilCtrl->getCmd()) {
104  case "filterContainer":
105  return IL_SCREEN_CENTER;
106  }
107  }
108 
109  public function getHTML()
110  {
113 
114  if (!$ilCtrl->isAsynch()) {
115  unset($_SESSION[self::getBlockType()]);
116  }
117 
118  $this->initProviders();
119 
120  if (!$this->validate()) {
121  return "";
122  }
123 
124  $tpl->addJavaScript("Services/Classification/js/ilClassification.js");
125 
126  return parent::getHTML();
127  }
128 
129  public function getAjax()
130  {
132 
133  $this->initProviders(true);
134 
135  echo $this->getHTML();
136  echo $tpl->getOnLoadCodeForAsynch();
137 
138  exit();
139  }
140 
141  public function fillDataSection()
142  {
144 
146 
147  $html = array();
148  foreach ($this->providers as $provider) {
149  $provider->render($html, $this);
150  }
151 
152  $this->tpl->setVariable("BLOCK_ROW", "");
153 
154  $ajax_block_id = "block_" . $this->getBlockType() . "_0";
155  $ajax_block_url = $ilCtrl->getLinkTarget($this, "getAjax", "", true, false);
156  $ajax_content_id = "il_center_col";
157  $ajax_content_url = $ilCtrl->getLinkTarget($this, "filterContainer", "", true, false);
158 
159  $tabs = new ilTabsGUI();
160  $tabs->setBackTarget($this->lng->txt("clsfct_back_to_cat"), $ilCtrl->getParentReturn($this));
161  $tabs->addTab("sel_objects", $this->lng->txt("clsfct_selected_objects"), "#");
162  $tabs_html = $tabs->getHTML();
163 
164 
165  // #15008 - always load regardless of content (because of redraw)
166  $tpl->addOnLoadCode('il.Classification.setAjax("' . $ajax_block_id . '", "' .
167  $ajax_block_url . '", "' . $ajax_content_id . '", "' . $ajax_content_url . '", ' . json_encode($tabs_html) . ');');
168 
169  if (sizeof($html)) {
170  $btpl = new ilTemplate("tpl.classification_block.html", true, true, "Services/Classification");
171 
172  foreach ($html as $item) {
173  $btpl->setCurrentBlock("provider_chunk_bl");
174  $btpl->setVariable("TITLE", $item["title"]);
175  $btpl->setVariable("CHUNK", $item["html"]);
176  $btpl->parseCurrentBlock();
177  }
178 
179  $this->tpl->setVariable("DATA", $btpl->get());
180  }
181  }
182 
183  protected function validate()
184  {
185  return sizeof($this->providers);
186  }
187 
188  protected function filterContainer()
189  {
190  $objDefinition = $this->obj_definition;
191  $lng = $this->lng;
192  $tree = $this->tree;
193  $ilAccess = $this->access;
195 
196  $this->initProviders();
197 
198  // empty selection is invalid
199  if (!$_SESSION[self::getBlockType()]) {
200  exit();
201  }
202 
203  $all_matching_provider_object_ids = null;
204 
205  foreach ($this->providers as $provider) {
206  $id = get_class($provider);
207  $current = $_SESSION[self::getBlockType()][$id];
208  if ($current) {
209  // combine providers AND
210  $provider_object_ids = $provider->getFilteredObjects();
211  if (is_array($all_matching_provider_object_ids)) {
212  $all_matching_provider_object_ids = array_intersect($matching_provider_object_ids, $provider_object_ids);
213  } else {
214  $all_matching_provider_object_ids = $provider_object_ids;
215  }
216  }
217  }
218 
219  $has_content = false;
220 
221  $ltpl = new ilTemplate("tpl.classification_object_list.html", true, true, "Services/Classification");
222 
223  if (sizeof($all_matching_provider_object_ids)) {
224  $fields = array(
225  "object_reference.ref_id"
226  ,"object_data.obj_id"
227  ,"object_data.type"
228  ,"object_data.title"
229  ,"object_data.description"
230  );
231  $matching = $tree->getSubTreeFilteredByObjIds($this->parent_ref_id, $all_matching_provider_object_ids, $fields);
232  if (sizeof($matching)) {
233  $valid_objects = array();
234 
235  // :TODO: not sure if this makes sense...
236  include_once "Services/Object/classes/class.ilObjectListGUIPreloader.php";
238 
239  foreach ($matching as $item) {
240  if ($item["ref_id"] != $this->parent_ref_id &&
241  !$tree->isDeleted($item["ref_id"]) &&
242  $ilAccess->checkAccess("visible", "", $item["ref_id"])) {
243  // group all valid items in blocks
244  // by their parent group/course or category
245  $block_ref_id = 0;
246  $block_title = "";
247  foreach ($tree->getPathFull($item["ref_id"]) as $p) {
248  if (in_array($p["type"], array("root", "cat", "crs", "grp"))) {
249  $block_ref_id = $p["ref_id"];
250  $block_title = $p["title"];
251  }
252  }
253  if ($block_ref_id > 0) {
254  if (!is_array($valid_objects[$block_ref_id])) {
255  $valid_objects[$block_ref_id] = array(
256  "title" => $block_title,
257  "items" => array()
258  );
259  }
260  $valid_objects[$block_ref_id]["items"][] = $item;
261  }
262 
263  $preloader->addItem($item["obj_id"], $item["type"], $item["ref_id"]);
264  }
265  }
266  $valid_objects = ilUtil::sortArray($valid_objects, "title", "asc", false, true);
267  if (sizeof($valid_objects)) {
268  $has_content = true;
269 
270  $preloader->preload();
271 
272  // see ilPDTaggingBlockGUI::showResourcesForTag()
273 
274  $this->item_list_gui = array();
275  foreach ($valid_objects as $block) {
276  $items = ilUtil::sortArray($block["items"], "title", "asc", false, true);
277  foreach ($items as $obj) {
278  $type = $obj["type"];
279 
280  // get list gui class for each object type
281  if (empty($this->item_list_gui[$type])) {
282  $class = $objDefinition->getClassName($type);
283  $location = $objDefinition->getLocation($type);
284 
285  $full_class = "ilObj" . $class . "ListGUI";
286 
287  include_once($location . "/class." . $full_class . ".php");
288  $this->item_list_gui[$type] = new $full_class();
289  $this->item_list_gui[$type]->enableDelete(false);
290  $this->item_list_gui[$type]->enablePath(
291  true,
292  $this->parent_ref_id,
294  );
295  $this->item_list_gui[$type]->enableLinkedPath(true);
296  $this->item_list_gui[$type]->enableCut(false);
297  $this->item_list_gui[$type]->enableCopy(false);
298  $this->item_list_gui[$type]->enableSubscribe(false);
299  $this->item_list_gui[$type]->enableLink(false);
300  $this->item_list_gui[$type]->enableIcon(true);
301 
302  // :TOOD: for each item or just for each list?
303  foreach ($this->providers as $provider) {
304  $provider->initListGUI($this->item_list_gui[$type]);
305  }
306  }
307 
308  $html = $this->item_list_gui[$type]->getListItemHTML(
309  $obj["ref_id"],
310  $obj["obj_id"],
311  $obj["title"],
312  $obj["description"]
313  );
314 
315  if ($html != "") {
316  $ltpl->setCurrentBlock("res_row");
317  $ltpl->setVariable("RESOURCE_HTML", $html);
318  $ltpl->parseCurrentBlock();
319  }
320  }
321  $ltpl->setCurrentBlock("block");
322  $ltpl->setVariable("BLOCK_TITLE", $block["title"]);
323  $ltpl->parseCurrentBlock();
324  }
325  }
326  }
327  }
328 
329  if ($has_content) {
330  echo $ltpl->get();
331  } else {
332  //$content_block->setContent($lng->txt("clsfct_content_no_match"));
333  echo $tpl->getMessageHTML($lng->txt("clsfct_content_no_match"), "info");
334  }
335 
336  exit();
337  }
338 
339  protected function initProviders($a_check_post = false)
340  {
341  if (!isset(self::$providers_cache[$this->parent_ref_id])) {
342  include_once "Services/Classification/classes/class.ilClassificationProvider.php";
344  $this->parent_ref_id,
345  $this->parent_obj_id,
346  $this->parent_obj_typ
347  );
348  }
349  $this->providers = self::$providers_cache[$this->parent_ref_id];
350 
351  if ($a_check_post && (bool) !$_REQUEST["rdrw"]) {
352  foreach ($this->providers as $provider) {
353  $id = get_class($provider);
354  $current = $provider->importPostData($_SESSION[self::getBlockType()][$id]);
355  if ($current) {
356  $_SESSION[self::getBlockType()][$id] = $current;
357  } else {
358  unset($_SESSION[self::getBlockType()][$id]);
359  }
360  }
361  }
362 
363  foreach ($this->providers as $provider) {
364  $id = get_class($provider);
365  $current = $_SESSION[self::getBlockType()][$id];
366  if ($current) {
367  $provider->setSelection($current);
368  }
369  }
370  }
371 }
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static getValidProviders($a_parent_ref_id, $a_parent_obj_id, $a_parent_obj_type)
Get all valid providers (for parent container)
$_SESSION["AccountId"]
Tabs GUI.
$type
global $DIC
Definition: saml.php:7
$_GET["client_id"]
$location
Definition: buildRTE.php:44
setFooterInfo($a_footerinfo, $a_hide_and_icon=false)
Set Footer Info.
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilCtrl
Definition: ilias.php:18
Classification block, displayed in different contexts, e.g.
Preloader for object list GUIs.
setTitle($a_title)
Set Title.
static _lookupObjId($a_id)
special template class to simplify handling of ITX/PEAR
const IL_SCREEN_CENTER
PathGUI which handles materials assigned to sessions.
static _lookupType($a_id, $a_reference=false)
lookup object type
if(!empty($this->data['faventry'])) $tabs
Definition: disco.tpl.php:124
exit
Definition: backend.php:16
This class represents a block method of a block.
$html
Definition: example_001.php:87