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 ILIAS\UI\Component\Table\DataRetrieval as DataRetrievalInterface;
27use ilObjPoll;
28use Generator;
29
30class DataRetrieval implements DataRetrievalInterface
31{
32 protected array $data;
33
34 public function __construct(
35 protected ilObjPoll $poll
36 ) {
37 }
38
39 public function getQuestion(): string
40 {
41 return $this->poll->getQuestion();
42 }
43
44 protected function getRawData(): array
45 {
46 if (isset($this->data)) {
47 return $this->data;
48 }
49
50 $data = $this->poll->getAnswers();
51 $perc = $this->poll->getVotePercentages();
52 $perc = (array) ($perc["perc"] ?? []);
53 // add current percentages
54 foreach ($data as $idx => $item) {
55 $item_id = (int) ($item['id'] ?? 0);
56 if (!isset($perc[$item_id])) {
57 $data[$idx]["percentage"] = 0;
58 $data[$idx]["votes"] = 0;
59 } else {
60 $data[$idx]["percentage"] = round((float) ($perc[$item_id]["perc"] ?? 0));
61 $data[$idx]["votes"] = (int) ($perc[$item_id]["abs"] ?? 0);
62 }
63 }
64 return $this->data = $data;
65 }
66
67 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 $comparator = function (array $f1, array $f2) {
78 return 0;
79 };
80 switch ($column_name) {
82 $comparator = function (array $f1, array $f2) {
83 if ((int) $f1['pos'] === (int) $f2['pos']) {
84 return 0;
85 }
86 return (int) $f1['pos'] > (int) $f2['pos'] ? 1 : -1;
87 };
88 break;
90 $comparator = function (array $f1, array $f2) {
91 return strcmp($f1['answer'], $f2['answer']);
92 };
93 break;
95 $comparator = function (array $f1, array $f2) {
96 if ((int) $f1['votes'] === (int) $f2['votes']) {
97 return 0;
98 }
99 return (int) $f1['votes'] > (int) $f2['votes'] ? 1 : -1;
100 };
101 break;
103 $comparator = function (array $f1, array $f2) {
104 if ((int) $f1['percentage'] === (int) $f2['percentage']) {
105 return 0;
106 }
107 return (int) $f1['percentage'] > (int) $f2['percentage'] ? 1 : -1;
108 };
109 break;
110 }
111 $rows = $this->getRawData();
112 uasort($rows, $comparator);
113 if ($direction === "DESC") {
114 $rows = array_reverse($rows, true);
115 }
116 $rows = array_slice($rows, $range->getStart(), $range->getLength(), true);
117 foreach ($rows as $row) {
118 yield $row_builder->buildDataRow(
119 $row['id'] . '',
120 [
121 TableBuilder::TABLE_COL_ORDER => (int) ($row['pos'] ?? 10) / 10,
122 TableBuilder::TABLE_COL_ANSWER => $row['answer'] ?? '',
123 TableBuilder::TABLE_COL_CURRENT_VOTES => (int) ($row['votes'] ?? 0),
124 TableBuilder::TABLE_COL_CURRENT_PERCENTAGE => (int) ($row['percentage'] ?? 0),
125 ]
126 );
127 }
128 }
129
130 public function getTotalRowCount(
131 mixed $additional_viewcontrol_data,
132 mixed $filter_data,
133 mixed $additional_parameters
134 ): ?int {
135 return count($this->getRawData());
136 }
137}
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
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 ilObjPoll.
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)