ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
with_additional_viewcontrols.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6
12use Psr\Http\Message\ServerRequestInterface;
13
32{
33 global $DIC;
34 $f = $DIC['ui.factory'];
35 $r = $DIC['ui.renderer'];
36 $df = new \ILIAS\Data\Factory();
37 $refinery = $DIC['refinery'];
38 $request = $DIC->http()->request();
39
40 $columns = [
41 'usr_id' => $f->table()->column()->number("User ID")
42 ->withIsSortable(false),
43 'login' => $f->table()->column()->text("Login")
44 ->withIsOptional(true)
45 ->withIsSortable(false),
46 'email' => $f->table()->column()->eMail("eMail")
47 ->withIsOptional(true)
48 ->withIsSortable(false),
49 ];
50
51
55 $data_retrieval = new class ($f, $r) implements I\DataRetrieval {
56 public function __construct(
57 protected \ILIAS\UI\Factory $ui_factory,
58 protected \ILIAS\UI\Renderer $ui_renderer
59 ) {
60 }
61
62 public function getRows(
63 I\DataRowBuilder $row_builder,
64 array $visible_column_ids,
66 Order $order,
67 mixed $additional_viewcontrol_data,
68 mixed $filter_data,
69 mixed $additional_parameters
70 ): \Generator {
71 $records = $this->getRecords($range, $order);
72 foreach ($records as $idx => $record) {
73 $row_id = (string) $record['usr_id'];
74
75 if (in_array('hide_login', $additional_viewcontrol_data[0])) {
76 $record['login'] = '-';
77 }
78 if (in_array('hide_mail', $additional_viewcontrol_data[0])) {
79 $record['email'] = '-';
80 }
81 yield $row_builder->buildDataRow($row_id, $record);
82 }
83 }
84
85 public function getTotalRowCount(
86 mixed $additional_viewcontrol_data,
87 mixed $filter_data,
88 mixed $additional_parameters
89 ): ?int {
90 return count($this->getRecords());
91 }
92
93 protected function getRecords(?Range $range = null, ?Order $order = null): array
94 {
95 return [
96 ['usr_id' => 123,'login' => 'superuser','email' => 'user@example.com',
97 'last' => (new \DateTimeImmutable())->modify('-1 day') ,'achieve' => 20,'fee' => 0
98 ],
99 ['usr_id' => 867,'login' => 'student1','email' => 'student1@example.com',
100 'last' => (new \DateTimeImmutable())->modify('-10 day'),'achieve' => 90,'fee' => 40
101 ],
102 ['usr_id' => 8923,'login' => 'student2','email' => 'student2@example.com',
103 'last' => (new \DateTimeImmutable())->modify('-8 day'),'achieve' => 66,'fee' => 36.789
104 ]
105 ];
106 }
107 };
108
109 $table = $f->table()
110 ->data(
111 $data_retrieval,
112 'a data table with additional view controls',
113 $columns
114 )
118 ->withAdditionalViewControl(
119 $f->input()->viewControl()->group(
120 [
121 $f->input()->viewControl()->mode([
122 'show_login' => 'show login',
123 'hide_login' => 'anon login'
124 ])
125 ->withValue('show_login'),
126
127 $f->input()->viewControl()->mode([
128 'show_mail' => 'show mails',
129 'hide_mail' => 'anon mails'
130 ])
131 ->withValue('show_mail'),
132
133 $f->input()->viewControl()->fieldSelection([
134 'opt1' => 'option 1',
135 'opt2' => 'option 2',
136 'opt3' => 'option 3',
137 ]),
138 $f->input()->viewControl()->fieldSelection([
139 'opt1' => 'option 1',
140 'opt2' => 'option 2',
141 'opt3' => 'option 3',
142 ]),
143
144 $f->input()->viewControl()->sortation([
145 'Field 1, ascending' => new Order('field1', 'ASC'),
146 'Field 1, descending' => new Order('field1', 'DESC'),
147 ]),
148 $f->input()->viewControl()->sortation([
149 'Field 1, ascending' => new Order('field1', 'ASC'),
150 'Field 1, descending' => new Order('field1', 'DESC'),
151 ]),
152
153 ]
154 )
155 )
156 ->withRequest($request);
157
158 return $r->render($table->withId('_addvc_example'));
159
160}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
Definition: UI.php:24
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26