ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Renderer.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2017 Jesús López <lopez@leifos.de> Extended GPL, see docs/LICENSE */
3 
5 
9 
15 {
16  const MODE_ROLE = "group";
17 
22  public function render(Component\Component $component, RendererInterface $default_renderer)
23  {
24  $this->checkComponent($component);
25 
26  if ($component instanceof Component\ViewControl\Mode) {
27  return $this->renderMode($component, $default_renderer);
28  }
29  if ($component instanceof Component\ViewControl\Section) {
30  return $this->renderSection($component, $default_renderer);
31  }
32  if ($component instanceof Component\ViewControl\Sortation) {
33  return $this->renderSortation($component, $default_renderer);
34  }
35  }
36 
37  protected function renderMode(Component\ViewControl\Mode $component, RendererInterface $default_renderer)
38  {
39  $f = $this->getUIFactory();
40 
41  $tpl = $this->getTemplate("tpl.mode.html", true, true);
42 
43  $active = $component->getActive();
44  if ($active == "") {
45  $activate_first_item = true;
46  }
47 
48  foreach ($component->getLabelledActions() as $label => $action) {
49  $tpl->setVariable("ARIA", $this->txt($component->getAriaLabel()));
50  $tpl->setVariable("ROLE", self::MODE_ROLE);
51 
52  $tpl->setCurrentBlock("view_control");
53 
54  //At this point we don't have an specific text for the button aria label. component->getAriaLabel gets the main viewcontrol aria label.
55  if ($activate_first_item) {
56  $tpl->setVariable("BUTTON", $default_renderer->render($f->button()->standard($label, $action)->WithUnavailableAction()->withAriaLabel($label)->withAriaChecked()));
57  $activate_first_item = false;
58  } elseif ($active == $label) {
59  $tpl->setVariable("BUTTON", $default_renderer->render($f->button()->standard($label, $action)->withUnavailableAction()->withAriaLabel($label)->withAriaChecked()));
60  } else {
61  $tpl->setVariable("BUTTON", $default_renderer->render($f->button()->standard($label, $action)->withAriaLabel($label)));
62  }
63  $tpl->parseCurrentBlock();
64  }
65 
66  return $tpl->get();
67  }
68 
69  protected function renderSection(Component\ViewControl\Section $component, RendererInterface $default_renderer)
70  {
71  $f = $this->getUIFactory();
72 
73  $tpl = $this->getTemplate("tpl.section.html", true, true);
74 
75  // render middle button
76  $tpl->setVariable("BUTTON", $default_renderer->render($component->getSelectorButton()));
77 
78  // previous button
79  $this->renderSectionButton($component->getPreviousActions(), $tpl, "prev");
80 
81  // next button
82  $this->renderSectionButton($component->getNextActions(), $tpl, "next");
83 
84  return $tpl->get();
85  }
86 
92  protected function renderSectionButton(Component\Button\Button $component, $tpl, $type)
93  {
94  $uptype = strtoupper($type);
95 
96  $action = $component->getAction();
97  $tpl->setVariable($uptype . "_ACTION", $action);
98  if ($component->isActive()) {
99  $tpl->setCurrentBlock($type . "_with_href");
100  $tpl->setVariable($uptype . "_HREF", $action);
101  $tpl->parseCurrentBlock();
102  } else {
103  $tpl->touchBlock($type . "_disabled");
104  }
105  $this->maybeRenderId($component, $tpl, $type . "_with_id", $uptype . "_ID");
106  }
107 
108 
109  protected function renderSortation(Component\ViewControl\Sortation $component, RendererInterface $default_renderer)
110  {
111  $f = new \ILIAS\UI\Implementation\Factory(
112  new \ILIAS\UI\Implementation\Component\SignalGenerator()
113  );
114 
115  $tpl = $this->getTemplate("tpl.sortation.html", true, true);
116 
117  $component = $component->withResetSignals();
118  $triggeredSignals = $component->getTriggeredSignals();
119  if ($triggeredSignals) {
120  $internal_signal = $component->getSelectSignal();
121  $signal = $triggeredSignals[0]->getSignal();
122  $options = json_encode($signal->getOptions());
123 
124  $component = $component->withOnLoadCode(function ($id) use ($internal_signal, $signal) {
125  return "$(document).on('{$internal_signal}', function(event, signalData) {
126  il.UI.viewcontrol.sortation.onInternalSelect(event, signalData, '{$signal}', '{$id}');
127  return false;
128  })";
129  });
130 
131  //maybeRenderId does not return id
132  $id = $this->bindJavaScript($component);
133  $tpl->setVariable('ID', $id);
134  }
135 
136  //setup entries
137  $options = $component->getOptions();
138  $init_label = $component->getLabel();
139  $items = array();
140  foreach ($options as $val => $label) {
141  if ($triggeredSignals) {
142  $shy = $f->button()->shy($label, $val)->withOnClick($internal_signal);
143  } else {
144  $url = $component->getTargetURL();
145  $url .= (strpos($url, '?') === false) ? '?' : '&';
146  $url .= $component->getParameterName() . '=' . $val;
147  $shy = $f->button()->shy($label, $url);
148  }
149  $items[] = $shy;
150  }
151 
152  $dd = $f->dropdown()->standard($items)
153  ->withLabel($init_label);
154 
155  $tpl->setVariable('SORTATION_DROPDOWN', $default_renderer->render($dd));
156  return $tpl->get();
157  }
158 
159 
163  public function registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry)
164  {
165  parent::registerResources($registry);
166  $registry->register('./src/UI/templates/js/ViewControl/sortation.js');
167  }
168 
169 
170  protected function maybeRenderId(Component\Component $component, $tpl, $block, $template_var)
171  {
172  $id = $this->bindJavaScript($component);
173  if ($id !== null) {
174  $tpl->setCurrentBlock($block);
175  $tpl->setVariable($template_var, $id);
176  $tpl->parseCurrentBlock();
177  }
178  }
179 
183  protected function getComponentInterfaceName()
184  {
185  return array(
186  Component\ViewControl\Mode::class,
187  Component\ViewControl\Section::class,
188  Component\ViewControl\Sortation::class
189  );
190  }
191 }
renderSection(Component\ViewControl\Section $component, RendererInterface $default_renderer)
Definition: Renderer.php:69
renderSortation(Component\ViewControl\Sortation $component, RendererInterface $default_renderer)
Definition: Renderer.php:109
Class Factory.
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:22
$action
checkComponent(Component $component)
Check if a given component fits this renderer and throw if that is not the case. ...
$type
$tpl
Definition: ilias.php:10
Class BaseForm.
if(!array_key_exists('StateId', $_REQUEST)) $id
renderSectionButton(Component\Button\Button $component, $tpl, $type)
Definition: Renderer.php:92
registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry)
Definition: Renderer.php:163
renderMode(Component\ViewControl\Mode $component, RendererInterface $default_renderer)
Definition: Renderer.php:37
maybeRenderId(Component\Component $component, $tpl, $block, $template_var)
Definition: Renderer.php:170
Create styles array
The data for the language used.
$url
getTemplate($name, $purge_unfilled_vars, $purge_unused_blocks)
Get template of component this renderer is made for.
This describes commonalities between standard and primary buttons.
Definition: Button.php:15
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.