ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
GlobalTestSettings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\UI\Factory as UIFactory;
28
30{
31 public function __construct(
32 private ProcessLockModes $process_lock_mode = ProcessLockModes::ASS_PROC_LOCK_MODE_NONE,
33 private string $image_map_line_color = 'FF0000',
34 private UserIdentifiers $user_identifier = UserIdentifiers::USER_ID,
35 private int $skill_triggering_number_of_answers = 1,
36 private array $disabled_question_types = [],
37 private bool $manual_scoring_enabled = false,
38 private bool $adjusting_questions_with_results_allowed = false,
39 private bool $page_editor_enabled = false
40 ) {
41 }
42
47 public function toForm(
48 UIFactory $ui_factory,
51 ): array {
52 $ff = $ui_factory->input()->field();
53 $all_question_types = \ilObjQuestionPool::_getQuestionTypes(true);
54 $enabled_question_types = array_map(
55 static fn(array $v): int => $v['question_type_id'],
56 array_filter(
57 $all_question_types,
58 fn(array $v): bool => !in_array($v['question_type_id'], $this->disabled_question_types)
59 )
60 );
61 $trafo = $this->buildGlobalSettingsBuilderTrafo($refinery, $all_question_types);
62
63 return [
64 'global_settings' => $ff->group([
65 'general_settings' => $this->buildGeneralSettingsInputs($ff, $refinery, $lng),
66 'question_settings' => $this->buildQuestionSettingsInputs(
67 $ff,
68 $lng,
69 $all_question_types,
70 $enabled_question_types
71 )
72 ])->withAdditionalTransformation($trafo)
73 ];
74 }
75
77 {
78 return $this->process_lock_mode;
79 }
80
81 public function withProcessLockMode(ProcessLockModes $process_lock_mode): self
82 {
83 $clone = clone $this;
84 $clone->process_lock_mode = $process_lock_mode;
85 return $clone;
86 }
87
88 public function getImageMapLineColor(): string
89 {
90 return $this->image_map_line_color;
91 }
92
93 public function withImageMapLineColor(string $image_map_line_color): self
94 {
95 $clone = clone $this;
96 $clone->image_map_line_color = $image_map_line_color;
97 return $clone;
98 }
99
101 {
102 return $this->user_identifier;
103 }
104
105 public function withUserIdentifier(UserIdentifiers $user_identifier): self
106 {
107 $clone = clone $this;
108 $clone->user_identifier = $user_identifier;
109 return $clone;
110 }
111
113 {
114 return $this->skill_triggering_number_of_answers;
115 }
116
117 public function withSkillTriggeringNumberOfAnswers(int $skill_triggering_number_of_answers): self
118 {
119 $clone = clone $this;
120 $clone->skill_triggering_number_of_answers = $skill_triggering_number_of_answers;
121 return $clone;
122 }
123
127 public function getDisabledQuestionTypes(): array
128 {
129 return $this->disabled_question_types;
130 }
131
135 public function withDisabledQuestionTypes(array $disabled_question_types): self
136 {
137 $clone = clone $this;
138 $clone->disabled_question_types = $disabled_question_types;
139 return $clone;
140 }
141
142 public function isManualScoringEnabled(): bool
143 {
144 return $this->manual_scoring_enabled;
145 }
146
147 public function withManualScoringEnabled(bool $manual_scoring_enabled): self
148 {
149 $clone = clone $this;
150 $clone->manual_scoring_enabled = $manual_scoring_enabled;
151 return $clone;
152 }
153
155 {
156 return $this->adjusting_questions_with_results_allowed;
157 }
158
159 public function withAdjustingQuestionsWithResultsAllowed(bool $adjusting_questions_with_results_allowed): self
160 {
161 $clone = clone $this;
162 $clone->adjusting_questions_with_results_allowed = $adjusting_questions_with_results_allowed;
163 return $clone;
164 }
165
166 public function isPageEditorEnabled(): bool
167 {
168 return $this->page_editor_enabled;
169 }
170
171 public function withPageEditorEnabled(bool $page_editor_enabled): self
172 {
173 $clone = clone $this;
174 $clone->page_editor_enabled = $page_editor_enabled;
175 return $clone;
176 }
177
180 array $all_question_types
181 ): Transformation {
182 return $refinery->custom()->transformation(
183 static function ($vs) use ($all_question_types): self {
184 $process_lock_mode = ProcessLockModes::ASS_PROC_LOCK_MODE_NONE;
185 if ($vs['general_settings']['process_lock_mode'] !== null) {
186 $process_lock_mode = ProcessLockModes::from($vs['general_settings']['process_lock_mode'][0]);
187 }
188 return new self(
189 $process_lock_mode,
190 substr($vs['general_settings']['image_map_line_color']->asHex(), 1),
191 UserIdentifiers::from($vs['general_settings']['user_identifier']),
192 $vs['general_settings']['skill_triggering_number_of_answers'],
193 array_reduce(
194 $all_question_types,
195 static function (array $c, array $v) use ($vs): array {
196 if (!in_array($v['question_type_id'], $vs['question_settings']['enabled_question_types'])) {
197 $c[] = $v['question_type_id'];
198 }
199 return $c;
200 },
201 []
202 ),
203 $vs['question_settings']['manual_scoring_enabled'],
204 $vs['question_settings']['adjusting_questions_with_results_allowed']
205 );
206 }
207 );
208 }
209
211 FieldFactory $ff,
214 ): Section {
215 return $ff->section(
216 [
217 'process_lock_mode' => $ff->optionalGroup(
218 [
219 $ff->radio($lng->txt('ass_process_lock_mode'))
220 ->withOption(
221 ProcessLockModes::ASS_PROC_LOCK_MODE_FILE->value,
222 $lng->txt('ass_process_lock_mode_file'),
223 $lng->txt('ass_process_lock_mode_file_desc')
224 )->withOption(
226 $lng->txt('ass_process_lock_mode_db'),
227 $lng->txt('ass_process_lock_mode_db_desc')
228 )
229 ],
230 $lng->txt('ass_process_lock')
231 )->withByline($lng->txt('ass_process_lock_desc'))
232 ->withValue($this->process_lock_mode === ProcessLockModes::ASS_PROC_LOCK_MODE_NONE ? null : [$this->process_lock_mode->value]),
233 'image_map_line_color' => $ff->colorSelect($lng->txt('imap_line_color'))
234 ->withValue('#' . $this->image_map_line_color),
235 'user_identifier' => $ff->select(
236 $lng->txt('user_criteria'),
237 array_reduce(
238 UserIdentifiers::cases(),
239 function (array $c, UserIdentifiers $v): array {
240 $c[$v->value] = $v->value;
241 return $c;
242 },
243 []
244 )
245 )->withRequired(true)
246 ->withByline($lng->txt('user_criteria_desc'))
247 ->withValue($this->user_identifier->value),
248 'skill_triggering_number_of_answers' => $ff->numeric($lng->txt('tst_skill_triggerings_num_req_answers'))
249 ->withAdditionalTransformation($refinery->int()->isGreaterThan(0))
250 ->withByline($lng->txt('tst_skill_triggerings_num_req_answers_desc'))
251 ->withValue($this->skill_triggering_number_of_answers)
252 ],
253 $lng->txt('settings')
254 );
255 }
256
258 FieldFactory $ff,
260 array $all_question_types,
261 array $enabled_question_types
262 ): Section {
263 return $ff->section(
264 [
265 'enabled_question_types' => $ff->multiSelect(
266 $lng->txt('assf_allowed_questiontypes'),
267 array_reduce(
268 array_keys($all_question_types),
269 function (array $c, string $v) use ($all_question_types): array {
270 $c[$all_question_types[$v]['question_type_id']] = $v;
271 return $c;
272 },
273 []
274 )
275 )->withByline($lng->txt('assf_allowed_questiontypes_desc'))
276 ->withValue($enabled_question_types),
277 'manual_scoring_enabled' => $ff->checkbox($lng->txt('activate_manual_scoring'))
278 ->withByline($lng->txt('activate_manual_scoring_desc'))
279 ->withValue($this->isManualScoringEnabled()),
280 'adjusting_questions_with_results_allowed' => $ff->checkbox($lng->txt('assessment_scoring_adjust'))
281 ->withByline($lng->txt('assessment_scoring_adjust_desc'))
282 ->withValue($this->isAdjustingQuestionsWithResultsAllowed())
283 ],
284 $lng->txt('assf_questiontypes')
285 );
286 }
287}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
buildQuestionSettingsInputs(FieldFactory $ff, \ilLanguage $lng, array $all_question_types, array $enabled_question_types)
withProcessLockMode(ProcessLockModes $process_lock_mode)
toForm(UIFactory $ui_factory, Refinery $refinery, \ilLanguage $lng)
buildGlobalSettingsBuilderTrafo(Refinery $refinery, array $all_question_types)
withAdjustingQuestionsWithResultsAllowed(bool $adjusting_questions_with_results_allowed)
withSkillTriggeringNumberOfAnswers(int $skill_triggering_number_of_answers)
__construct(private ProcessLockModes $process_lock_mode=ProcessLockModes::ASS_PROC_LOCK_MODE_NONE, private string $image_map_line_color='FF0000', private UserIdentifiers $user_identifier=UserIdentifiers::USER_ID, private int $skill_triggering_number_of_answers=1, private array $disabled_question_types=[], private bool $manual_scoring_enabled=false, private bool $adjusting_questions_with_results_allowed=false, private bool $page_editor_enabled=false)
buildGeneralSettingsInputs(FieldFactory $ff, Refinery $refinery, \ilLanguage $lng)
language handling
static _getQuestionTypes($all_tags=false, $fixOrder=false, $withDeprecatedTypes=true)
$c
Definition: deliver.php:25
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 section inputs.
Definition: Section.php:29
withAdditionalTransformation(Transformation $trafo)
@inheritDoc
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
global $lng
Definition: privfeed.php:31