ILIAS  release_7 Revision v7.30-3-g800a261c036
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
9use ILIAS\UI\Renderer as RendererInterface;
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
33 protected function renderPresentationTable(Component\Table\Presentation $component, RendererInterface $default_renderer)
34 {
35 $tpl = $this->getTemplate("tpl.presentationtable.html", true, true);
36
37 $tpl->setVariable("TITLE", $component->getTitle());
38
39 $vcs = $component->getViewControls();
40 if ($vcs) {
41 $tpl->touchBlock("viewcontrols");
42 foreach ($vcs as $vc) {
43 $tpl->setCurrentBlock("vc");
44 $tpl->setVariable("VC", $default_renderer->render($vc));
45 $tpl->parseCurrentBlock();
46 }
47 }
48
49 $row_mapping = $component->getRowMapping();
50 $data = $component->getData();
51 foreach ($data as $record) {
52 $row = $row_mapping(
53 new PresentationRow($component->getSignalGenerator()),
54 $record,
55 $this->getUIFactory(),
56 $component->getEnvironment()
57 );
58
59 $tpl->setCurrentBlock("row");
60 $tpl->setVariable("ROW", $default_renderer->render($row));
61 $tpl->parseCurrentBlock();
62 }
63
64 return $tpl->get();
65 }
66
72 protected function renderPresentationRow(Component\Table\PresentationRow $component, RendererInterface $default_renderer)
73 {
74 $f = $this->getUIFactory();
75 $tpl = $this->getTemplate("tpl.presentationrow.html", true, true);
76
77 $component = $this->registerSignals($component->withResetSignals());
78 $sig_show = $component->getShowSignal();
79 $sig_hide = $component->getCloseSignal();
80 $sig_toggle = $component->getToggleSignal();
81 $id = $this->bindJavaScript($component);
82
83 $expander = $f->symbol()->glyph()->expand("#")
84 ->withOnClick($sig_show);
85 $collapser = $f->symbol()->glyph()->collapse("#")
86 ->withOnClick($sig_hide);
87 $shy_expander = $f->button()->shy($this->txt("presentation_table_more"), "#")
88 ->withOnClick($sig_show);
89
90 $tpl->setVariable("ID", $id);
91 $tpl->setVariable("EXPANDER", $default_renderer->render($expander));
92 $tpl->setVariable("COLLAPSER", $default_renderer->render($collapser));
93 $tpl->setVariable("SHY_EXPANDER", $default_renderer->render($shy_expander));
94
95 $tpl->setVariable("HEADLINE", $component->getHeadline());
96 $tpl->setVariable("TOGGLE_SIGNAL", $sig_toggle);
97 $tpl->setVariable("SUBHEADLINE", $component->getSubheadline());
98
99 foreach ($component->getImportantFields() as $label => $value) {
100 $tpl->setCurrentBlock("important_field");
101 if (is_string($label)) {
102 $tpl->setVariable("IMPORTANT_FIELD_LABEL", $label);
103 }
104 $tpl->setVariable("IMPORTANT_FIELD_VALUE", $value);
105 $tpl->parseCurrentBlock();
106 }
107
108 $tpl->setVariable("DESCLIST", $default_renderer->render($component->getContent()));
109
110 $further_fields_headline = $component->getFurtherFieldsHeadline();
111 if ($further_fields_headline) {
112 $tpl->setVariable("FURTHER_FIELDS_HEADLINE", $further_fields_headline);
113 }
114
115 foreach ($component->getFurtherFields() as $label => $value) {
116 $tpl->setCurrentBlock("further_field");
117 if (is_string($label)) {
118 $tpl->setVariable("FIELD_LABEL", $label);
119 }
120 $tpl->setVariable("FIELD_VALUE", $value);
121 $tpl->parseCurrentBlock();
122 }
123
124 $action = $component->getAction();
125 if (!is_null($action)) {
126 $tpl->setCurrentBlock("button");
127 $tpl->setVariable("BUTTON", $default_renderer->render($action));
128 $tpl->parseCurrentBlock();
129 }
130
131 return $tpl->get();
132 }
133
137 public function registerResources(ResourceRegistry $registry)
138 {
139 parent::registerResources($registry);
140 $registry->register('./src/UI/templates/js/Table/presentation.js');
141 }
142
146 protected function registerSignals(Component\Table\PresentationRow $component)
147 {
148 $show = $component->getShowSignal();
149 $close = $component->getCloseSignal();
150 $toggle = $component->getToggleSignal();
151 return $component->withAdditionalOnLoadCode(function ($id) use ($show, $close, $toggle) {
152 return
153 "$(document).on('{$show}', function() { il.UI.table.presentation.expandRow('{$id}'); return false; });" .
154 "$(document).on('{$close}', function() { il.UI.table.presentation.collapseRow('{$id}'); return false; });" .
155 "$(document).on('{$toggle}', function() { il.UI.table.presentation.toggleRow('{$id}'); return false; });";
156 });
157 }
158
159
163 protected function getComponentInterfaceName()
164 {
165 return array(
166 Component\Table\PresentationRow::class,
167 Component\Table\Presentation::class
168 );
169 }
170}
An exception for terminatinating execution or to throw for unit testing.
registerSignals(Component\Table\PresentationRow $component)
Definition: Renderer.php:146
getComponentInterfaceName()
Get the name of the component-interface this renderer is supposed to render.ATTENTION: Fully qualifie...
Definition: Renderer.php:163
renderPresentationRow(Component\Table\PresentationRow $component, RendererInterface $default_renderer)
Definition: Renderer.php:72
renderPresentationTable(Component\Table\Presentation $component, RendererInterface $default_renderer)
Definition: Renderer.php:33
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:17
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.null
Definition: Renderer.php:137
getTemplate($name, $purge_unfilled_vars, $purge_unused_blocks)
Get template of component this renderer is made for.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.
checkComponent(Component $component)
Check if a given component fits this renderer and throw \LogicError if that is not the case.
A component is the most general form of an entity in the UI.
Definition: Component.php:14
Registry for resources required by rendered output like Javascript or CSS.
An entity that renders components to a string output.
Definition: Renderer.php:15
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$data
Definition: storeScorm.php:23