ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 ?array $filter_data,
88 ?array $additional_parameters
89 ): \Generator {
90 $icons = [
91 $this->ui_factory->symbol()->icon()->custom('assets/images/standard/icon_checked.svg', '', 'small'),
92 $this->ui_factory->symbol()->icon()->custom('assets/images/standard/icon_unchecked.svg', '', 'small')
93 ];
94 foreach ($this->doSelect($order, $range) as $idx => $record) {
95 $row_id = (string) $record['usr_id'];
96 $record['achieve_txt'] = $record['achieve'] > 80 ? 'passed' : 'failed';
97 $record['failure_txt'] = "not " . $record["achieve_txt"];
98 $record['repeat'] = $record['achieve'] < 80;
99 $record['achieve_icon'] = $icons[(int) $record['achieve'] > 80];
100 yield $row_builder->buildDataRow($row_id, $record);
101 }
102 }
103
104 public function getTotalRowCount(
105 ?array $filter_data,
106 ?array $additional_parameters
107 ): ?int {
108 return count($this->dummyrecords());
109 }
110
111 //do the actual reading - note, that e.g. order and range are easily converted to SQL
112 protected function doSelect(Order $order, Range $range): array
113 {
114 $sql_order_part = $order->join('ORDER BY', fn(...$o) => implode(' ', $o));
115 $sql_range_part = sprintf('LIMIT %2$s OFFSET %1$s', ...$range->unpack());
116 return array_map(
117 fn($rec) => array_merge($rec, ['sql_order' => $sql_order_part, 'sql_range' => $sql_range_part]),
118 $this->dummyrecords()
119 );
120 }
121
122 //this is how the UI-Table looks - and that's usually quite close to the db-table
123 protected function getColumsForRepresentation(): array
124 {
125 $f = $this->ui_factory;
126 return [
127 'usr_id' => $f->table()->column()->number("User ID")
128 ->withIsSortable(false),
129 'login' => $f->table()->column()->text("Login")
130 ->withHighlight(true),
131 'email' => $f->table()->column()->eMail("eMail"),
132 'last' => $f->table()->column()->date("last login", $this->df->dateFormat()->germanLong()),
133 'achieve' => $f->table()->column()->status("progress")
134 ->withIsOptional(true),
135 'achieve_txt' => $f->table()->column()->status("success")
136 ->withIsSortable(false)
137 ->withIsOptional(true),
138 'failure_txt' => $f->table()->column()->status("failure")
139 ->withIsSortable(false)
140 ->withIsOptional(true, false),
141 'achieve_icon' => $f->table()->column()->statusIcon("achieved")
142 ->withIsOptional(true),
143 'repeat' => $f->table()->column()->boolean("repeat", 'yes', 'no')
144 ->withIsSortable(false),
145 'fee' => $f->table()->column()->number("Fee")
146 ->withDecimals(2)
147 ->withUnit('£', I\Column\Number::UNIT_POSITION_FORE),
148 'sql_order' => $f->table()->column()->text("sql order part")
149 ->withIsSortable(false)
150 ->withIsOptional(true),
151 'sql_range' => $f->table()->column()->text("sql range part")
152 ->withIsSortable(false)
153 ->withIsOptional(true)
154 ];
155 }
156
157 protected function dummyrecords()
158 {
159 return [
160 ['usr_id' => 123,'login' => 'superuser','email' => 'user@example.com',
161 'last' => new \DateTimeImmutable(),'achieve' => 20,'fee' => 0
162 ],
163 ['usr_id' => 867,'login' => 'student1','email' => 'student1@example.com',
164 'last' => new \DateTimeImmutable(),'achieve' => 90,'fee' => 40
165 ],
166 ['usr_id' => 8923,'login' => 'student2','email' => 'student2@example.com',
167 'last' => new \DateTimeImmutable(),'achieve' => 66,'fee' => 36.789
168 ],
169 ['usr_id' => 8748,'login' => 'student3_longname','email' => 'student3_long_email@example.com',
170 'last' => new \DateTimeImmutable(),'achieve' => 66,'fee' => 36.789
171 ]
172 ];
173 }
174}
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(?array $filter_data, ?array $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, ?array $filter_data, ?array $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