ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
repo_implementation.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
35{
48 global $DIC;
49 $r = $DIC['ui.renderer'];
50
51 $repo = new DataTableDemoRepo();
52 $table = $repo->getTableForRepresentation();
53
54 return $r->render(
55 $table->withRequest($DIC->http()->request())
56 );
57}
58
60{
61 protected \ILIAS\UI\Factory $ui_factory;
62 protected \ILIAS\Data\Factory $df;
63
64 public function __construct()
65 {
66 global $DIC;
67 $this->ui_factory = $DIC['ui.factory'];
68 $this->df = new \ILIAS\Data\Factory();
69 }
70
71 //the repo is capable of building its table-view (similar to forms from a repo)
73 {
74 return $this->ui_factory->table()->data(
75 $this,
76 'a data table from a repository',
78 );
79 }
80
81 //implementation of DataRetrieval - accept params and yield rows
82 public function getRows(
83 I\DataRowBuilder $row_builder,
84 array $visible_column_ids,
86 Order $order,
87 mixed $additional_viewcontrol_data,
88 mixed $filter_data,
89 mixed $additional_parameters
90 ): \Generator {
91 $icons = [
92 $this->ui_factory->symbol()->icon()->custom('assets/images/standard/icon_checked.svg', '', 'small'),
93 $this->ui_factory->symbol()->icon()->custom('assets/images/standard/icon_unchecked.svg', '', 'small')
94 ];
95 foreach ($this->doSelect($order, $range) as $idx => $record) {
96 $row_id = (string) $record['usr_id'];
97 $record['achieve_txt'] = $record['achieve'] > 80 ? 'passed' : 'failed';
98 $record['failure_txt'] = "not " . $record["achieve_txt"];
99 $record['repeat'] = $record['achieve'] < 80;
100 $record['achieve_icon'] = $icons[(int) $record['achieve'] > 80];
101 yield $row_builder->buildDataRow($row_id, $record);
102 }
103 }
104
105 public function getTotalRowCount(
106 mixed $additional_viewcontrol_data,
107 mixed $filter_data,
108 mixed $additional_parameters
109 ): ?int {
110 return count($this->dummyrecords());
111 }
112
113 //do the actual reading - note, that e.g. order and range are easily converted to SQL
114 protected function doSelect(Order $order, Range $range): array
115 {
116 $sql_order_part = $order->join('ORDER BY', fn(...$o) => implode(' ', $o));
117 $sql_range_part = sprintf('LIMIT %2$s OFFSET %1$s', ...$range->unpack());
118 return array_map(
119 fn($rec) => array_merge($rec, ['sql_order' => $sql_order_part, 'sql_range' => $sql_range_part]),
120 $this->dummyrecords()
121 );
122 }
123
124 //this is how the UI-Table looks - and that's usually quite close to the db-table
125 protected function getColumsForRepresentation(): array
126 {
127 $f = $this->ui_factory;
128 return [
129 'usr_id' => $f->table()->column()->number("User ID")
130 ->withIsSortable(false),
131 'login' => $f->table()->column()->text("Login")
132 ->withHighlight(true),
133 'email' => $f->table()->column()->eMail("eMail"),
134 'last' => $f->table()->column()->date("last login", $this->df->dateFormat()->germanLong()),
135 'achieve' => $f->table()->column()->status("progress")
136 ->withIsOptional(true),
137 'achieve_txt' => $f->table()->column()->status("success")
138 ->withIsSortable(false)
139 ->withIsOptional(true),
140 'failure_txt' => $f->table()->column()->status("failure")
141 ->withIsSortable(false)
142 ->withIsOptional(true, false),
143 'achieve_icon' => $f->table()->column()->statusIcon("achieved")
144 ->withIsOptional(true),
145 'repeat' => $f->table()->column()->boolean("repeat", 'yes', 'no')
146 ->withIsSortable(false),
147 'fee' => $f->table()->column()->number("Fee")
148 ->withDecimals(2)
149 ->withUnit('£', I\Column\Number::UNIT_POSITION_FORE),
150 'sql_order' => $f->table()->column()->text("sql order part")
151 ->withIsSortable(false)
152 ->withIsOptional(true),
153 'sql_range' => $f->table()->column()->text("sql range part")
154 ->withIsSortable(false)
155 ->withIsOptional(true)
156 ];
157 }
158
159 protected function dummyrecords()
160 {
161 return [
162 ['usr_id' => 123,'login' => 'superuser','email' => 'user@example.com',
163 'last' => new \DateTimeImmutable(),'achieve' => 20,'fee' => 0
164 ],
165 ['usr_id' => 867,'login' => 'student1','email' => 'student1@example.com',
166 'last' => new \DateTimeImmutable(),'achieve' => 90,'fee' => 40
167 ],
168 ['usr_id' => 8923,'login' => 'student2','email' => 'student2@example.com',
169 'last' => new \DateTimeImmutable(),'achieve' => 66,'fee' => 36.789
170 ],
171 ['usr_id' => 8748,'login' => 'student3_longname','email' => 'student3_long_email@example.com',
172 'last' => new \DateTimeImmutable(),'achieve' => 66,'fee' => 36.789
173 ]
174 ];
175 }
176}
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
join($init, callable $fn)
Definition: Order.php:75
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
getTotalRowCount(mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
getRows(I\DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
Definition: UI.php:24
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26