ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
DataRetrieval.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use DateTimeImmutable;
24use Generator;
32use ilLink;
33use ilObject;
35use ilObjUser;
37use ilTimingUser;
38
40{
41 protected const string KEY_SUGGESTION = 'suggestion';
42 protected const string KEY_PLANNED = 'planned';
43 protected const string KEY_ROW_ID = 'row_id';
44 protected const string KEY_TITLE_LINK = 'title_link';
45 protected const string KEY_TITLE = 'title';
46 protected const string OBJECT_GROUP_TYPE = 'obgr';
47 protected array $rows;
48 protected string $username;
49
50 public function __construct(
51 protected readonly UIServices $ui,
52 protected readonly ilObjUser $user,
53 protected readonly int $user_id,
54 protected readonly int $parent_object_ref_id,
55 ) {
56 $this->initRows();
57 }
58
59 final protected function initRows(): void
60 {
61 if (isset($this->rows)) {
62 return;
63 }
64 $this->rows = [];
65 $items = ilObjectActivation::getItems($this->parent_object_ref_id, false);
66 foreach ($items as $item) {
67 // hide objects without timings
68 if ($item['timing_type'] != ilObjectActivation::TIMINGS_PRESETTING) {
69 continue;
70 }
71 // no object groups
72 if ($item['type'] == self::OBJECT_GROUP_TYPE) {
73 continue;
74 }
75 # Title
77 $title = (
78 count($sess_values) > 0 &&
79 $item['type'] == 'sess' &&
80 !strlen($item['title'])
81 )
83 $sess_values['start'],
84 $sess_values['end'],
85 (bool) $sess_values['fullday']
86 )
87 : $item['title'];
88
89 # Title Link
90 $title_link = (in_array($item['type'], ['fold', 'grp', 'sess']))
91 ? ilLink::_getLink($item['ref_id'], $item['type'])
92 : '';
93
94 # Suggested Timing
95 $suggested = [
96 DateTimeImmutable::createFromTimestamp($item['suggestion_start']),
97 DateTimeImmutable::createFromTimestamp($item['suggestion_end']),
98 ];
99
100 # Planned Timing
101 $timing_user = new ilTimingUser($item['child'], $this->user_id);
102
103 $planned = (
104 ((int) $item['timing_type']) === ilObjectActivation::TIMINGS_PRESETTING &&
105 !is_null($timing_user->getStart()->get(IL_CAL_UNIX)) &&
106 !is_null($timing_user->getEnd()->get(IL_CAL_UNIX))
107 )
108 ? [
109 DateTimeImmutable::createFromTimestamp($timing_user->getStart()->get(IL_CAL_UNIX)),
110 DateTimeImmutable::createFromTimestamp($timing_user->getEnd()->get(IL_CAL_UNIX))
111 ]
112 : $suggested;
113
114 $this->rows[] = [
115 self::KEY_ROW_ID => $item['ref_id'],
116 self::KEY_TITLE => $title,
117 self::KEY_TITLE_LINK => $title_link,
118 self::KEY_PLANNED => $planned,
119 self::KEY_SUGGESTION => $suggested,
120 ];
121 }
122 }
123
124 final public function getRows(
125 DataRowBuilder $row_builder,
126 array $visible_column_ids,
128 Order $order,
129 mixed $additional_viewcontrol_data,
130 mixed $filter_data,
131 mixed $additional_parameters
132 ): Generator {
133 [$column_name, $direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
134 $comparator = match ($column_name) {
135 HandlerInterface::TABLE_COL_TITLE => fn(array $a, array $b) => strcmp($a[self::KEY_TITLE], $b[self::KEY_TITLE]),
137 default => fn(array $a, array $b) => 0
138 };
140 uasort($rows, $comparator);
141 if ($direction === "DESC") {
142 $rows = array_reverse($rows, true);
143 }
144 $rows = array_slice($rows, $range->getStart(), $range->getLength(), true);
145 foreach ($rows as $row) {
146 yield $row_builder->buildDataRow(
147 $row[self::KEY_ROW_ID] . '',
148 [
149 HandlerInterface::TABLE_COL_TITLE => $this->ui->factory()->link()->standard(
150 $row[self::KEY_TITLE],
151 $row[self::KEY_TITLE_LINK]
152 )
153 ->withDisabled(strcmp($row[self::KEY_TITLE_LINK], '') === 0),
154 HandlerInterface::TABLE_COL_SUGGESTION => $row[self::KEY_SUGGESTION],
155 HandlerInterface::TABLE_COL_TIMINGS_PLANNED => $row[self::KEY_PLANNED],
156 ]
157 );
158 }
159 }
160
161 final public function getTotalRowCount(
162 mixed $additional_viewcontrol_data,
163 mixed $filter_data,
164 mixed $additional_parameters
165 ): ?int {
166 return count($this->rows);
167 }
168
169 final public function getUsername(): string
170 {
171 if (!isset($this->username)) {
172 $name = ilObjUser::_lookupName($this->user_id);
173 $this->username = $name['lastname'] . ', ' . $name['firstname'];
174 }
175 return $this->username;
176 }
177
178 final public function getDateFormat(): DateFormat
179 {
180 return $this->user->getDateFormat();
181 }
182}
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...
__construct(protected readonly UIServices $ui, protected readonly ilObjUser $user, protected readonly int $user_id, protected readonly int $parent_object_ref_id,)
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
This is called by the table to retrieve rows; map data-records to rows using the $row_builder e....
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
A Date Format provides a format definition akin to PHP's date formatting options, but stores the sing...
Definition: DateFormat.php:28
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
const IL_CAL_UNIX
User class.
static _lookupName(int $a_user_id)
Class ilObjectActivation.
static getItems(int $parent_id, bool $with_list_data=true)
Get sub item data.
Class ilObject Basic functions for all objects.
static _lookupObjId(int $ref_id)
class ilSessionAppointment
static _lookupAppointment(int $a_obj_id)
static _appointmentToString(int $start, int $end, bool $fulltime)
TableGUI class for timings administration.
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', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildDataRow(string $id, array $record)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples