ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
DataRetrieval.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use Generator;
25use ilDateTime;
31use ilSCTask;
32use ilSCTasks;
34use ilSCUtils;
35
37{
39 protected array $sc_tasks;
41 protected array $actions;
42
43 public function __construct(
44 protected readonly int $group_id
45 ) {
46 }
47
51 final public function getSCTasks(): array
52 {
53 if (isset($this->sc_tasks)) {
54 return $this->sc_tasks;
55 }
56
57 $this->sc_tasks = [];
58 foreach (ilSCTasks::getInstanceByGroupId($this->group_id)->getTasks() as $task) {
59 if (!$task->isActive()) {
60 continue;
61 }
62 $this->sc_tasks[$task->getId()] = $task;
63 }
64 return $this->sc_tasks;
65 }
66
67 final public function getRows(
68 DataRowBuilder $row_builder,
69 array $visible_column_ids,
71 Order $order,
72 mixed $additional_viewcontrol_data,
73 mixed $filter_data,
74 mixed $additional_parameters
75 ): Generator {
76 [$column_name, $direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
77 $titles = $descriptions = $last_updates = $status = [];
78 foreach ($this->getSCTasks() as $task) {
79 $task_handler = ilSCComponentTaskFactory::getComponentTask($task->getId());
80 $titles[$task->getId()] = $task_handler->getTitle();
81 $descriptions[$task->getId()] = $task_handler->getDescription();
82 $last_updates[$task->getId()] = $task->getLastUpdate();
83 $status[$task->getId()] = $task->getStatus();
84 }
85 $comparator = match ($column_name) {
86 Handler::TABLE_COL_TITLE => function (ilSCTask $f1, ilSCTask $f2) use ($titles) {
87 return strcasecmp($titles[$f1->getId()], $titles[$f2->getId()]);
88 },
89 Handler::TABLE_COL_DESCRIPTION => function (ilSCTask $f1, ilSCTask $f2) use ($descriptions) {
90 return strcasecmp($descriptions[$f1->getId()], $descriptions[$f2->getId()]);
91 },
92 Handler::TABLE_COL_LAST_UPDATE => function (ilSCTask $f1, ilSCTask $f2) use ($last_updates) {
93 if (ilDateTime::_equals($last_updates[$f1->getId()], $last_updates[$f2->getId()])) {
94 return 0;
95 }
96 return ilDateTime::_before($last_updates[$f1->getId()], $last_updates[$f2->getId()]) ? -1 : 1;
97 },
98 Handler::TABLE_COL_STATUS => function (ilSCTask $f1, ilSCTask $f2) use ($status) {
99 return $status[$f1->getId()] - $status[$f2->getId()];
100 },
101 default => fn(ilSCTask $f1, ilSCTask $f2) => 0
102 };
103 $sc_tasks = $this->getSCTasks();
104 uasort($sc_tasks, $comparator);
105 if ($direction === "DESC") {
106 $sc_tasks = array_reverse($sc_tasks, true);
107 }
108 $sc_tasks = array_slice($sc_tasks, $range->getStart(), $range->getLength(), true);
109 foreach ($sc_tasks as $sc_task) {
110 $data_row = $row_builder->buildDataRow(
111 (string) $sc_task->getId(),
112 [
113 Handler::TABLE_COL_TITLE => $titles[$sc_task->getId()],
114 Handler::TABLE_COL_DESCRIPTION => $descriptions[$sc_task->getId()],
115 Handler::TABLE_COL_LAST_UPDATE => ilDatePresentation::formatDate($last_updates[$sc_task->getId()]),
116 Handler::TABLE_COL_STATUS => ilSCUtils::taskStatus2Text($status[$sc_task->getId()])
117 ]
118 );
119 foreach ($this->getInactiveActions($sc_task) as $action_name) {
120 $data_row = $data_row->withDisabledAction($action_name);
121 }
122 yield $data_row;
123 }
124 }
125
126 final public function getTotalRowCount(
127 mixed $additional_viewcontrol_data,
128 mixed $filter_data,
129 mixed $additional_parameters
130 ): ?int {
131 return count($this->getSCTasks());
132 }
133
135 final public function getAllActions(): array
136 {
137 if (isset($this->actions)) {
138 return $this->actions;
139 }
140 $this->actions = [];
141 foreach ($this->getSCTasks() as $task) {
142 $task_gui = ilSCComponentTaskFactory::getComponentTask($task->getId());
143 foreach ($task_gui->getActions() as $action) {
144 $this->actions[$action['command']] = $action['txt'];
145 }
146 }
147 return $this->actions;
148 }
149
150 final protected function getInactiveActions(
151 ilSCTask $task
152 ): array {
153 $active_actions = [];
155 foreach ($task_gui->getActions() as $action) {
156 $active_actions[$action['command']] = $action['txt'];
157 }
158 return array_diff(array_keys($this->getAllActions()), array_keys($active_actions));
159 }
160}
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
__construct(protected readonly int $group_id)
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(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....
Class for date presentation.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
static _equals(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check if two date are equal.
static _before(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
Defines a system check task.
Description of class.
static getInstanceByGroupId(int $a_group_id)
Handles tree tasks.
Utilities for system check.
static taskStatus2Text(int $a_status)
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)