ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAccessibilityCriterionFormGUI.php
Go to the documentation of this file.
1<?php
2
20
25{
28 protected string $formAction;
29 protected ilObjUser $actor;
30 protected string $saveCommand;
31 protected string $cancelCommand;
32 protected string $translatedError = '';
34
35 public function __construct(
40 string $formAction = '',
41 string $saveCommand = 'saveDocument',
42 string $cancelCommand = 'showDocuments'
43 ) {
44 $this->document = $document;
45 $this->assignment = $assignment;
46 $this->criterionTypeFactory = $criterionTypeFactory;
47 $this->actor = $actor;
48 $this->formAction = $formAction;
49 $this->saveCommand = $saveCommand;
50 $this->cancelCommand = $cancelCommand;
51
53
54 $this->initForm();
55 }
56
57 public function setCheckInputCalled(bool $status): void
58 {
59 $this->check_input_called = $status;
60 }
61
62 protected function initForm(): void
63 {
64 if ($this->assignment->getId() > 0) {
65 $this->setTitle($this->lng->txt('acc_form_edit_criterion_head'));
66 } else {
67 $this->setTitle($this->lng->txt('acc_form_attach_criterion_head'));
68 }
69
70 $this->setFormAction($this->formAction);
71
72 $document = new ilNonEditableValueGUI($this->lng->txt('acc_document'));
73 $document->setValue($this->document->getTitle());
74 $this->addItem($document);
75
76
77 if ($this->criterionTypeFactory->hasOnlyOneCriterion()) {
78 $criteriaSelection = new ilHiddenInputGUI('criterion');
79 $criteriaSelection->setRequired(true);
80 $criteriaSelection->setValue($this->assignment->getCriterionId());
81
82 foreach ($this->criterionTypeFactory->getTypesByIdentMap() as $criterion) {
84 if (!$this->assignment->getId()) {
85 $criteriaSelection->setValue($criterion->getTypeIdent());
86 }
87
88 $criterionGui = $criterion->ui($this->lng);
89 if ($this->assignment->getCriterionId() == $criterion->getTypeIdent()) {
90 $languageSelection = $criterionGui->getSelection($this->assignment->getCriterionValue());
91 } else {
92 $languageSelection = $criterionGui->getSelection(new ilAccessibilityCriterionConfig());
93 }
94 $this->addItem($languageSelection);
95 }
96 } else {
97 $criteriaSelection = new ilRadioGroupInputGUI($this->lng->txt('acc_form_criterion'), 'criterion');
98 $criteriaSelection->setRequired(true);
99 $criteriaSelection->setValue($this->assignment->getCriterionId());
100
101 $first = true;
102 foreach ($this->criterionTypeFactory->getTypesByIdentMap() as $criterion) {
104 if (!$this->assignment->getId() && $first) {
105 $criteriaSelection->setValue($criterion->getTypeIdent());
106 }
107 $first = false;
108
109 $criterionGui = $criterion->ui($this->lng);
110 if ($this->assignment->getCriterionId() == $criterion->getTypeIdent()) {
111 $criterionGui->appendOption(
112 $criteriaSelection,
113 $this->assignment->getCriterionValue()
114 );
115 } else {
116 $criterionGui->appendOption($criteriaSelection, new ilAccessibilityCriterionConfig());
117 }
118 }
119 }
120 $this->addItem($criteriaSelection);
121
122 $this->addCommandButton($this->saveCommand, $this->lng->txt('save'));
123 $this->addCommandButton($this->cancelCommand, $this->lng->txt('cancel'));
124 }
125
126 public function hasTranslatedError(): bool
127 {
128 return strlen($this->translatedError) > 0;
129 }
130
131 public function getTranslatedError(): string
132 {
134 }
135
139 public function saveObject(): bool
140 {
141 if (!$this->fillObject()) {
142 $this->setValuesByPost();
143 return false;
144 }
145
146 $uniqueAssignmentConstraint = new ilAccessibilityDocumentCriterionAssignmentConstraint(
147 $this->criterionTypeFactory,
148 $this->document,
149 new Factory(),
150 $this->lng
151 );
152
153 if (!$uniqueAssignmentConstraint->accepts($this->assignment)) {
154 $this->getItemByPostVar('criterion')->setAlert($this->lng->txt('acc_criterion_assignment_must_be_unique_insert'));
155 if ($this->assignment->getId() > 0) {
156 $this->getItemByPostVar('criterion')->setAlert($this->lng->txt('acc_criterion_assignment_must_be_unique_update'));
157 }
158
159 $this->translatedError = $this->lng->txt('form_input_not_valid');
160 $this->setValuesByPost();
161 return false;
162 }
163
164 if (!$this->assignment->getId()) {
165 $this->document->attachCriterion($this->assignment);
166 }
167 $this->document->save();
168
169 return true;
170 }
171
172 protected function fillObject(): bool
173 {
174 if (!$this->checkInput()) {
175 return false;
176 }
177
178 try {
179 $criterionType = $this->criterionTypeFactory->findByTypeIdent($this->getInput('criterion'));
180 $criterionGui = $criterionType->ui($this->lng);
181
182 $this->assignment->setCriterionId($criterionType->getTypeIdent());
183 $this->assignment->setCriterionValue($criterionGui->getConfigByForm($this));
184
185 if ($this->assignment->getId() > 0) {
186 $this->assignment->setLastModifiedUsrId($this->actor->getId());
187 } else {
188 $this->assignment->setOwnerUsrId($this->actor->getId());
189 }
190 } catch (Exception $e) {
191 $this->getItemByPostVar('criterion')->setAlert($e->getMessage());
192 $this->translatedError = $this->lng->txt('form_input_not_valid');
193 return false;
194 }
195
196 return true;
197 }
198}
Builds data types.
Definition: Factory.php:36
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilAccessibilityCriterionFormGUI.
ilAccessibilityCriterionTypeFactoryInterface $criterionTypeFactory
__construct(ilAccessibilityDocument $document, ilAccessibilityDocumentCriterionAssignment $assignment, ilAccessibilityCriterionTypeFactoryInterface $criterionTypeFactory, ilObjUser $actor, string $formAction='', string $saveCommand='saveDocument', string $cancelCommand='showDocuments')
ilAccessibilityDocumentCriterionAssignment $assignment
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFormAction(string $a_formaction)
This class represents a hidden form property in a property form.
This class represents a non editable value in a property form.
User class.
This class represents a property form user interface.
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc