ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.ConfigurationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27use ILIAS\UI\Factory as UIFactory;
28use ILIAS\UI\Renderer as UIRenderer;
30
32{
33 private const string CMD_DEFAULT = 'view';
34 private const string CMD_SAVE = 'save';
35
36 public function __construct(
37 private readonly \ilCtrl $ctrl,
38 private readonly HTTP $http,
39 private readonly Language $lng,
40 private readonly Refinery $refinery,
41 private readonly \ilGlobalTemplateInterface $tpl,
42 private readonly UIFactory $ui_factory,
43 private readonly UIRenderer $ui_renderer,
44 private readonly ConfigurationRepository $repository
45 ) {
46 }
47
48 public function executeCommand(): void
49 {
50 $cmd = $this->ctrl->getCmd(self::CMD_DEFAULT) . 'Cmd';
51 $this->$cmd();
52 }
53
54 private function viewCmd(
55 ?StandardForm $form = null
56 ): void {
57 $this->tpl->setContent(
58 $this->ui_renderer->render(
59 $form ?? $this->buildSettingsForm()
60 )
61 );
62 }
63
64 private function saveCmd(): void
65 {
66 $form = $this->buildSettingsForm()->withRequest($this->http->request());
67 $data = $form->getData();
68 if ($data === null) {
69 $this->viewCmd($form);
70 }
71
72 $this->repository->persistCreateMode(
73 $data['default_user_settings']['create_mode']
74 );
75
76 $this->ctrl->redirectByClass(
77 [
78 \ilAdministrationGUI::class,
79 \ilObjQuestionsGUI::class,
80 self::class
81 ]
82 );
83 }
84
85 private function buildSettingsForm(): StandardForm
86 {
87 return $this->ui_factory->input()->container()->form()->standard(
88 $this->ctrl->getLinkTargetByClass(
89 [
90 \ilAdministrationGUI::class,
91 \ilObjQuestionsGUI::class,
92 self::class
93 ],
94 self::CMD_SAVE
95 ),
96 [
97 'default_user_settings' => $this->ui_factory->input()->field()->section(
98 [
99 'create_mode' => $this->repository->getInputForCreateMode(
100 $this->ui_factory->input()->field(),
101 $this->lng,
102 $this->refinery
103 )->withAdditionalTransformation(
104 $this->refinery->custom()->transformation(
105 static fn(string $v): CreateModes => CreateModes::tryFrom($v)
106 ?? CreateModes::getDefaultMode()
107 )
108 )
109 ],
110 $this->lng->txt('default_user_settings')
111 )
112 ]
113 );
114 }
115}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:43
__construct(private readonly \ilCtrl $ctrl, private readonly HTTP $http, private readonly Language $lng, private readonly Refinery $refinery, private readonly \ilGlobalTemplateInterface $tpl, private readonly UIFactory $ui_factory, private readonly UIRenderer $ui_renderer, private readonly ConfigurationRepository $repository)
Class ilCtrl provides processing control methods.
This describes a standard form.
Definition: Standard.php:30
An entity that renders components to a string output.
Definition: Renderer.php:31
static http()
Fetches the global http state from ILIAS.
readonly ilGlobalTemplateInterface $tpl
global $lng
Definition: privfeed.php:26
$data
Definition: storeScorm.php:45