ILIAS  release_8 Revision v8.24
repo_implementation.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6
11
13{
26 global $DIC;
27 $r = $DIC['ui.renderer'];
28
29 $repo = new DataTableDemoRepo();
30 $table = $repo->getTableForRepresentation();
31
32 return $r->render(
33 $table->withRequest($DIC->http()->request())
34 );
35}
36
38{
39 protected \ILIAS\UI\Factory $ui_factory;
40 protected \ILIAS\Data\Factory $df;
41
42 public function __construct()
43 {
44 global $DIC;
45 $this->ui_factory = $DIC['ui.factory'];
46 $this->df = new \ILIAS\Data\Factory();
47 }
48
49 //the repo is capable of building its table-view (similar to forms from a repo)
51 {
52 return $this->ui_factory->table()->data(
53 'a data table from a repository',
55 $this
56 );
57 }
58
59 //implementation of DataRetrieval - accept params and yield rows
60 public function getRows(
61 I\DataRowBuilder $row_builder,
62 array $visible_column_ids,
63 Range $range,
64 Order $order,
65 ?array $filter_data,
66 ?array $additional_parameters
67 ): \Generator {
68 $icons = [
69 $this->ui_factory->symbol()->icon()->custom('templates/default/images/standard/icon_checked.svg', '', 'small'),
70 $this->ui_factory->symbol()->icon()->custom('templates/default/images/standard/icon_unchecked.svg', '', 'small')
71 ];
72 foreach ($this->doSelect($order, $range) as $idx => $record) {
73 $row_id = (string)$record['usr_id'];
74 $record['achieve_txt'] = $record['achieve'] > 80 ? 'passed' : 'failed';
75 $record['failure_txt'] = "not " . $record["achieve_txt"];
76 $record['repeat'] = $record['achieve'] < 80;
77 $record['achieve_icon'] = $icons[(int) $record['achieve'] > 80];
78 yield $row_builder->buildDataRow($row_id, $record);
79 }
80 }
81
82 public function getTotalRowCount(
83 ?array $filter_data,
84 ?array $additional_parameters
85 ): ?int {
86 return count($this->dummyrecords());
87 }
88
89 //do the actual reading - note, that e.g. order and range are easily converted to SQL
90 protected function doSelect(Order $order, Range $range): array
91 {
92 $sql_order_part = $order->join('ORDER BY', fn (...$o) => implode(' ', $o));
93 $sql_range_part = sprintf('LIMIT %2$s OFFSET %1$s', ...$range->unpack());
94 return array_map(
95 fn ($rec) => array_merge($rec, ['sql_order' => $sql_order_part, 'sql_range' => $sql_range_part]),
96 $this->dummyrecords()
97 );
98 }
99
100 //this is how the UI-Table looks - and that's usually quite close to the db-table
101 protected function getColumsForRepresentation(): array
102 {
103 $f = $this->ui_factory;
104 return [
105 'usr_id' => $f->table()->column()->number("User ID")
106 ->withIsSortable(false),
107 'login' => $f->table()->column()->text("Login")
108 ->withHighlight(true),
109 'email' => $f->table()->column()->eMail("eMail"),
110 'last' => $f->table()->column()->date("last login", $this->df->dateFormat()->germanLong()),
111 'achieve' => $f->table()->column()->status("progress")
112 ->withIsOptional(true),
113 'achieve_txt' => $f->table()->column()->status("success")
114 ->withIsSortable(false)
115 ->withIsOptional(true),
116 'failure_txt' => $f->table()->column()->status("failure")
117 ->withIsSortable(false)
118 ->withIsOptional(true, false),
119 'achieve_icon' => $f->table()->column()->statusIcon("achieved")
120 ->withIsOptional(true),
121 'repeat' => $f->table()->column()->boolean("repeat", 'yes', 'no')
122 ->withIsSortable(false),
123 'fee' => $f->table()->column()->number("Fee")
124 ->withDecimals(2)
125 ->withUnit('£', I\Column\Number::UNIT_POSITION_FORE),
126 'sql_order' => $f->table()->column()->text("sql order part")
127 ->withIsSortable(false)
128 ->withIsOptional(true),
129 'sql_range' => $f->table()->column()->text("sql range part")
130 ->withIsSortable(false)
131 ->withIsOptional(true)
132 ];
133 }
134
135 protected function dummyrecords()
136 {
137 return [
138 ['usr_id' => 123,'login' => 'superuser','email' => 'user@example.com',
139 'last' => new \DateTimeImmutable(),'achieve' => 20,'fee' => 0
140 ],
141 ['usr_id' => 867,'login' => 'student1','email' => 'student1@example.com',
142 'last' => new \DateTimeImmutable(),'achieve' => 90,'fee' => 40
143 ],
144 ['usr_id' => 8923,'login' => 'student2','email' => 'student2@example.com',
145 'last' => new \DateTimeImmutable(),'achieve' => 66,'fee' => 36.789
146 ],
147 ['usr_id' => 8748,'login' => 'student3_longname','email' => 'student3_long_email@example.com',
148 'last' => new \DateTimeImmutable(),'achieve' => 66,'fee' => 36.789
149 ]
150 ];
151 }
152}
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:13
join($init, callable $fn)
Definition: Order.php:59
A simple class to express a range of whole positive numbers.
Definition: Range.php:31
getTotalRowCount(?array $filter_data, ?array $additional_parameters)
getRows(I\DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.