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
24use ILIAS\UI\Component\Table\DataRetrieval as DataRetrievalInterface;
25use ILIAS\UI\Factory as UIFactory;
26use ILIAS\UI\Renderer as UIRenderer;
30use ilObjPoll;
31use ilLanguage;
32use Generator;
33use ilUtil;
34
35class DataRetrieval implements DataRetrievalInterface
36{
37 protected array $data;
38
39 public function __construct(
40 protected ilObjPoll $poll,
41 protected UIFactory $ui_factory,
42 protected ilLanguage $lng
43 ) {
44 }
45
46 public function getAnswers(): array
47 {
48 return $this->poll->getAnswers();
49 }
50
51 public function getPollQuestion(): string
52 {
53 return $this->poll->getQuestion();
54 }
55
56 protected function getRawData(): array
57 {
58 if (isset($this->data)) {
59 return $this->data;
60 }
61
62 $answer_ids = $this->getAnswerIds();
63 $data = [];
64 foreach ($this->poll->getVotesByUsers() as $user_id => $vote) {
65 $answers = (array) ($vote["answers"] ?? []);
66 unset($vote["answers"]);
67
68 foreach ($answer_ids as $answer_id) {
69 $vote[TableBuilder::TABLE_COL_ANSWER_PREFIX . $answer_id] = in_array($answer_id, $answers);
70 }
71
72 $data[] = $vote;
73 }
74 return $this->data = $data;
75 }
76
77 public function getRows(
78 DataRowBuilder $row_builder,
79 array $visible_column_ids,
81 Order $order,
82 mixed $additional_viewcontrol_data,
83 mixed $filter_data,
84 mixed $additional_parameters
85 ): Generator {
86 [$column_name, $direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
87 $answer_ids = $this->getAnswerIds();
88 $comparator = null;
89 $rows = $this->getRawData();
90 for ($i = 0; $i < count($rows); $i++) {
91 $rows[$i]['column'] = $column_name;
92 }
93 switch ($column_name) {
95 $comparator = function (array $f1, array $f2) {
96 return strcmp($f1['login'], $f2['login']);
97 };
98 break;
100 $comparator = function (array $f1, array $f2) {
101 return strcmp($f1['firstname'], $f2['firstname']);
102 };
103 break;
105 $comparator = function (array $f1, array $f2) {
106 return strcmp($f1['lastname'], $f2['lastname']);
107 };
108 break;
109 default:
110 $comparator = function (array $f1, array $f2) {
111 return $f1[$f1['column']] ? $f2[$f2['column']] ? 0 : 1 : -1;
112 };
113 }
114 uasort($rows, $comparator);
115 if ($direction === "DESC") {
116 $rows = array_reverse($rows, true);
117 }
118 $rows = array_slice($rows, $range->getStart(), $range->getLength(), true);
119 $checked_icon = $this->ui_factory->symbol()->icon()->custom(
120 ilUtil::getImagePath('standard/icon_ok.svg'),
121 $this->lng->txt('poll_answer_selected_alt_text'),
122 'medium'
123 );
124 $unchecked_icon = $this->ui_factory->symbol()->icon()->custom(
125 ilUtil::getImagePath('standard/icon_not_ok.svg'),
126 $this->lng->txt('poll_answer_selected_alt_text'),
127 'medium'
128 );
129 foreach ($rows as $row) {
130 $record = [
131 TableBuilder::TABLE_COL_LOGIN => (string) ($row['login'] ?? ''),
132 TableBuilder::TABLE_COL_FIRSTNAME => (string) ($row['firstname'] ?? ''),
133 TableBuilder::TABLE_COL_LASTNAME => (string) ($row['lastname'] ?? ''),
134 ];
135 foreach ($answer_ids as $answer_id) {
136 $icon = $row[TableBuilder::TABLE_COL_ANSWER_PREFIX . $answer_id]
137 ? $checked_icon
138 : $unchecked_icon;
139 $record[TableBuilder::TABLE_COL_ANSWER_PREFIX . $answer_id] = $icon;
140 }
141 yield $row_builder->buildDataRow(
142 '' . $row['login'],
143 $record
144 );
145 }
146 }
147
148 public function getTotalRowCount(
149 mixed $additional_viewcontrol_data,
150 mixed $filter_data,
151 mixed $additional_parameters
152 ): ?int {
153 return count($this->getRawData());
154 }
155
156 protected function getAnswerIds(): array
157 {
158 $a_answer_ids = [];
159 foreach ($this->getAnswers() as $answer) {
160 $a_answer_ids[] = (int) ($answer["id"] ?? 0);
161 }
162 return $a_answer_ids;
163 }
164}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
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 ilObjPoll $poll, protected UIFactory $ui_factory, protected ilLanguage $lng)
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....
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...
language handling
Class ilObjPoll.
Util class various functions, usage as namespace.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
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...
This describes how an icon could be modified during construction of UI.
Definition: Icon.php:29
buildDataRow(string $id, array $record)
An entity that renders components to a string output.
Definition: Renderer.php:31
global $lng
Definition: privfeed.php:26