ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
ContributorRetrieval.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\Repository\RetrievalBase;
27
29{
30 use RetrievalBase;
31
32 protected \ilRbacReview $rbac_review;
33 protected array $local_roles = [];
34
35 public function __construct(
37 array $local_roles
38 ) {
39 $this->rbac_review = $rbac_review;
40 $this->local_roles = $local_roles;
41 }
42
43 public function getData(
44 array $fields,
45 ?Range $range = null,
46 ?Order $order = null,
47 array $filter = [],
48 array $parameters = []
49 ): \Generator {
50 $data = $this->collectData();
51
52 // Apply ordering if specified
53 $data = $this->applyOrder($data, $order);
54
55 // Apply range (pagination) if specified
56 $data = $this->applyRange($data, $range);
57
58 foreach ($data as $row) {
59 yield $row;
60 }
61 }
62
63 protected function applyOrder(array $data, ?Order $order = null): array
64 {
65 if ($order !== null) {
66 $order_field = array_keys($order->get())[0];
67 $order_direction = $order->get()[$order_field];
68
69 array_multisort(
70 array_column($data, $order_field),
71 $order_direction === 'ASC' ? SORT_ASC : SORT_DESC,
72 $this->isFieldNumeric($order_field) ? SORT_NUMERIC : SORT_STRING,
73 $data
74 );
75 }
76 return $data;
77 }
78
79 protected function applyRange(array $data, ?Range $range = null): array
80 {
81 if ($range !== null) {
82 $offset = $range->getStart();
83 $limit = $range->getLength();
84 $data = array_slice($data, $offset, $limit);
85 }
86 return $data;
87 }
88
89 public function count(
90 array $filter,
91 array $parameters
92 ): int {
93 return count($this->collectData());
94 }
95
96 protected function collectData(): array
97 {
98 $user_map = $assigned = array();
99 foreach ($this->local_roles as $id => $title) {
100 $local = $this->rbac_review->assignedUsers($id);
101 $assigned = array_merge($assigned, $local);
102 foreach ($local as $user_id) {
103 $user_map[$user_id][] = $title;
104 }
105 }
106
107 $data = array();
108 foreach (array_unique($assigned) as $id) {
109 $data[] = array(
110 "id" => $id,
111 "name" => \ilUserUtil::getNamePresentation($id, false, false, "", true),
112 "role" => $user_map[$id]
113 );
114 }
115
116 return $data;
117 }
118
119 public function isFieldNumeric(string $field): bool
120 {
121 return $field === "id";
122 }
123
124}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
applyOrder(array $data, ?Order $order=null)
applyRange(array $data, ?Range $range=null)
getData(array $fields, ?Range $range=null, ?Order $order=null, array $filter=[], array $parameters=[])
__construct(\ilRbacReview $rbac_review, array $local_roles)
count(array $filter, array $parameters)
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
class ilRbacReview Contains Review functions of core Rbac.
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path=null)
Default behaviour is:
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...
$data
Definition: storeScorm.php:45