ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
Roles.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\User\Profile\Fields\NoOverrides;
28
29class Roles implements FieldDefinition
30{
31 use NoOverrides;
32
33 public function __construct(
34 private readonly \ilObjectDataCache $object_cache
35 ) {
36 }
37
38 public function getIdentifier(): string
39 {
40 return 'roles';
41 }
42
43 public function getLabel(Language $lng): string
44 {
45 return $lng->txt($this->getIdentifier());
46 }
47
48 public function getSection(): AvailableSections
49 {
50 return AvailableSections::Access;
51 }
52
53 public function hiddenInLists(): bool
54 {
55 return true;
56 }
57
58 public function visibleInRegistrationForcedTo(): ?bool
59 {
60 return false;
61 }
62
63 public function visibleInCoursesForcedTo(): ?bool
64 {
65 return false;
66 }
67
68 public function visibleInGroupsForcedTo(): ?bool
69 {
70 return false;
71 }
72
73 public function visibleInStudyProgrammesForcedTo(): ?bool
74 {
75 return false;
76 }
77
78 public function exportForcedTo(): ?bool
79 {
80 return false;
81 }
82
83 public function changeableByUserForcedTo(): ?bool
84 {
85 return false;
86 }
87
88 public function requiredForcedTo(): ?bool
89 {
90 return false;
91 }
92
93 public function searchableForcedTo(): ?bool
94 {
95 return false;
96 }
97
98 public function availableInCertificatesForcedTo(): ?bool
99 {
100 return false;
101 }
102
103 public function getLegacyInput(
106 ?\ilObjUser $user = null
108 if ($user !== null) {
109 return $this->buildNonEditableInput($lng, $user);
110 }
111 return $this->buildMultiselect($lng);
112 }
113
114 public function addValueToUserObject(
115 \ilObjUser $user,
116 mixed $input,
117 ?\ilPropertyFormGUI $form = null
118 ): \ilObjUser {
119 if (!is_array($input)) {
120 return $user;
121 }
122
123 $rbac_admin = new \ilRbacAdmin();
124 foreach ($input as $role_id) {
125 $rbac_admin->assignUser((int) $role_id, $user->getId());
126 }
127
128 return $user;
129 }
130
131 public function retrieveValueFromUser(\ilObjUser $user): string
132 {
133 $rbac_review = new \ilRbacReview();
134 $assigned_roles = $rbac_review->assignedRoles($user->getId());
135 return substr(
136 array_reduce(
137 $rbac_review->getGlobalRolesArray(),
138 fn(string $c, array $v) => in_array($v['obj_id'], $assigned_roles)
139 ? $c . $this->object_cache->lookupTitle($v['obj_id']) . ', '
140 : $c,
141 ''
142 ),
143 0,
144 -2
145 );
146 }
147
148 private function buildNonEditableInput(
150 \ilObjUser $user
152 $input = new \ilNonEditableValueGUI($this->getLabel($lng));
153 $input->setValue(
154 $this->retrieveValueFromUser($user)
155 );
156 return $input;
157 }
158
160 {
161 $rbac_review = new \ilRbacReview();
162 $input = new \ilMultiSelectInputGUI($this->getLabel($lng));
163 $input->setOptions(
164 array_reduce(
165 $rbac_review->getGlobalRolesArray(),
166 function (array $c, array $v): array {
167 if ($v['obj_id'] === ANONYMOUS_ROLE_ID) {
168 return $c;
169 }
170 $c[$v['obj_id']] = $this->object_cache->lookupTitle($v['obj_id']);
171 return $c;
172 },
173 []
174 ),
175 );
176 $input->setRequired(true);
177
178 return $input;
179 }
180}
retrieveValueFromUser(\ilObjUser $user)
Definition: Roles.php:131
buildNonEditableInput(Language $lng, \ilObjUser $user)
Definition: Roles.php:148
addValueToUserObject(\ilObjUser $user, mixed $input, ?\ilPropertyFormGUI $form=null)
Definition: Roles.php:114
getLegacyInput(Language $lng, Context $context, ?\ilObjUser $user=null)
You don't need to add a post_var to the input as the User will handle this for you,...
Definition: Roles.php:103
__construct(private readonly \ilObjectDataCache $object_cache)
Definition: Roles.php:33
This class represents a property in a property form.
This class represents a non editable value in a property form.
User class.
class ilObjectDataCache
This class represents a property form user interface.
const ANONYMOUS_ROLE_ID
Definition: constants.php:28
$c
Definition: deliver.php:25
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
$context
Definition: webdav.php:31