ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilMultipleNestedOrderingElementsInputGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Form/classes/class.ilIdentifiedMultiValuesInputGUI.php';
5 require_once 'Modules/Test/classes/inc.AssessmentConstants.php';
14 {
15  const HTML_LIST_TAG_UL = 'ul';
16  const HTML_LIST_TAG_OL = 'ol';
17 
18  const CSS_LIST_CLASS = 'dd-list';
19  const CSS_ITEM_CLASS = 'dd-item';
20  const CSS_HANDLE_CLASS = 'dd-handle';
21 
22  const POSTVAR_SUBFIELD_NEST_ELEM = 'content';
23  const POSTVAR_SUBFIELD_NEST_INDENT = 'indentation';
24 
25  const DEFAULT_INSTANCE_ID = 'default';
26 
27  protected $instanceId = self::DEFAULT_INSTANCE_ID;
28 
29  protected $interactionEnabled = true;
30 
31  protected $nestingEnabled = true;
32 
33  protected $stylingDisabled = false;
34 
35  protected $listTpl = null;
36 
37  protected $cssListClass = self::CSS_LIST_CLASS;
38 
39  protected $cssItemClass = self::CSS_ITEM_CLASS;
40 
41  protected $cssHandleClass = self::CSS_HANDLE_CLASS;
42 
43  protected $htmlListTag = self::HTML_LIST_TAG_OL;
44 
45  public function __construct($a_title = '', $a_postvar = '')
46  {
47  parent::__construct($a_title, $a_postvar);
48 
49  require_once 'Services/Form/classes/class.ilMultipleNestedOrderingElementsAdditionalIndexLevelRemover.php';
51  $this->addFormValuesManipulator($manipulator);
52  }
53 
54  public function setInstanceId($instanceId)
55  {
56  $this->instanceId = $instanceId;
57  }
58 
59  public function getInstanceId()
60  {
61  return $this->instanceId;
62  }
63 
65  {
66  $this->interactionEnabled = $interactionEnabled;
67  }
68 
69  public function isInteractionEnabled()
70  {
72  }
73 
74  public function isNestingEnabled()
75  {
76  return $this->nestingEnabled;
77  }
78 
80  {
81  $this->nestingEnabled = $nestingEnabled;
82  }
83 
84  public function isStylingDisabled()
85  {
87  }
88 
90  {
91  $this->stylingDisabled = $stylingDisabled;
92  }
93 
94  protected function isStylingEnabled()
95  {
96  return !$this->isStylingDisabled();
97  }
98 
102  public function getCssListClass()
103  {
104  return $this->cssListClass;
105  }
106 
111  {
112  $this->cssListClass = $cssListClass;
113  }
114 
118  public function getCssItemClass()
119  {
120  return $this->cssItemClass;
121  }
122 
126  public function getCssHandleClass()
127  {
128  return $this->cssHandleClass;
129  }
130 
135  {
136  $this->cssHandleClass = $cssHandleClass;
137  }
138 
143  {
144  $this->cssItemClass = $cssItemClass;
145  }
146 
150  public function getHtmlListTag()
151  {
152  return $this->htmlListTag;
153  }
154 
158  public function setHtmlListTag($htmlListTag)
159  {
160  $this->htmlListTag = $htmlListTag;
161  }
162 
166  protected function getGlobalTpl()
167  {
168  return isset($GLOBALS['DIC']) ? $GLOBALS['DIC']['tpl'] : $GLOBALS['tpl'];
169  }
170 
174  public function getListTpl()
175  {
176  return $this->listTpl;
177  }
178 
182  public function setListTpl($listTpl)
183  {
184  $this->listTpl = $listTpl;
185  }
186 
187  protected function initListTemplate()
188  {
189  $this->setListTpl(
190  new ilTemplate('tpl.prop_nested_ordering_list.html', true, true, 'Services/Form')
191  );
192  }
193 
194  protected function fetchListHtml()
195  {
196  return $this->getListTpl()->get();
197  }
198 
199  protected function renderListContainer()
200  {
201  $this->getListTpl()->setCurrentBlock('list_container');
202  $this->getListTpl()->setVariable('INSTANCE_ID', $this->getInstanceId());
203  $this->getListTpl()->parseCurrentBlock();
204  }
205 
206  protected function renderListSnippet()
207  {
208  $this->getListTpl()->setCurrentBlock('list_snippet');
209  $this->getListTpl()->parseCurrentBlock();
210  }
211 
212  protected function renderListItem($value, $identifier, $position)
213  {
214  $subPostVar = $this->getMultiValuePostVarSubField($identifier, self::POSTVAR_SUBFIELD_NEST_ELEM);
215  $subFieldId = $this->getMultiValueSubFieldId($identifier, self::POSTVAR_SUBFIELD_NEST_ELEM);
216 
217  $this->getListTpl()->setCurrentBlock('item_value');
218 
219  $this->getListTpl()->setVariable('ILC_HANDLE_CSS_CLASS', $this->getCssHandleClass());
220 
221  $this->getListTpl()->setVariable('LIST_ITEM_VALUE', $this->getItemHtml(
222  $value, $identifier, $position, $subPostVar, $subFieldId
223  ));
224 
225  $this->getListTpl()->parseCurrentBlock();
226 
227  $this->renderListSnippet();
228  }
229 
238  abstract protected function getItemHtml($value, $identifier, $position, $itemSubFieldPostVar, $itemSubFieldId);
239 
240  protected function renderBeginListItem($identifier)
241  {
242  $this->getListTpl()->setCurrentBlock('begin_list_item');
243  $this->getListTpl()->setVariable('LIST_ITEM_ID', $identifier);
244  $this->getListTpl()->setVariable('ILC_ITEM_CSS_CLASS', $this->getCssItemClass());
245  $this->getListTpl()->parseCurrentBlock();
246  $this->renderListSnippet();
247  }
248 
249  protected function renderEndListItem()
250  {
251  $this->getListTpl()->setCurrentBlock('end_list_item');
252  $this->getListTpl()->touchBlock('end_list_item');
253  $this->getListTpl()->parseCurrentBlock();
254  $this->renderListSnippet();
255  }
256 
257  protected function renderBeginSubList()
258  {
259  $this->getListTpl()->setCurrentBlock('begin_sublist');
260  $this->getListTpl()->setVariable('BEGIN_HTML_LIST_TAG', $this->getHtmlListTag());
261  $this->getListTpl()->setVariable('ILC_LIST_CSS_CLASS', $this->getCssListClass());
262  $this->getListTpl()->parseCurrentBlock();
263  $this->renderListSnippet();
264  }
265 
266  protected function renderEndSubList()
267  {
268  $this->getListTpl()->setCurrentBlock('end_sublist');
269  $this->getListTpl()->setVariable('END_HTML_LIST_TAG', $this->getHtmlListTag());
270  $this->getListTpl()->parseCurrentBlock();
271  $this->renderListSnippet();
272  }
273 
279  abstract protected function getCurrentIndentation($elementValues, $elementCounter);
280 
286  abstract protected function getNextIndentation($elementValues, $elementCounter);
287 
288  protected function renderMainList()
289  {
290  $this->initListTemplate();
291  $this->renderBeginSubList();
292 
293 
294  $values = array_values($this->getIdentifiedMultiValues());
295  $keys = array_keys($this->getIdentifiedMultiValues());
296  $prevIndent = 0;
297 
298  foreach($values as $counter => $value)
299  {
300  $identifier = $keys[$counter];
301 
302  if( $this->isNestingEnabled() )
303  {
304  $curIndent = $this->getCurrentIndentation($values, $counter);
305  $nextIndent = $this->getNextIndentation($values, $counter);
306  }
307  else
308  {
309  $curIndent = $nextIndent = 0;
310  }
311 
312  if($prevIndent == $curIndent)
313  {
314  // pcn = Previous, Current, Next -> Depth
315  // pcn: 000, 001, 110, 220
316  if($curIndent == $nextIndent)
317  {
318  // (1) pcn: 000
319  // echo"(1)";
320  $this->renderBeginListItem($identifier);
321  $this->renderListItem($value, $identifier, $counter);
322  $this->renderEndListItem();
323  }
324  else if($curIndent > $nextIndent)
325  {
326  if($prevIndent == $nextIndent)
327  {
328  // wenn prev = cur ist und cur > next, wie soll prev = next sein !?
329 
330  // (8) pcn: 110
331  // echo"(8)";
332  $this->renderBeginListItem($identifier);
333  $this->renderListItem($value, $identifier, $counter);
334  $this->renderEndListItem();
335  $this->renderEndSubList();
336  $this->renderEndListItem();
337  }
338  else if($prevIndent > $nextIndent)
339  {
340  // (12) pcn: 220
341  // echo"(12)";
342  $this->renderBeginListItem($identifier);
343  $this->renderListItem($value, $identifier, $counter);
344 
345  for($openlists = $nextIndent; $openlists < $curIndent; $openlists++)
346  {
347  $this->renderEndListItem();
348  $this->renderEndSubList();
349  $this->renderEndListItem();
350  }
351  }
352  }
353  else if($curIndent < $nextIndent)
354  {
355  // (2) pcn: 001
356  // echo"(2)";
357  $this->renderBeginListItem($identifier);
358  $this->renderListItem($value, $identifier, $counter);
359  $this->renderBeginSubList();
360  }
361  }
362  else if($prevIndent > $curIndent)
363  {
364  if($curIndent == $nextIndent)
365  {
366  // (6) pcn: 100
367  // echo"(6)";
368  $this->renderBeginListItem($identifier);
369  $this->renderListItem($value, $identifier, $counter);
370  $this->renderEndListItem();
371  }
372  else if($curIndent > $nextIndent)
373  {
374  // (11) pcn: 210
375  // echo"(11)";
376  $this->renderBeginListItem($identifier);
377  $this->renderListItem($value, $identifier, $counter);
378  $this->renderEndListItem();
379  $this->renderEndSubList();
380  }
381  else if($curIndent < $nextIndent)
382  {
383  if($prevIndent == $nextIndent)
384  {
385  // (7) pcn: 101
386  // echo"(7)";
387  $this->renderBeginListItem($identifier);
388  $this->renderListItem($value, $identifier, $counter);
389  $this->renderBeginSubList();
390  }
391  else if($prevIndent > $nextIndent)
392  {
393  // (10) pcn: 201
394  // echo"(10)";
395  $this->renderBeginListItem($identifier);
396  $this->renderListItem($value, $identifier, $counter);
397  for($openlists = $nextIndent; $openlists < $curIndent; $openlists++)
398  {
399  $this->renderEndSubList();
400  }
401  $this->renderBeginSubList();
402  }
403  }
404  }
405  else if($prevIndent < $curIndent)
406  {
407  if($curIndent == $nextIndent)
408  {
409  // (4) pcn: 011
410  // echo"(4)";
411  $this->renderBeginListItem($identifier);
412  $this->renderListItem($value, $identifier, $counter);
413  $this->renderEndListItem();
414  }
415  else if($curIndent > $nextIndent)
416  {
417  if($prevIndent == $nextIndent)
418  {
419  // (3) pcn: 010,
420  // echo"(3)";
421  $this->renderBeginListItem($identifier);
422  $this->renderListItem($value, $identifier, $counter);
423  $this->renderEndListItem();
424  $this->renderEndSubList();
425  $this->renderEndListItem();
426 
427  }
428  else if($prevIndent > $nextIndent)
429  {
430  // (9) pcn: 120
431  // echo"(9)";
432  $this->renderBeginListItem($identifier);
433  $this->renderListItem($value, $identifier, $counter);
434  for($openlists = $nextIndent; $openlists < $curIndent; $openlists++)
435  {
436  $this->renderEndListItem();
437  $this->renderEndSubList();
438  }
439  }
440  }
441  else if($curIndent < $nextIndent)
442  {
443  // (5) pcn: 012
444  // echo"(5)";
445  $this->renderBeginListItem($identifier);
446  $this->renderListItem($value, $identifier, $counter);
447  $this->renderBeginSubList();
448  }
449  }
450 
451  $prevIndent = $curIndent;
452  }
453 
454  $this->renderEndSubList();
455  $this->renderListContainer();
456 
457  return $this->fetchListHtml();
458  }
459 
460  protected function renderJsInit()
461  {
462  $jsTpl = new ilTemplate('tpl.prop_nested_ordering_js.html', true, true, 'Services/Form');
463 
464  if( !$this->isNestingEnabled() )
465  {
466  $jsTpl->setCurrentBlock('avoid_nesting');
467  $jsTpl->touchBlock('avoid_nesting');
468  $jsTpl->parseCurrentBlock();
469  }
470 
471  $jsTpl->setCurrentBlock('nested_ordering_init');
472  $jsTpl->setVariable('INSTANCE_ID', $this->getInstanceId());
473  $jsTpl->setVariable('INDENTATION_POSTVAR', $this->getPostVarSubField('indentation'));
474  $jsTpl->setVariable('HTML_LIST_TAG', $this->getHtmlListTag());
475  $jsTpl->setVariable('CSS_LIST_CLASS', $this->getCssListClass());
476  $jsTpl->setVariable('CSS_ITEM_CLASS', $this->getCssItemClass());
477  $jsTpl->parseCurrentBlock();
478 
479  return $jsTpl->get();
480  }
481 
482  public function render($a_mode = "")
483  {
484  if( $this->isStylingEnabled() )
485  {
486  $this->getGlobalTpl()->addCss('Services/Form/css/nested_ordering.css');
487  }
488 
489  if( $this->isInteractionEnabled() )
490  {
491  require_once 'Services/jQuery/classes/class.iljQueryUtil.php';
492 
495 
496  $this->getGlobalTpl()->addJavaScript('Services/jQuery/js/jquery.nestable.js');
497 
498  return $this->renderMainList() . $this->renderJsInit();
499  }
500 
501  return $this->renderMainList();
502  }
503 
504  public function onCheckInput()
505  {
506  return true;
507  }
508 
509  public function getHTML()
510  {
511  return $this->render();
512  }
513 }
static initjQueryUI()
Init jQuery UI (see included_components.txt for included components)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$counter
special template class to simplify handling of ITX/PEAR
getItemHtml($value, $identifier, $position, $itemSubFieldPostVar, $itemSubFieldId)
getCurrentIndentation($elementValues, $elementCounter)
getNextIndentation($elementValues, $elementCounter)
static initjQuery($a_tpl=null)
Init jQuery.
addFormValuesManipulator(ilFormValuesManipulator $manipulator)