ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...