ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Setting.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\User\Settings;
22
27use ILIAS\Refinery\Factory as Refinery;
33
34class Setting implements Property
35{
36 public function __construct(
37 private SettingDefinition $definition,
38 private bool $changeable_by_user,
39 private bool $changeable_in_local_user_administration,
40 private bool $export
41 ) {
42 }
43
44 public function getIdentifier(): string
45 {
46 return $this->definition->getIdentifier();
47 }
48
49 public function getLabel(Language $lng): string
50 {
51 return $this->definition->getLabel($lng);
52 }
53
54 public function isChangeableByUser(): bool
55 {
56 return $this->changeable_by_user;
57 }
58
60 {
61 return $this->changeable_in_local_user_administration;
62 }
63
64 public function export(): bool
65 {
66 return $this->export;
67 }
68
70 {
71 return $this->definition->getSettingsPage();
72 }
73
74 public function getSection(): AvailableSections
75 {
76 return $this->definition->getSection();
77 }
78
79 public function getTableRow(
80 DataRowBuilder $row_builder,
82 ): DataRow {
83 return $row_builder->buildDataRow(
84 $this->definition->getIdentifier(),
85 [
86 'field' => $this->definition->getLabel($lng),
87 'changeable_by_user' => $this->changeable_by_user,
88 'changeable_in_local_user_administration' => $this->changeable_in_local_user_administration,
89 'export' => $this->export
90 ]
91 );
92 }
93
94 public function getInput(
95 FieldFactory $field_factory,
98 \ilSetting $settings,
99 ?\ilObjUser $user = null
100 ): Input {
101 return $this->definition->getInput($field_factory, $lng, $refinery, $settings, $user);
102 }
103
104 public function getLegacyInput(
106 \ilSetting $settings,
107 ?\ilObjUser $user = null
109 $input = $this->definition->getLegacyInput(
110 $lng,
111 $settings,
112 $user
113 );
114
115 $input->setPostVar($this->definition->getIdentifier());
116 return $input;
117 }
118
119 public function getForm(
121 FieldFactory $ff,
123 ): array {
124 return [
125 'setting' => $ff->group([
126 'changeable_by_user' => $ff->checkbox($lng->txt(
127 PropertyAttributes::ChangeableByUser->value
128 ))->withValue($this->changeable_by_user),
129 'changeable_in_local_user_administration' => $ff->checkbox($lng->txt(
130 PropertyAttributes::ChangeableInLocalUserAdministration->value
131 ))->withValue($this->changeable_in_local_user_administration),
132 'export' => $ff->checkbox($lng->txt(
133 PropertyAttributes::Export->value
134 ))->withValue($this->export),
136 $this->buildCreateSettingTransformation($refinery)
137 )
138 ];
139 }
140
143 \ilSetting $settings
144 ): string {
145 $default_value = $this->definition->getDefaultValueForDisplay($lng, $settings);
146 if ($default_value === null) {
147 return '';
148 }
149 return $default_value;
150 }
151
153 \ilSetting $settings,
154 ?\ilObjUser $user
155 ): bool {
156 if ($user === null) {
157 return false;
158 }
159 return $this->definition->hasUserPersonalizedSetting($settings, $user);
160 }
161
162 public function persistUserInput(
163 \ilObjUser $user,
164 Context $context,
165 mixed $input,
166 ?\ilPropertyFormGUI $form = null
167 ): \ilObjUser {
168 if (!$context->isSettingAvailableInType($this)) {
169 throw \Exception('It is not possible to Change this from here!');
170 }
171 return $this->definition->persistUserInput($user, $input, $form);
172 }
173
174 public function retrieveValueFromUser(\ilObjUser $user): mixed
175 {
176 return $this->definition->retrieveValueFromUser($user);
177 }
178
179 public function validateUserChoice(
182 \ilPropertyFormGUI $form
183 ): ?bool {
184 return $this->definition->validateUserChoice($tpl, $lng, $form);
185 }
186
189 ): Transformation {
190 return $refinery->custom()->transformation(
191 function (array $vs): self {
192 $clone = clone $this;
193 $clone->changeable_by_user = $vs['changeable_by_user'];
194 $clone->changeable_in_local_user_administration = $vs['changeable_in_local_user_administration'];
195 $clone->export = $vs['export'];
196 return $clone;
197 }
198 );
199 }
200}
Builds data types.
Definition: Factory.php:36
__construct(private SettingDefinition $definition, private bool $changeable_by_user, private bool $changeable_in_local_user_administration, private bool $export)
Definition: Setting.php:36
getTableRow(DataRowBuilder $row_builder, Language $lng)
Definition: Setting.php:79
persistUserInput(\ilObjUser $user, Context $context, mixed $input, ?\ilPropertyFormGUI $form=null)
Definition: Setting.php:162
validateUserChoice(\ilGlobalTemplateInterface $tpl, Language $lng, \ilPropertyFormGUI $form)
Definition: Setting.php:179
getDefaultValueForDisplay(Language $lng, \ilSetting $settings)
Definition: Setting.php:141
getLabel(Language $lng)
Definition: Setting.php:49
hasUserPersonalizedSetting(\ilSetting $settings, ?\ilObjUser $user)
Definition: Setting.php:152
getLegacyInput(Language $lng, \ilSetting $settings, ?\ilObjUser $user=null)
Definition: Setting.php:104
buildCreateSettingTransformation(Refinery $refinery)
Definition: Setting.php:187
getForm(Language $lng, FieldFactory $ff, Refinery $refinery)
Definition: Setting.php:119
retrieveValueFromUser(\ilObjUser $user)
Definition: Setting.php:174
getInput(FieldFactory $field_factory, Language $lng, Refinery $refinery, \ilSetting $settings, ?\ilObjUser $user=null)
Definition: Setting.php:94
This class represents a property in a property form.
setPostVar(string $a_postvar)
User class.
This class represents a property form user interface.
ILIAS Setting Class.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A transformation is a function from one datatype to another.
This is what a factory for input fields looks like.
Definition: Factory.php:31
This describes commonalities between all inputs.
Definition: Input.php:47
withAdditionalTransformation(Transformation $trafo)
@inheritDoc
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
$context
Definition: webdav.php:31