ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilAccessibilityCriterionFormGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
3
5
10{
12 protected $document;
13
15 protected $assignment;
16
18 protected $formAction;
19
21 protected $actor;
22
24 protected $saveCommand;
25
27 protected $cancelCommand;
28
30 protected $translatedError = '';
31
34
45 public function __construct(
50 string $formAction = '',
51 string $saveCommand = 'saveDocument',
52 string $cancelCommand = 'showDocuments'
53 ) {
54 $this->document = $document;
55 $this->assignment = $assignment;
56 $this->criterionTypeFactory = $criterionTypeFactory;
57 $this->actor = $actor;
58 $this->formAction = $formAction;
59 $this->saveCommand = $saveCommand;
60 $this->cancelCommand = $cancelCommand;
61
63
64 $this->initForm();
65 }
66
70 public function setCheckInputCalled(bool $status) : void
71 {
72 $this->check_input_called = $status;
73 }
74
78 protected function initForm() : void
79 {
80 if ($this->assignment->getId() > 0) {
81 $this->setTitle($this->lng->txt('acc_form_edit_criterion_head'));
82 } else {
83 $this->setTitle($this->lng->txt('acc_form_attach_criterion_head'));
84 }
85
86 $this->setFormAction($this->formAction);
87
88 $document = new ilNonEditableValueGUI($this->lng->txt('acc_document'));
89 $document->setValue($this->document->getTitle());
90 $this->addItem($document);
91
92
93 if ($this->criterionTypeFactory->hasOnlyOneCriterion()) {
94 $criteriaSelection = new ilHiddenInputGUI('criterion');
95 $criteriaSelection->setRequired(true);
96 $criteriaSelection->setValue($this->assignment->getCriterionId());
97
98 foreach ($this->criterionTypeFactory->getTypesByIdentMap() as $criterion) {
100 if (!$this->assignment->getId()) {
101 $criteriaSelection->setValue($criterion->getTypeIdent());
102 }
103
104 $criterionGui = $criterion->ui($this->lng);
105 if ($this->assignment->getCriterionId() == $criterion->getTypeIdent()) {
106 $languageSelection = $criterionGui->getSelection($this->assignment->getCriterionValue());
107 } else {
108 $languageSelection = $criterionGui->getSelection(new ilAccessibilityCriterionConfig());
109 }
110 $this->addItem($languageSelection);
111 }
112 $this->addItem($criteriaSelection);
113 } else {
114 $criteriaSelection = new ilRadioGroupInputGUI($this->lng->txt('acc_form_criterion'), 'criterion');
115 $criteriaSelection->setRequired(true);
116 $criteriaSelection->setValue($this->assignment->getCriterionId());
117
118 $first = true;
119 foreach ($this->criterionTypeFactory->getTypesByIdentMap() as $criterion) {
121 if (!$this->assignment->getId() && $first) {
122 $criteriaSelection->setValue($criterion->getTypeIdent());
123 }
124 $first = false;
125
126 $criterionGui = $criterion->ui($this->lng);
127 if ($this->assignment->getCriterionId() == $criterion->getTypeIdent()) {
128 $criterionGui->appendOption(
129 $criteriaSelection,
130 $this->assignment->getCriterionValue()
131 );
132 } else {
133 $criterionGui->appendOption($criteriaSelection, new ilAccessibilityCriterionConfig());
134 }
135 }
136 $this->addItem($criteriaSelection);
137 }
138
139 $this->addCommandButton($this->saveCommand, $this->lng->txt('save'));
140 $this->addCommandButton($this->cancelCommand, $this->lng->txt('cancel'));
141 }
142
146 public function hasTranslatedError() : bool
147 {
148 return strlen($this->translatedError) > 0;
149 }
150
154 public function getTranslatedError() : string
155 {
157 }
158
163 public function saveObject() : bool
164 {
165 if (!$this->fillObject()) {
166 $this->setValuesByPost();
167 return false;
168 }
169
170 $uniqueAssignmentConstraint = new ilAccessibilityDocumentCriterionAssignmentConstraint(
171 $this->criterionTypeFactory,
172 $this->document,
173 new Factory(),
174 $this->lng
175 );
176
177 if (!$uniqueAssignmentConstraint->accepts($this->assignment)) {
178 $this->getItemByPostVar('criterion')->setAlert($this->lng->txt('acc_criterion_assignment_must_be_unique_insert'));
179 if ($this->assignment->getId() > 0) {
180 $this->getItemByPostVar('criterion')->setAlert($this->lng->txt('acc_criterion_assignment_must_be_unique_update'));
181 }
182
183 $this->translatedError = $this->lng->txt('form_input_not_valid');
184 $this->setValuesByPost();
185 return false;
186 }
187
188 if (!$this->assignment->getId()) {
189 $this->document->attachCriterion($this->assignment);
190 }
191 $this->document->save();
192
193 return true;
194 }
195
199 protected function fillObject() : bool
200 {
201 if (!$this->checkInput()) {
202 return false;
203 }
204
205 try {
206 $criterionType = $this->criterionTypeFactory->findByTypeIdent($this->getInput('criterion'));
207 $criterionGui = $criterionType->ui($this->lng);
208
209 $this->assignment->setCriterionId($criterionType->getTypeIdent());
210 $this->assignment->setCriterionValue($criterionGui->getConfigByForm($this));
211
212 if ($this->assignment->getId() > 0) {
213 $this->assignment->setLastModifiedUsrId($this->actor->getId());
214 } else {
215 $this->assignment->setOwnerUsrId($this->actor->getId());
216 }
217 } catch (Exception $e) {
218 $this->getItemByPostVar('criterion')->setAlert($e->getMessage());
219 $this->translatedError = $this->lng->txt('form_input_not_valid');
220 return false;
221 }
222
223 return true;
224 }
225}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
Class ilAccessibilityCriterionConfig.
Class ilAccessibilityCriterionFormGUI.
__construct(ilAccessibilityDocument $document, ilAccessibilityDocumentCriterionAssignment $assignment, ilAccessibilityCriterionTypeFactoryInterface $criterionTypeFactory, ilObjUser $actor, string $formAction='', string $saveCommand='saveDocument', string $cancelCommand='showDocuments')
ilAccessibilityCriterionFormGUI constructor.
Class ilAccessibilityDocument.
setFormAction($a_formaction)
Set FormAction.
This class represents a hidden form property in a property form.
This class represents a non editable value in a property form.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
addCommandButton($a_cmd, $a_text, $a_id="")
Add Command button.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
checkInput()
Check Post Input.
setValuesByPost()
Set form values from POST values.
getItemByPostVar($a_post_var)
Get Item by POST variable.
setTitle($a_title)
Set Title.
This class represents a property in a property form.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc