ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Renderer.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2017 Nils Haagen <nils.haagen@concepts.and-training.de> Extended GPL, see docs/LICENSE */
4 
6 
11 
13 {
17  public function render(Component\Component $component, RendererInterface $default_renderer)
18  {
19  $this->checkComponent($component);
20  if ($component instanceof Component\Table\Presentation) {
21  return $this->renderPresentationTable($component, $default_renderer);
22  }
23  if ($component instanceof Component\Table\PresentationRow) {
24  return $this->renderPresentationRow($component, $default_renderer);
25  }
26  }
27 
31  protected function getComponentInterfaceName()
32  {
33  return array(
34  Component\Table\PresentationRow::class,
35  Component\Table\Presentation::class
36  );
37  }
38 
44  protected function renderPresentationTable(Component\Table\Presentation $component, RendererInterface $default_renderer)
45  {
46  $tpl = $this->getTemplate("tpl.presentationtable.html", true, true);
47 
48  $tpl->setVariable("TITLE", $component->getTitle());
49 
50  $vcs = $component->getViewControls();
51  if ($vcs) {
52  $tpl->touchBlock("viewcontrols");
53  foreach ($vcs as $vc) {
54  $tpl->setCurrentBlock("vc");
55  $tpl->setVariable("VC", $default_renderer->render($vc));
56  $tpl->parseCurrentBlock();
57  }
58  }
59 
60  $row_mapping = $component->getRowMapping();
61  $data = $component->getData();
62  foreach ($data as $record) {
63  $row = $row_mapping(
64  new PresentationRow($component->getSignalGenerator()),
65  $record,
66  $this->getUIFactory(),
67  $component->getEnvironment()
68  );
69 
70  $tpl->setCurrentBlock("row");
71  $tpl->setVariable("ROW", $default_renderer->render($row));
72  $tpl->parseCurrentBlock();
73  }
74 
75  return $tpl->get();
76  }
77 
83  protected function renderPresentationRow(Component\Table\PresentationRow $component, RendererInterface $default_renderer)
84  {
85  $f = $this->getUIFactory();
86  $tpl = $this->getTemplate("tpl.presentationrow.html", true, true);
87 
88  $component = $this->registerSignals($component->withResetSignals());
89  $sig_show = $component->getShowSignal();
90  $sig_hide = $component->getCloseSignal();
91  $sig_toggle = $component->getToggleSignal();
92  $id = $this->bindJavaScript($component);
93 
94  $expander = $f->glyph()->expand("#")
95  ->withOnClick($sig_show);
96  $collapser = $f->glyph()->collapse("#")
97  ->withOnClick($sig_hide);
98  $shy_expander = $f->button()->shy($this->txt("presentation_table_more"), "#")
99  ->withOnClick($sig_show);
100 
101  $tpl->setVariable("ID", $id);
102  $tpl->setVariable("EXPANDER", $default_renderer->render($expander));
103  $tpl->setVariable("COLLAPSER", $default_renderer->render($collapser));
104  $tpl->setVariable("SHY_EXPANDER", $default_renderer->render($shy_expander));
105 
106  $tpl->setVariable("HEADLINE", $component->getHeadline());
107  $tpl->setVariable("TOGGLE_SIGNAL", $sig_toggle);
108  $tpl->setVariable("SUBHEADLINE", $component->getSubheadline());
109 
110  foreach ($component->getImportantFields() as $label => $value) {
111  $tpl->setCurrentBlock("important_field");
112  if (is_string($label)) {
113  $tpl->setVariable("IMPORTANT_FIELD_LABEL", $label);
114  }
115  $tpl->setVariable("IMPORTANT_FIELD_VALUE", $value);
116  $tpl->parseCurrentBlock();
117  }
118 
119  $tpl->setVariable("DESCLIST", $default_renderer->render($component->getContent()));
120 
121  $further_fields_headline = $component->getFurtherFieldsHeadline();
122  if ($further_fields_headline) {
123  $tpl->setVariable("FURTHER_FIELDS_HEADLINE", $further_fields_headline);
124  }
125 
126  foreach ($component->getFurtherFields() as $label => $value) {
127  $tpl->setCurrentBlock("further_field");
128  if (is_string($label)) {
129  $tpl->setVariable("FIELD_LABEL", $label);
130  }
131  $tpl->setVariable("FIELD_VALUE", $value);
132  $tpl->parseCurrentBlock();
133  }
134 
135  $action = $component->getAction();
136  if (!is_null($action)) {
137  $tpl->setCurrentBlock("button");
138  $tpl->setVariable("BUTTON", $default_renderer->render($action));
139  $tpl->parseCurrentBlock();
140  }
141 
142  return $tpl->get();
143  }
144 
148  public function registerResources(ResourceRegistry $registry)
149  {
150  parent::registerResources($registry);
151  $registry->register('./src/UI/templates/js/Table/presentation.js');
152  }
153 
157  protected function registerSignals(Component\Table\PresentationRow $component)
158  {
159  $show = $component->getShowSignal();
160  $close = $component->getCloseSignal();
161  $toggle = $component->getToggleSignal();
162  return $component->withAdditionalOnLoadCode(function ($id) use ($show, $close, $toggle) {
163  return
164  "$(document).on('{$show}', function() { il.UI.table.presentation.expandRow('{$id}'); return false; });" .
165  "$(document).on('{$close}', function() { il.UI.table.presentation.collapseRow('{$id}'); return false; });" .
166  "$(document).on('{$toggle}', function() { il.UI.table.presentation.toggleRow('{$id}'); return false; });";
167  });
168  }
169 }
Registry for resources required by rendered output like Javascript or CSS.
$action
checkComponent(Component $component)
Check if a given component fits this renderer and throw if that is not the case. ...
registerSignals(Component\Table\PresentationRow $component)
Definition: Renderer.php:157
renderPresentationTable(Component\Table\Presentation $component, RendererInterface $default_renderer)
Definition: Renderer.php:44
$tpl
Definition: ilias.php:10
if(!array_key_exists('StateId', $_REQUEST)) $id
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.null
Definition: Renderer.php:148
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:17
renderPresentationRow(Component\Table\PresentationRow $component, RendererInterface $default_renderer)
Definition: Renderer.php:83
$row
getTemplate($name, $purge_unfilled_vars, $purge_unused_blocks)
Get template of component this renderer is made for.
$data
Definition: bench.php:6
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.