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