3 declare(strict_types=1);
23 $f = $DIC[
'ui.factory'];
24 $r = $DIC[
'ui.renderer'];
25 $df = new \ILIAS\Data\Factory();
27 $request = $DIC->http()->request();
35 'usr_id' =>
$f->table()->column()->number(
"User ID")
36 ->withIsSortable(
false),
37 'login' =>
$f->table()->column()->text(
"Login")
38 ->withHighlight(
true),
39 'email' =>
$f->table()->column()->eMail(
"eMail"),
40 'last' =>
$f->table()->column()->date(
"last login", $df->dateFormat()->germanLong()),
41 'achieve' =>
$f->table()->column()->statusIcon(
"progress")
42 ->withIsOptional(
true),
43 'achieve_txt' =>
$f->table()->column()->status(
"success")
44 ->withIsSortable(
true)
45 ->withIsOptional(
true,
false),
46 'repeat' =>
$f->table()->column()->boolean(
"repeat",
'yes',
'no')
47 ->withIsSortable(
false),
48 'fee' =>
$f->table()->column()->number(
"Fee")
50 ->withUnit(
'£',
I\Column\Number::UNIT_POSITION_FORE)
51 ->withOrderingLabels(
'cheapest first',
'most expensive first'),
52 'failure_txt' =>
$f->table()->column()->status(
"failure")
53 ->withIsSortable(
false)
54 ->withIsOptional(
true,
false),
66 $here_uri = $df->uri($DIC->http()->request()->getUri()->__toString());
73 $query_params_namespace = [
'datatable',
'example'];
81 list($url_builder, $action_parameter_token, $row_id_token) =
82 $url_builder->acquireParameters(
83 $query_params_namespace,
92 'edit' =>
$f->table()->action()->single(
96 $url_builder->withParameter($action_parameter_token,
"edit"),
100 'compare' =>
$f->table()->action()->multi(
102 $url_builder->withParameter($action_parameter_token,
"compare"),
106 $f->table()->action()->standard(
108 $url_builder->withParameter($action_parameter_token,
"delete"),
119 $f->table()->action()->standard(
121 $url_builder->withParameter($action_parameter_token,
"info"),
145 public function getRows(
147 array $visible_column_ids,
151 ?array $additional_parameters
153 $records = $this->getRecords($range, $order);
154 foreach ($records as $idx => $record) {
155 $row_id = (string) $record[
'usr_id'];
156 $record[
'achieve_txt'] = $record[
'achieve'] > 80 ?
'passed' :
'failed';
157 $record[
'failure_txt'] =
"not " . $record[
"achieve_txt"];
158 $record[
'repeat'] = $record[
'achieve'] < 80;
161 $this->ui_factory->symbol()->icon()->custom(
'assets/images/standard/icon_checked.svg',
'',
'small'),
162 $this->ui_factory->symbol()->icon()->custom(
'assets/images/standard/icon_unchecked.svg',
'',
'small'),
163 $this->ui_factory->symbol()->icon()->custom(
'assets/images/standard/icon_x.svg',
'',
'small'),
166 if ($record[
'achieve'] > 80) {
169 if ($record[
'achieve'] < 30) {
172 $record[
'achieve'] = $icon;
174 yield $row_builder->buildDataRow($row_id, $record)
176 ->withDisabledAction(
'delete', ($record[
'login'] ===
'superuser'));
180 public function getTotalRowCount(
182 ?array $additional_parameters
184 return count($this->getRecords());
187 protected function getRecords(
Range $range = null,
Order $order = null): array
190 [
'usr_id' => 123,
'login' =>
'superuser',
'email' =>
'user@example.com',
191 'last' => (new \DateTimeImmutable())->modify(
'-1 day') ,
'achieve' => 20,
'fee' => 0
193 [
'usr_id' => 867,
'login' =>
'student1',
'email' =>
'student1@example.com',
194 'last' => (new \DateTimeImmutable())->modify(
'-10 day'),
'achieve' => 90,
'fee' => 40
196 [
'usr_id' => 8923,
'login' =>
'student2',
'email' =>
'student2@example.com',
197 'last' => (new \DateTimeImmutable())->modify(
'-8 day'),
'achieve' => 66,
'fee' => 36.789
199 [
'usr_id' => 8748,
'login' =>
'student3_longname',
'email' =>
'student3_long_email@example.com',
200 'last' => (new \DateTimeImmutable())->modify(
'-300 day'),
'achieve' => 8,
'fee' => 36.789
202 [
'usr_id' => 8749,
'login' =>
'studentAB',
'email' =>
'studentAB@example.com',
203 'last' => (new \DateTimeImmutable())->modify(
'-7 day'),
'achieve' => 100,
'fee' => 114
205 [
'usr_id' => 8750,
'login' =>
'student5',
'email' =>
'student5@example.com',
206 'last' => new \DateTimeImmutable(),
'achieve' => 76,
'fee' => 3.789
208 [
'usr_id' => 8751,
'login' =>
'student6',
'email' =>
'student6@example.com',
209 'last' => (new \DateTimeImmutable())->modify(
'-2 day'),
'achieve' => 66,
'fee' => 67
213 list($order_field, $order_direction) = $order->
join([], fn($ret, $key, $value) => [$key, $value]);
214 usort($records, fn(
$a,
$b) =>
$a[$order_field] <=>
$b[$order_field]);
215 if ($order_direction ===
'DESC') {
216 $records = array_reverse($records);
233 ->data(
'a data table', $columns, $data_retrieval)
234 ->withId(
'example_base')
235 ->withActions($actions)
239 ->withRange(
new Range(0, 2))
240 ->withOrder(
new Order(
'achieve', Order::DESC))
242 ->withRequest($request);
253 $query = $DIC->http()->wrapper()->query();
254 if ($query->has($action_parameter_token->getName())) {
255 $action = $query->retrieve($action_parameter_token->getName(),
$refinery->to()->string());
257 $ids = $query->retrieve($row_id_token->getName(),
$refinery->custom()->transformation(fn($v) => $v));
258 $listing =
$f->listing()->characteristicValue()->text([
259 'table_action' => $action,
260 'id' => print_r($ids,
true),
264 if ($action ===
'delete') {
266 foreach ($ids as
$id) {
267 $items[] =
$f->modal()->interruptiveItem()->keyValue($id, $row_id_token->getName(),
$id);
269 echo(
$r->renderAsync([
270 $f->modal()->interruptive(
272 'You are about to delete items!',
274 )->withAffectedItems($items)
275 ->withAdditionalOnLoadCode(
static fn($id):
string =>
"console.log('ASYNC JS');")
279 if ($action ===
'info') {
281 $r->render(
$f->messageBox()->info(
'an info message: <br><li>' . implode(
'<li>', $ids)))
282 .
'<script data-replace-marker="script">console.log("ASYNC JS, too");</script>' 288 $out[] =
$f->divider()->horizontal();
join($init, callable $fn)
Interface Observer Contains several chained tasks and infos about them.
Both the subject and the direction need to be specified when expressing an order. ...
This is how the factory for UI elements looks.
__construct()
Constructor setup ILIAS global object public.
base()
expected output: > ILIAS shows the rendered Component.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
A simple class to express a naive range of whole positive numbers.