ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
base1.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
40function base1()
41{
42 global $DIC;
43 $ui_factory = $DIC->ui()->factory();
44 $renderer = $DIC->ui()->renderer();
45 $tpl = $DIC['tpl'];
46 $target = $DIC->http()->request()->getRequestTarget();
47 $refinery = $DIC->refinery();
48 $request_wrapper = $DIC->http()->wrapper()->query();
49
50 $tpl->addCss('src/UI/examples/Table/Presentation/presentation_alignment_example.css');
51
52 //example data
54
55 //build viewcontrols
56 $aria_label = "filter entries";
57 $active_view_control = 'Alle';
58 $actions = [
59 "Alle" => $target . '&all=1',
60 "Mehr als 5 Antworten" => $target . '&all=0'
61 ];
62 if ($request_wrapper->has('all') && $request_wrapper->retrieve('all', $refinery->kindlyTo()->int()) === 0) {
63 $data = [array_shift($data)];
64 $active_view_control = 'Mehr als 5 Antworten';
65 }
66 $view_controls = array(
67 $ui_factory->viewControl()->mode($actions, $aria_label)->withActive($active_view_control)
68 );
69
70 //build an example modal
71 $modal = $ui_factory->modal()->interruptive('zur Frage', 'This is just an example', '#')
72 ->withActionButtonLabel('Go');
73
74 $mapping_closure = function ($row, $record, $ui_factory, $environment) use ($modal) {
75 return $row
76 ->withHeadline($record['question_title'])
77 ->withLeadingSymbol(
78 $ui_factory->symbol()->icon()->custom('assets/images/standard/icon_ques.svg', '')
79 )
80 ->withSubheadline($record['question_txt'])
81 ->withImportantFields(
82 array(
83 $record['type'],
84 'Beantwortet: ' => $record['stats']['total'],
85 'Häufigste Antwort: ' => $record['answers'][$record['stats']['most_common']]['title']
86 )
87 )
88 ->withContent(
89 $ui_factory->layout()->alignment()->horizontal()->dynamicallyDistributed(
90 $ui_factory->layout()->alignment()->vertical(
91 $ui_factory->listing()->descriptive([
92 'Werte' => $environment['totals']($record['answers'])
93 ]),
94 $ui_factory->listing()->descriptive([
95 'Chart' => $environment['chart']($record['answers'])
96 ])
97 ),
98 $ui_factory->listing()->descriptive([
99 '' => $environment['stats']($record)
100 ])
101 )
102 )
103 ->withAction(
104 $ui_factory->button()->standard('zur Frage', '#')
105 ->withOnClick($modal->getShowSignal())
106 );
107 };
108
109 $ptable = $ui_factory->table()->presentation(
110 'Presentation Table with Alignments', //title
111 $view_controls,
112 $mapping_closure
113 )
114 ->withEnvironment(environment());
115
116
117 //apply data to table and render
118 return $renderer->render([
119 $modal,
120 $ptable->withData($data)
121 ]);
122}
123
124function environment()
125{
126 $totals = function ($answers) {
127 $ret = '<div class="example_block content"><table>';
128 $ret .= '<tr><td></td>'
129 . '<td>Amount</td>'
130 . '<td style="padding-left: 10px;">Proportion</td></tr>';
131
132 foreach ($answers as $answer) {
133 $ret .= '<tr>'
134 . '<td style="padding-right: 10px;">' . $answer['title'] . '</td>'
135 . '<td style="text-align:right">' . $answer['amount'] . '</td>'
136 . '<td style="text-align:right">' . $answer['proportion'] . '%</td>'
137 . '</tr>';
138 }
139
140 $ret .= '</table></div>';
141 return $ret;
142 };
143
144 $chart = function ($answers) {
145 $ret = '<div class="example_block content"><table style="width:100%">';
146 foreach ($answers as $answer) {
147 $ret .= '<tr style="border-bottom: 1px solid black;">'
148 . '<td style="width: 200px;">'
149 . $answer['title']
150 . '</td><td>'
151 . '<div style="background-color:grey; height:20px; width:' . $answer['proportion'] . '%;"></div>'
152 . '</td></tr>';
153 }
154 $ret .= '</table></div>';
155 return $ret;
156 };
157
158 $stats = function ($answers) {
159 global $DIC;
160 $ui_factory = $DIC->ui()->factory();
161 $ui_renderer = $DIC->ui()->renderer();
162
163 $icon = $ui_factory->symbol()->icon()->custom('assets/images/standard/icon_ques.svg', '');
164
165 $ret = '<div class="example_block stats">';
166 $ret .= '<h5>' . $ui_renderer->render($icon) . ' ' . $answers['type'] . '</h5>';
167 $ret .= '<span class="c-stats--title">Beantwortet:</span> '
168 . $answers['stats']['total'] . '<br>'
169 . '<span class="c-stats--title">Übersprungen:</span> '
170 . $answers['stats']['skipped'] . '<br>'
171 . '<span class="c-stats--title">Häufigste Antwort:</span> '
172 . $answers['answers'][$answers['stats']['most_common']]['title'] . '<br>'
173 . '<span class="c-stats--title">Anzahl Häufigste:</span> '
174 . $answers['stats']['most_common_total'] . '<br>'
175 . '<span class="c-stats--title">Median:</span> '
176 . $answers['answers'][$answers['stats']['median']]['title'];
177 $ret .= '</div>';
178 return $ret;
179 };
180
181 return array(
182 'totals' => $totals,
183 'chart' => $chart,
184 'stats' => $stats
185 );
186}
187
189{
190 return array(
191 array(
192 'type' => 'Single Choice Frage',
193 'question_title' => 'Belastbarkeit',
194 'question_txt' => 'Wie ausgeprägt ist die Belastbarkeit des / der Auszubildenden?',
195 'answers' => array(
196 array('title' => 'weniger ausgeprägt', 'amount' => 2, 'proportion' => 20),
197 array('title' => 'teilweise ausgeprägt', 'amount' => 0, 'proportion' => 0),
198 array('title' => 'ausgeprägt', 'amount' => 6, 'proportion' => 60),
199 array('title' => 'deutlich ausgeprägt', 'amount' => 1, 'proportion' => 10),
200 array('title' => 'stark ausgeprägt', 'amount' => 0, 'proportion' => 0),
201 array('title' => 'sehr stark ausgeprägt', 'amount' => 0, 'proportion' => 0),
202 array('title' => 'übermäßig ausgeprägt', 'amount' => 1, 'proportion' => 10)
203 ),
204 'stats' => array(
205 'total' => 10,
206 'skipped' => 2,
207 'most_common' => 2,
208 'most_common_total' => 6,
209 'median' => 2,
210 )
211 ),
212
213 array(
214 'type' => 'Single Choice Frage',
215 'question_title' => 'Dialogfähigkeit, Kundenorientierung, Beratungsfähigkeit',
216 'question_txt' => 'Wie ausgeprägt ist die Dialogfähigkeit, Kundenorientierung und Beratungsfähigkeit des / der Auszubildenden?',
217 'answers' => array(
218 array('title' => 'weniger ausgeprägt', 'amount' => 0, 'proportion' => 0),
219 array('title' => 'teilweise ausgeprägt', 'amount' => 1, 'proportion' => 100),
220 array('title' => 'ausgeprägt', 'amount' => 0, 'proportion' => 0),
221 array('title' => 'deutlich ausgeprägt', 'amount' => 0, 'proportion' => 0),
222 array('title' => 'stark ausgeprägt', 'amount' => 0, 'proportion' => 0),
223 array('title' => 'sehr stark ausgeprägt', 'amount' => 0, 'proportion' => 0),
224 array('title' => 'übermäßig ausgeprägt', 'amount' => 0, 'proportion' => 0)
225 ),
226 'stats' => array(
227 'total' => 1,
228 'skipped' => 0,
229 'most_common' => 1,
230 'most_common_total' => 1,
231 'median' => 1,
232 )
233 ),
234 );
235}
$renderer
withAction(URI|Signal|string $action)
global $DIC
Definition: shib_login.php:26