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