ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
DefaultEnvironment.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use ILIAS\Data\UUID\Factory as UuidFactory;
31use ILIAS\HTTP\Services as HTTPServices;
33use ILIAS\Refinery\Factory as Refinery;
36use ILIAS\UI\Factory as UIFactory;
39
41{
42 private const array QUERY_PARAMETER_NAME_SPACE = ['q'];
43 private const string TOKEN_STRING_ACTION = 'a';
44 private const string TOKEN_STRING_SUB_ACTION = 'sa';
45 private const string TOKEN_STRING_QUESTION_ID = 'q';
46 private const string TOKEN_STRING_TABLE_ROW_ID = 'r';
47 private const string TOKEN_STRING_TYPE_HASH = 't';
48 private const string TOKEN_STRING_ANSWER_FORM_ID = 'af';
49 private const string TOKEN_STRING_CREATE_MODE = 'cm';
50 private const string TOKEN_STRING_FORM_START_SUB_ACTION = 'fssa';
51 private const string TOKEN_STRING_CREATE_AND_NEW = 'can';
52
53 private const string PARAMETER_STRING_HIER_ID = 'hier_id';
54
55 private const string INTERRUPTIVE_ITEMS_KEY = 'interruptive_items';
56
57 private const string TAB_ID_ANSWER_FORM = 'answer_form';
58
60
61 private bool $default_sub_action = false;
62 private bool $is_in_creation_context = false;
63
73
74 private ?array $table_row_ids = null;
75
76 public function __construct(
77 private readonly \ilCtrl $ctrl,
78 private readonly HTTPServices $http,
79 private readonly Refinery $refinery,
80 private readonly Language $lng,
81 private readonly \ilTabsGUI $tabs_gui,
82 private readonly UuidFactory $uuid_factory,
83 private readonly Factory $presentation_factory,
84 private readonly Editability $editability,
85 private readonly RequiredCapabilities $required_capabilities,
86 private readonly int $parent_obj_id,
87 URI $base_uri
88 ) {
89 $this->acquireURLBuilderAndParameters($base_uri);
90 }
91
92 #[\Override]
93 public function getHttpServices(): HTTPServices
94 {
95 return $this->http;
96 }
97
98 #[\Override]
99 public function getLanguage(): Language
100 {
101 return $this->lng;
102 }
103
104 #[\Override]
105 public function getRefinery(): Refinery
106 {
107 return $this->refinery;
108 }
109
110 #[\Override]
111 public function getUIFactory(): UIFactory
112 {
113 return $this->presentation_factory->getUIFactory();
114 }
115
116 #[\Override]
117 public function setEditAnswerFormBackTarget(): void
118 {
119 $this->tabs_gui->clearTargets();
120 $this->tabs_gui->setBackTarget(
121 $this->lng->txt('cancel'),
122 $this->buildEditAnswerFormBackUrl()->buildURI()->__toString()
123 );
124 }
125
126 #[\Override]
127 public function addEditAnswerFormSubTab(
128 string $sub_action,
129 string $language_variable
130 ): void {
131 $this->tabs_gui->addSubTab(
132 $sub_action,
133 $this->lng->txt($language_variable),
134 $this->withSubActionParameter($sub_action)
135 ->withActionParameter(Edit::ACTION_OTHER_ANSWER_FORM)
136 ->getUrlBuilder()
137 ->buildURI()
138 ->__toString()
139 );
140 }
141
142 #[\Override]
144 string $sub_action
145 ): void {
146 $this->tabs_gui->activateSubTab($sub_action);
147 }
148
149 #[\Override]
151 {
152 return $this->presentation_factory;
153 }
154
155 #[\Override]
156 public function getUrlBuilder(): URLBuilder
157 {
158 return $this->url_builder;
159 }
160
161 #[\Override]
162 public function withSubActionParameter(
163 string $sub_action
164 ): self {
165 $clone = clone $this;
166 if ($clone->sub_action_token === null) {
167 [
168 $clone->url_builder,
169 $clone->sub_action_token
170 ] = $this->url_builder->acquireParameter(
171 self::QUERY_PARAMETER_NAME_SPACE,
172 self::TOKEN_STRING_SUB_ACTION
173 );
174 }
175 $clone->url_builder = $clone->url_builder
176 ->withParameter($clone->sub_action_token, $sub_action);
177 return $clone;
178 }
179
180 #[\Override]
181 public function withDefaultSubAction(): self
182 {
183 $clone = clone $this;
184 $clone->default_sub_action = true;
185 return $clone;
186 }
187
188 #[\Override]
189 public function getSubAction(): string
190 {
191 if ($this->default_sub_action) {
192 return '';
193 }
194
195 $sub_action_token = $this->sub_action_token;
196 if ($sub_action_token === null) {
197 [,$sub_action_token] = $this->url_builder->acquireParameter(
198 self::QUERY_PARAMETER_NAME_SPACE,
199 self::TOKEN_STRING_SUB_ACTION
200 );
201 }
202
203 return $this->retrieveStringValueForToken(
204 $sub_action_token,
205 self::TOKEN_STRING_SUB_ACTION
206 );
207 }
208
209 #[\Override]
210 public function getEditability(): Editability
211 {
212 return $this->editability;
213 }
214
215 #[\Override]
216 public function isMarkingRequired(): bool
217 {
218 return $this->required_capabilities->isMarkingRequired();
219 }
220
221 #[\Override]
223 {
224 return array_map(
225 fn(AdditionalFormStepAction $v): TableAction => $v->getAsTableAction(
226 $this->withActionParameter($v->getIdentifier())
227 ),
228 $this->required_capabilities->getRequiredFormStepActions()
229 );
230 }
231
232 #[\Override]
233 public function isInCreationContext(): bool
234 {
235 return $this->is_in_creation_context;
236 }
237
238 #[\Override]
239 public function getAnswerFormId(): ?Uuid
240 {
241 if ($this->answer_form_properties !== null) {
242 return $this->answer_form_properties->getAnswerFormId();
243 }
244
245 $answer_form_id_token = $this->answer_form_id_token;
246 if ($answer_form_id_token === null) {
247 [,$answer_form_id_token] = $this->url_builder->acquireParameter(
248 self::QUERY_PARAMETER_NAME_SPACE,
249 self::TOKEN_STRING_ANSWER_FORM_ID
250 );
251 }
252 return $this->http->wrapper()->query()->retrieve(
253 $answer_form_id_token->getName(),
254 $this->refinery->byTrying([
255 $this->refinery->custom()->transformation(
256 $this->buildRetrieveUuidClosure()
257 ),
258 $this->refinery->always(null)
259 ])
260 );
261 }
262
263 #[\Override]
265 {
266 return $this->answer_form_properties;
267 }
268
269 #[\Override]
271 Properties $properties
272 ): self {
273 $clone = clone $this;
274 $clone->answer_form_properties = $properties;
275 return $clone;
276 }
277
278 #[\Override]
280 {
281 return $this->table_row_token;
282 }
283
287 #[\Override]
288 public function getTableRowIds(): array
289 {
290 if ($this->table_row_ids === null) {
291 $this->table_row_ids = $this->http->wrapper()->query()->retrieve(
292 $this->table_row_token->getName(),
293 $this->refinery->byTrying([
294 $this->refinery->kindlyTo()->listOf(
295 $this->refinery->custom()->transformation(
296 fn($v): string => $v !== ''
297 ? $this->refinery->kindlyTo()->string()->transform($v)
298 : throw new \UnexpectedValueException()
299 )
300 ),
301 $this->refinery->always([])
302 ])
303 );
304 }
305
306 return $this->table_row_ids;
307 }
308
309 #[\Override]
310 public function withPreservedTableRowIdsParameter(): self
311 {
312 $clone = clone $this;
313 $clone->table_row_ids = $clone->getTableRowIds();
314 $clone->url_builder = $this->url_builder
315 ->withParameter($this->table_row_token, $clone->table_row_ids);
316 return $clone;
317 }
318
319 #[\Override]
320 public function redirectTo(URLBuilder $target): void
321 {
322 $this->ctrl->redirectToURL(
323 $target->buildURI()->__toString()
324 );
325 }
326
327 public function runPageMigrations(): void
328 {
329 foreach ($this->required_capabilities
330 ->getRequiredPageMigrationProviders() as $provider) {
331 $provider->runPageMigrations();
332 }
333 }
334
335 public function withIsInCreationContext(
336 bool $is_in_creation_context
337 ): self {
338 $clone = clone $this;
339 $clone->is_in_creation_context = $is_in_creation_context;
340 return $clone;
341 }
342
343 public function getParentObjId(): int
344 {
345 return $this->parent_obj_id;
346 }
347
348 public function getAction(): string
349 {
350 $action_token = $this->action_token;
351 if ($action_token === null) {
352 [,$action_token] = $this->url_builder->acquireParameter(
353 self::QUERY_PARAMETER_NAME_SPACE,
354 self::TOKEN_STRING_ACTION
355 );
356 }
357 return $this->retrieveStringValueForToken($action_token);
358 }
359
360 public function withActionParameter(
361 string $action
362 ): self {
363 $clone = clone $this;
364 if ($clone->action_token === null) {
365 [
366 $clone->url_builder,
367 $clone->action_token
368 ] = $this->url_builder->acquireParameter(
369 self::QUERY_PARAMETER_NAME_SPACE,
370 self::TOKEN_STRING_ACTION
371 );
372 }
373 $clone->url_builder = $clone->url_builder
374 ->withParameter($clone->action_token, $action);
375 return $clone;
376 }
377
378 public function withQuestionIdParameter(
379 Uuid $question_id
380 ): self {
381 $clone = clone $this;
382 $clone->url_builder = $this->url_builder
383 ->withParameter($this->question_id_token, $question_id->toString());
384 return $clone;
385 }
386
388 string $type_hash
389 ): self {
390 $clone = clone $this;
391 if ($clone->type_hash_token === null) {
392 [
393 $clone->url_builder,
394 $clone->type_hash_token
395 ] = $this->url_builder->acquireParameter(
396 self::QUERY_PARAMETER_NAME_SPACE,
397 self::TOKEN_STRING_TYPE_HASH
398 );
399 }
400
401 $clone->url_builder = $clone->url_builder
402 ->withParameter($clone->type_hash_token, $type_hash);
403 return $clone;
404 }
405
407 Uuid $answer_form_id
408 ): self {
409 $clone = clone $this;
410 if ($clone->answer_form_id_token === null) {
411 [
412 $clone->url_builder,
413 $clone->answer_form_id_token
414 ] = $this->url_builder->acquireParameter(
415 self::QUERY_PARAMETER_NAME_SPACE,
416 self::TOKEN_STRING_ANSWER_FORM_ID
417 );
418 }
419 $clone->url_builder = $clone->url_builder->withParameter(
420 $clone->answer_form_id_token,
421 $answer_form_id->toString()
422 );
423 return $clone;
424 }
425
426 public function withCreateModeParameter(): self
427 {
428 $clone = clone $this;
429 if ($clone->create_mode_token === null) {
430 [
431 $clone->url_builder,
432 $clone->create_mode_token
433 ] = $this->url_builder->acquireParameter(
434 self::QUERY_PARAMETER_NAME_SPACE,
435 self::TOKEN_STRING_CREATE_MODE
436 );
437 }
438
439 $clone->url_builder = $clone->url_builder
440 ->withParameter($clone->create_mode_token, '1');
441 return $clone;
442 }
443
444 #[\Override]
446 string $sub_action
447 ): self {
448 $clone = clone $this;
449 if ($clone->form_start_sub_action_token === null) {
450 [
451 $clone->url_builder,
452 $clone->form_start_sub_action_token
453 ] = $this->url_builder->acquireParameter(
454 self::QUERY_PARAMETER_NAME_SPACE,
455 self::TOKEN_STRING_FORM_START_SUB_ACTION
456 );
457 }
458
459 $clone->url_builder = $clone->url_builder
460 ->withParameter(
461 $clone->form_start_sub_action_token,
462 $sub_action
463 );
464 return $clone;
465 }
466
467 #[\Override]
469 {
470 return $this->withFormStartSubActionParameter(
471 $this->getFormStartSubAction()
472 );
473 }
474
475 public function getQuestionId(): ?Uuid
476 {
477 return $this->http->wrapper()->query()->retrieve(
478 $this->question_id_token->getName(),
479 $this->refinery->byTrying([
480 $this->refinery->custom()->transformation(
481 $this->buildRetrieveUuidClosure()
482 ),
483 $this->refinery->always(null)
484 ])
485 );
486 }
487
493 public function getQuestionIds(): array|string|null
494 {
495 return $this->http->wrapper()->query()->retrieve(
496 $this->table_row_token->getName(),
497 $this->refinery->byTrying([
498 $this->refinery->custom()->transformation(
499 fn($v): string => $v === ['ALL_OBJECTS']
500 ? 'ALL_OBJECTS'
501 : throw new \UnexpectedValueException()
502 ),
503 $this->refinery->kindlyTo()->listOf(
504 $this->refinery->custom()->transformation(
505 $this->buildRetrieveUuidClosure()
506 )
507 ),
508 $this->refinery->always(null)
509 ])
510 ) ?? $this->http->wrapper()->post()->retrieve(
511 self::INTERRUPTIVE_ITEMS_KEY,
512 $this->refinery->kindlyTo()->listOf(
513 $this->refinery->custom()->transformation(
514 $this->buildRetrieveUuidClosure()
515 )
516 ),
517 $this->refinery->always(null)
518 );
519 }
520
521 public function getTypeClassHash(): string
522 {
523 $type_hash_token = $this->type_hash_token;
524 if ($type_hash_token === null) {
525 [,$type_hash_token] = $this->url_builder->acquireParameter(
526 self::QUERY_PARAMETER_NAME_SPACE,
527 self::TOKEN_STRING_TYPE_HASH
528 );
529 }
530 return $this->retrieveStringValueForToken($type_hash_token);
531 }
532
533 public function getFormStartSubAction(): string
534 {
535 $form_start_command_token = $this->form_start_sub_action_token;
536 if ($form_start_command_token === null) {
537 [,$form_start_command_token] = $this->url_builder->acquireParameter(
538 self::QUERY_PARAMETER_NAME_SPACE,
539 self::TOKEN_STRING_FORM_START_SUB_ACTION
540 );
541 }
542 return $this->retrieveStringValueForToken($form_start_command_token);
543 }
544
545 public function isCreateModeSimple(): bool
546 {
547 $create_mode_token = $this->create_mode_token;
548 if ($create_mode_token === null) {
549 [, $create_mode_token] = $this->url_builder->acquireParameter(
550 self::QUERY_PARAMETER_NAME_SPACE,
551 self::TOKEN_STRING_CREATE_MODE
552 );
553 }
554
555 return $this->http->wrapper()->query()->has(
556 $create_mode_token->getName()
557 );
558 }
559
564 public function setEditAnswerFormTabs(
565 array $additional_actions
566 ): void {
567 $this->tabs_gui->addTab(
568 self::TAB_ID_ANSWER_FORM,
569 $this->lng->txt('answer_form'),
570 $this->withDefaultSubAction()->getUrlBuilder()->buildURI()->__toString()
571 );
572
573 foreach ($additional_actions as $action) {
574 $action->addTab(
575 $this,
576 $this->tabs_gui,
577 $this->lng
578 );
579 }
580
581 $this->tabs_gui->addSubTab(
582 self::TAB_ID_ANSWER_FORM,
583 $this->lng->txt('overview'),
584 $this->withDefaultSubAction()->getUrlBuilder()->buildURI()->__toString()
585 );
586
587 $this->tabs_gui->activateTab(self::TAB_ID_ANSWER_FORM);
588 $this->tabs_gui->activateSubTab(self::TAB_ID_ANSWER_FORM);
589 }
590
592 {
593 $this->setQuestionIdParamterForPageEditorCmds($this->getQuestionId());
594 }
595
597 Uuid $question_id
598 ): void {
599 $this->setQuestionIdParamterForPageEditorCmds($question_id);
600
601 $this->ctrl->setParameterByClass(
602 \QstsQuestionPageGUI::class,
603 self::PARAMETER_STRING_HIER_ID,
604 '1'
605 );
606
607 [, $create_mode_token] = $this->url_builder->acquireParameter(
608 self::QUERY_PARAMETER_NAME_SPACE,
609 self::TOKEN_STRING_CREATE_MODE
610 );
611
612 $this->ctrl->setParameterByClass(
613 \QstsQuestionPageGUI::class,
614 $create_mode_token->getName(),
615 '1'
616 );
617 }
618
619 public function isCreateAndNewAction(): bool
620 {
621 return $this->http->wrapper()->query()->has(
622 $this->buildURLBuilderTokenForCreateAndNew()->getName()
623 );
624 }
625
627 {
628 return new URLBuilderToken(
629 self::QUERY_PARAMETER_NAME_SPACE,
630 self::TOKEN_STRING_CREATE_AND_NEW
631 );
632 }
633
635 Uuid $question_id
636 ): void {
637 $this->ctrl->setParameterByClass(
638 \QstsQuestionPageGUI::class,
639 $this->question_id_token->getName(),
640 $question_id->toString()
641 );
642 }
643
645 {
646 if (!$this->is_in_creation_context) {
647 return $this->withDefaultSubAction()->getUrlBuilder();
648 }
649
650 if (!$this->isCreateModeSimple()) {
651 return new URLBuilder(
652 new URI(
653 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(
654 \QstsQuestionPageGUI::class,
655 'edit'
656 )
657 )
658 );
659 }
660
661 return $this->withActionParameter(
662 Edit::ACTION_DELETE_QUESTIONS
663 )->withSubActionParameter(
664 Edit::ACTION_DELETE_QUESTIONS
665 )->getUrlBuilder()->withParameter(
666 $this->table_row_token,
667 [$this->getQuestionId()->toString()]
668 );
669 }
670
672 URI $base_uri
673 ): void {
674 [
675 $this->url_builder,
676 $this->table_row_token,
677 $this->question_id_token
678 ] = (new URLBuilder($base_uri))
679 ->acquireParameters(
680 self::QUERY_PARAMETER_NAME_SPACE,
681 self::TOKEN_STRING_TABLE_ROW_ID,
682 self::TOKEN_STRING_QUESTION_ID
683 );
684 }
685
688 ): string {
689 return $this->http->wrapper()->query()->retrieve(
690 $token->getName(),
691 $this->buildStringTrafo()
692 );
693 }
694
696 {
697 return $this->refinery->byTrying([
698 $this->refinery->kindlyTo()->string(),
699 $this->refinery->always('')
700 ]);
701 }
702
703 private function buildRetrieveUuidClosure(): \Closure
704 {
705 return fn($v): Uuid => is_string($v)
706 ? $this->uuid_factory->fromString($v)
707 : throw new \UnexpectedValueException();
708 }
709}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
Class Services.
Definition: Services.php:43
__construct(private readonly \ilCtrl $ctrl, private readonly HTTPServices $http, private readonly Refinery $refinery, private readonly Language $lng, private readonly \ilTabsGUI $tabs_gui, private readonly UuidFactory $uuid_factory, private readonly Factory $presentation_factory, private readonly Editability $editability, private readonly RequiredCapabilities $required_capabilities, private readonly int $parent_obj_id, URI $base_uri)
addEditAnswerFormSubTab(string $sub_action, string $language_variable)
getAnswerFormId()
Returns the answer form id of the current context either from the answer form properties,...
getQuestionIds()
This function will either return the QuestionIds from the $_GET parameter for row ids OR from an Inte...
getName()
Get the full name of the token including its namespace.
buildURI()
Get a URI representation of the full URL including query string and fragment/hash.
Definition: URLBuilder.php:214
@ilCtrl_Calls QstsQuestionPageGUI: ilPageEditorGUI, ilEditClipboardGUI @ilCtrl_Calls QstsQuestionPage...
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
toString()
Converts this UUID into a string representation.
A transformation is a function from one datatype to another.
static http()
Fetches the global http state from ILIAS.
global $lng
Definition: privfeed.php:26
$token
Definition: xapitoken.php:69