ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
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]->enableLink(false);
261  $this->item_list_gui[$type]->enableIcon(true);
262 
263  // :TOOD: for each item or just for each list?
264  foreach($this->providers as $provider)
265  {
266  $provider->initListGUI($this->item_list_gui[$type]);
267  }
268  }
269 
270  $html = $this->item_list_gui[$type]->getListItemHTML(
271  $obj["ref_id"],
272  $obj["obj_id"],
273  $obj["title"],
274  $obj["description"]);
275 
276  if ($html != "")
277  {
278  $css = ($css != "tblrow1") ? "tblrow1" : "tblrow2";
279 
280  $ltpl->setCurrentBlock("res_row");
281  $ltpl->setVariable("ROWCLASS", $css);
282  $ltpl->setVariable("RESOURCE_HTML", $html);
283  $ltpl->setVariable("ALT_TYPE", $lng->txt("obj_".$type));
284  $ltpl->setVariable("IMG_TYPE",
285  ilUtil::getImagePath("icon_".$type.".svg"));
286  $ltpl->parseCurrentBlock();
287  }
288  }
289  }
290  }
291  }
292 
293  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
294  $content_block = new ilPDContentBlockGUI();
295  $content_block->setTitle($lng->txt("clsfct_content_title"));
296  $content_block->addHeaderCommand($ilCtrl->getParentReturn($this), "", true);
297 
298  if($has_content)
299  {
300  $content_block->setContent($ltpl->get());
301  }
302  else
303  {
304  $content_block->setContent($lng->txt("clsfct_content_no_match"));
305  }
306 
307  echo $content_block->getHTML();
308  exit();
309  }
310 
311  protected function initProviders($a_check_post = false)
312  {
313  if(!isset(self::$providers_cache[$this->parent_ref_id]))
314  {
315  include_once "Services/Classification/classes/class.ilClassificationProvider.php";
317  $this->parent_ref_id,
318  $this->parent_obj_id,
319  $this->parent_obj_typ
320  );
321  }
322  $this->providers = self::$providers_cache[$this->parent_ref_id];
323 
324  if($a_check_post && (bool)!$_REQUEST["rdrw"])
325  {
326  foreach($this->providers as $provider)
327  {
328  $id = get_class($provider);
329  $current = $provider->importPostData($_SESSION[self::getBlockType()][$id]);
330  if($current)
331  {
332  $_SESSION[self::getBlockType()][$id] = $current;
333  }
334  else
335  {
336  unset($_SESSION[self::getBlockType()][$id]);
337  }
338  }
339  }
340 
341  foreach($this->providers as $provider)
342  {
343  $id = get_class($provider);
344  $current = $_SESSION[self::getBlockType()][$id];
345  if($current)
346  {
347  $provider->setSelection($current);
348  }
349  }
350  }
351 }
static getValidProviders($a_parent_ref_id, $a_parent_obj_id, $a_parent_obj_type)
Get all valid providers (for parent container)
$_SESSION["AccountId"]
$_GET["client_id"]
$location
Definition: buildRTE.php:44
setFooterInfo($a_footerinfo, $a_hide_and_icon=false)
Set Footer Info.
$cmd
Definition: sahs_server.php:35
global $tpl
Definition: ilias.php:8
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 getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static _lookupObjId($a_id)
special template class to simplify handling of ITX/PEAR
const IL_SCREEN_CENTER
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
global $lng
Definition: privfeed.php:17
This class represents a block method of a block.
BlockGUI class for (centered) Content on Personal Desktop.
$html
Definition: example_001.php:87