ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
AssignedRolesRetrieval.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 array $data = [];
33
34 public function __construct(
35 protected InternalDomainService $domain,
36 protected int $ref_id,
37 protected int $managed_user_id,
38 protected int $managing_user_id
39 ) {
40 }
41
42
43 public function isFieldNumeric(string $field): bool
44 {
45 return in_array($field, ['id', 'obj_id', 'ref_id']);
46 }
47
48 public function getData(
49 array $fields,
50 ?Range $range = null,
51 ?Order $order = null,
52 array $filter = [],
53 array $parameters = []
54 ): \Generator {
55
56 $rbacreview = $this->domain->rbac()->review();
57 $roles = $this->domain->assignedRolesManager(
58 $this->ref_id,
59 $this->managed_user_id,
60 $this->managing_user_id
61 )->getAssignableRoles();
62 $ass_roles = $rbacreview->assignedRoles($this->managed_user_id);
63 $lng = $this->domain->lng();
64
65 $data = [];
66 foreach ($roles as $role) {
67 $role_obj = \ilObjectFactory::getInstanceByObjId((int) $role['obj_id']);
68
69 $assigned = in_array((int) $role['obj_id'], $ass_roles, true);
70 $title = $role_obj?->getTitle() ?: "";
71 $desc = $role_obj?->getDescription() ?: "";
72 $type = ($role['role_type'] ?? '') === 'global' ?
73 $lng->txt('global') :
74 $lng->txt('local');
75 $data[] = [
76 "assigned" => $assigned,
77 "desc" => $desc,
78 "title" => $title,
79 "id" => $role['obj_id'],
80 "type" => $type
81 ];
82 }
83
84 $data = $this->applyOrder($data, $order);
85 $this->data = $this->applyRange($data, $range);
86
87 foreach ($this->data as $row) {
88 yield $row;
89 }
90 }
91
92 public function count(array $filter, array $parameters): int
93 {
94 return count($this->data);
95 }
96}
__construct(protected InternalDomainService $domain, protected int $ref_id, protected int $managed_user_id, protected int $managing_user_id)
getData(array $fields, ?Range $range=null, ?Order $order=null, array $filter=[], array $parameters=[])
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
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
$ref_id
Definition: ltiauth.php:66
global $lng
Definition: privfeed.php:31