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