ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
18 protected $parent_obj_type; // [string]
19 protected $parent_obj_id; // [int]
20 protected $parent_ref_id; // [int]
21 protected $providers; // [array]
22 protected $item_list_gui; // [array]
23
24 protected static $providers_cache; // [array]
25
26 public function __construct()
27 {
28 global $lng;
29
30 parent::__construct();
31
32 $this->parent_ref_id = (int)$_GET["ref_id"];
33 $this->parent_obj_id = ilObject::_lookupObjId($this->parent_ref_id);
34 $this->parent_obj_type = ilObject::_lookupType($this->parent_obj_id);
35
36 $lng->loadLanguageModule("classification");
37 $this->setTitle($lng->txt("clsfct_block_title"));
38 $this->setFooterInfo($lng->txt("clsfct_block_info"));
39 }
40
41 public static function getBlockType()
42 {
43 return 'clsfct';
44 }
45
46 public static function isRepositoryObject()
47 {
48 return false;
49 }
50
51 public function executeCommand()
52 {
53 global $ilCtrl;
54
55 $cmd = $ilCtrl->getCmd();
56 $next_class = $ilCtrl->getNextClass($this);
57
58 switch ($next_class)
59 {
60 default:
61 // explorer call
62 if($ilCtrl->isAsynch() && $cmd != "getAjax" && $cmd != "filterContainer")
63 {
64 $this->getHTML();
65 }
66 else
67 {
68 $this->$cmd();
69 }
70 break;
71 }
72 }
73
74 static function getScreenMode()
75 {
76 global $ilCtrl;
77
78 if($ilCtrl->isAsynch())
79 {
80 return;
81 }
82
83 switch($ilCtrl->getCmd())
84 {
85 case "filterContainer":
86 return IL_SCREEN_CENTER;
87 }
88 }
89
90 public function getHTML()
91 {
92 global $tpl, $ilCtrl;
93
94 if(!$ilCtrl->isAsynch())
95 {
96 unset($_SESSION[self::getBlockType()]);
97 }
98
99 $this->initProviders();
100
101 if(!$this->validate())
102 {
103 return "";
104 }
105
106 $tpl->addJavaScript("Services/Classification/js/ilClassification.js");
107
108 return parent::getHTML();
109 }
110
111 public function getAjax()
112 {
113 global $tpl;
114
115 $this->initProviders(true);
116
117 echo $this->getHTML();
118 echo $tpl->getOnLoadCodeForAsynch();
119
120 exit();
121 }
122
123 public function fillDataSection()
124 {
125 global $ilCtrl, $tpl;
126
127 $html = array();
128 foreach($this->providers as $provider)
129 {
130 $provider->render($html, $this);
131 }
132
133 $this->tpl->setVariable("BLOCK_ROW", "");
134
135 $ajax_block_id = "block_".$this->getBlockType()."_0";
136 $ajax_block_url = $ilCtrl->getLinkTarget($this, "getAjax", "", true, false);
137 $ajax_content_id = "il_center_col";
138 $ajax_content_url = $ilCtrl->getLinkTarget($this, "filterContainer", "", true, false);
139
140 // #15008 - always load regardless of content (because of redraw)
141 $tpl->addOnLoadCode('il.Classification.setAjax("'.$ajax_block_id.'", "'.
142 $ajax_block_url.'", "'.$ajax_content_id.'", "'.$ajax_content_url.'");');
143
144 if(sizeof($html))
145 {
146 $btpl = new ilTemplate("tpl.classification_block.html", true, true, "Services/Classification");
147
148 foreach($html as $item)
149 {
150 $btpl->setCurrentBlock("provider_chunk_bl");
151 $btpl->setVariable("TITLE", $item["title"]);
152 $btpl->setVariable("CHUNK", $item["html"]);
153 $btpl->parseCurrentBlock();
154 }
155
156 $this->tpl->setVariable("DATA", $btpl->get());
157 }
158 }
159
160 protected function validate()
161 {
162 return sizeof($this->providers);
163 }
164
165 protected function filterContainer()
166 {
167 global $objDefinition, $lng, $tree, $ilAccess, $ilCtrl;
168
169 $this->initProviders();
170
171 // empty selection is invalid
172 if(!$_SESSION[self::getBlockType()])
173 {
174 exit();
175 }
176
177 $all_matching_provider_object_ids = null;
178
179 foreach($this->providers as $provider)
180 {
181 $id = get_class($provider);
182 $current = $_SESSION[self::getBlockType()][$id];
183 if($current)
184 {
185 // combine providers AND
186 $provider_object_ids = $provider->getFilteredObjects();
187 if(is_array($all_matching_provider_object_ids))
188 {
189 $all_matching_provider_object_ids = array_intersect($matching_provider_object_ids, $provider_object_ids);
190 }
191 else
192 {
193 $all_matching_provider_object_ids = $provider_object_ids;
194 }
195 }
196 }
197
198 $has_content = false;
199
200 $ltpl = new ilTemplate("tpl.classification_object_list.html", true, true, "Services/Classification");
201
202 if(sizeof($all_matching_provider_object_ids))
203 {
204 $fields = array(
205 "object_reference.ref_id"
206 ,"object_data.obj_id"
207 ,"object_data.type"
208 ,"object_data.title"
209 ,"object_data.description"
210 );
211 $matching = $tree->getSubTreeFilteredByObjIds($this->parent_ref_id, $all_matching_provider_object_ids, $fields);
212 if(sizeof($matching))
213 {
214 $valid_objects = array();
215
216 // :TODO: not sure if this makes sense...
217 include_once "Services/Object/classes/class.ilObjectListGUIPreloader.php";
219
220 foreach($matching as $item)
221 {
222 if($item["ref_id"] != $this->parent_ref_id &&
223 !$tree->isDeleted($item["ref_id"]) &&
224 $ilAccess->checkAccess("read", "", $item["ref_id"]))
225 {
226 $valid_objects[] = $item;
227
228 $preloader->addItem($item["obj_id"], $item["type"], $item["ref_id"]);
229 }
230 }
231
232 if(sizeof($valid_objects))
233 {
234 $has_content = true;
235
236 $preloader->preload();
237
238 // see ilPDTaggingBlockGUI::showResourcesForTag()
239
240 $this->item_list_gui = array();
241 foreach($valid_objects as $obj)
242 {
243 $type = $obj["type"];
244
245 // get list gui class for each object type
246 if (empty($this->item_list_gui[$type]))
247 {
248 $class = $objDefinition->getClassName($type);
249 $location = $objDefinition->getLocation($type);
250
251 $full_class = "ilObj".$class."ListGUI";
252
253 include_once($location."/class.".$full_class.".php");
254 $this->item_list_gui[$type] = new $full_class();
255 $this->item_list_gui[$type]->enableDelete(false);
256 $this->item_list_gui[$type]->enablePath(true, $this->parent_ref_id); // relative path
257 $this->item_list_gui[$type]->enableCut(false);
258 $this->item_list_gui[$type]->enableCopy(false);
259 $this->item_list_gui[$type]->enableSubscribe(false);
260 $this->item_list_gui[$type]->enablePayment(false);
261 $this->item_list_gui[$type]->enableLink(false);
262 $this->item_list_gui[$type]->enableIcon(true);
263
264 // :TOOD: for each item or just for each list?
265 foreach($this->providers as $provider)
266 {
267 $provider->initListGUI($this->item_list_gui[$type]);
268 }
269 }
270
271 $html = $this->item_list_gui[$type]->getListItemHTML(
272 $obj["ref_id"],
273 $obj["obj_id"],
274 $obj["title"],
275 $obj["description"]);
276
277 if ($html != "")
278 {
279 $css = ($css != "tblrow1") ? "tblrow1" : "tblrow2";
280
281 $ltpl->setCurrentBlock("res_row");
282 $ltpl->setVariable("ROWCLASS", $css);
283 $ltpl->setVariable("RESOURCE_HTML", $html);
284 $ltpl->setVariable("ALT_TYPE", $lng->txt("obj_".$type));
285 $ltpl->setVariable("IMG_TYPE",
286 ilUtil::getImagePath("icon_".$type.".svg"));
287 $ltpl->parseCurrentBlock();
288 }
289 }
290 }
291 }
292 }
293
294 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
295 $content_block = new ilPDContentBlockGUI();
296 $content_block->setTitle($lng->txt("clsfct_content_title"));
297 $content_block->addHeaderCommand($ilCtrl->getParentReturn($this), "", true);
298
299 if($has_content)
300 {
301 $content_block->setContent($ltpl->get());
302 }
303 else
304 {
305 $content_block->setContent($lng->txt("clsfct_content_no_match"));
306 }
307
308 echo $content_block->getHTML();
309 exit();
310 }
311
312 protected function initProviders($a_check_post = false)
313 {
314 if(!isset(self::$providers_cache[$this->parent_ref_id]))
315 {
316 include_once "Services/Classification/classes/class.ilClassificationProvider.php";
318 $this->parent_ref_id,
319 $this->parent_obj_id,
320 $this->parent_obj_typ
321 );
322 }
323 $this->providers = self::$providers_cache[$this->parent_ref_id];
324
325 if($a_check_post && (bool)!$_REQUEST["rdrw"])
326 {
327 foreach($this->providers as $provider)
328 {
329 $id = get_class($provider);
330 $current = $provider->importPostData($_SESSION[self::getBlockType()][$id]);
331 if($current)
332 {
333 $_SESSION[self::getBlockType()][$id] = $current;
334 }
335 else
336 {
337 unset($_SESSION[self::getBlockType()][$id]);
338 }
339 }
340 }
341
342 foreach($this->providers as $provider)
343 {
344 $id = get_class($provider);
345 $current = $_SESSION[self::getBlockType()][$id];
346 if($current)
347 {
348 $provider->setSelection($current);
349 }
350 }
351 }
352}
global $tpl
Definition: ilias.php:8
$location
Definition: buildRTE.php:44
$_GET["client_id"]
$_SESSION["AccountId"]
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
BlockGUI class for (centered) Content on Personal Desktop.
special template class to simplify handling of ITX/PEAR
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$html
Definition: example_001.php:87
global $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:54
global $lng
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7