ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSurveyConstraintsGUI.php
Go to the documentation of this file.
1<?php
2
24{
25 protected \ILIAS\Survey\Editing\EditingGUIRequest $request;
26 protected \ILIAS\Survey\Editing\EditManager $edit_manager;
29 protected ilCtrl $ctrl;
30 protected ilLanguage $lng;
33
34 public function __construct(
35 ilObjSurveyGUI $a_parent_gui
36 ) {
37 global $DIC;
38
39 $this->access = $DIC->access();
40 $ilCtrl = $DIC->ctrl();
41 $lng = $DIC->language();
42 $tpl = $DIC["tpl"];
43
44 $this->parent_gui = $a_parent_gui;
45
47 $survey = $this->parent_gui->getObject();
48 $this->object = $survey;
49
50 $this->ctrl = $ilCtrl;
51 $this->lng = $lng;
52 $this->tpl = $tpl;
53 $this->edit_manager = $DIC->survey()
54 ->internal()
55 ->domain()
56 ->edit();
57 $this->request = $DIC->survey()
58 ->internal()
59 ->gui()
60 ->editing()
61 ->request();
62 }
63
64 public function executeCommand(): void
65 {
66 $ilCtrl = $this->ctrl;
67
68 $cmd = $ilCtrl->getCmd("constraints");
69 $cmd .= "Object";
70
71 $this->$cmd();
72 }
73
77 public function constraintsObject(): void
78 {
79 $step = $this->request->getStep();
80 switch ($step) {
81 case 1:
82 $this->constraintStep1Object();
83 return;
84 case 3:
85 case 2:
86 return;
87 }
88
89 $hasDatasets = ilObjSurvey::_hasDatasets($this->object->getSurveyId());
90
91 $tbl = new SurveyConstraintsTableGUI($this, "constraints", $this->object, $hasDatasets);
92
93 $mess = "";
94 if ($hasDatasets) {
96 $mess = $mbox->getHTML();
97 } else {
98 $this->edit_manager->setConstraintStructure($tbl->getStructure());
99 }
100
101 $this->tpl->setContent($mess . $tbl->getHTML());
102 }
103
107 public function constraintsAddObject(): void
108 {
109 if ($this->request->getConstraintPar("v") === '') {
110 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_enter_value_for_valid_constraint"));
111 $this->constraintStep3Object();
112 return;
113 }
114 $survey_questions = $this->object->getSurveyQuestions();
115 $structure = $this->edit_manager->getConstraintStructure();
116 $include_elements = $this->edit_manager->getConstraintElements();
117 foreach ($include_elements as $elementCounter) {
118 if (is_array($structure[$elementCounter])) {
119 if ($this->request->getPrecondition() !== '') {
120 $this->object->updateConstraint(
121 $this->request->getPrecondition(),
122 $this->request->getConstraintPar("q"),
123 $this->request->getConstraintPar("r"),
124 $this->request->getConstraintPar("v"),
125 $this->request->getConstraintPar("c")
126 );
127 } else {
128 $constraint_id = $this->object->addConstraint(
129 $this->request->getConstraintPar("q"),
130 $this->request->getConstraintPar("r"),
131 $this->request->getConstraintPar("v"),
132 $this->request->getConstraintPar("c")
133 );
134 foreach ($structure[$elementCounter] as $key => $question_id) {
135 $this->object->addConstraintToQuestion($question_id, $constraint_id);
136 }
137 }
138 if (count($structure[$elementCounter]) > 1) {
139 $this->object->updateConjunctionForQuestions(
140 $structure[$elementCounter],
141 $this->request->getConstraintPar("c")
142 );
143 }
144 }
145 }
146 $this->edit_manager->clearConstraintElements();
147 $this->edit_manager->clearConstraintStructure();
148 $this->ctrl->redirect($this, "constraints");
149 }
150
154 public function constraintStep1Object($start = null): void
155 {
156 $survey_questions = $this->object->getSurveyQuestions();
157 $structure = $this->edit_manager->getConstraintStructure();
158 if (is_null($start)) {
159 $start = $this->request->getStart();
160 }
161 $option_questions = array();
162 for ($i = 1; $i < $start; $i++) {
163 if (is_array($structure[$i])) {
164 foreach ($structure[$i] as $key => $question_id) {
165 if ($survey_questions[$question_id]["usableForPrecondition"]) {
166 $option_questions[] = array("question_id" => $survey_questions[$question_id]["question_id"],
167 "title" => $survey_questions[$question_id]["title"],
168 "type_tag" => $survey_questions[$question_id]["type_tag"]
169 );
170 }
171 }
172 }
173 }
174 if (count($option_questions) === 0) {
175 $this->edit_manager->clearConstraintElements();
176 $this->edit_manager->clearConstraintStructure();
177 $this->tpl->setOnScreenMessage('info', $this->lng->txt("constraints_no_nonessay_available"), true);
178 $this->ctrl->redirect($this, "constraints");
179 }
180 $this->constraintForm(1, $this->getConstraintParsFromPost(), $survey_questions, $option_questions);
181 }
182
186 public function constraintStep2Object(): void
187 {
188 $survey_questions = $this->object->getSurveyQuestions();
189 $option_questions = array();
190 $q = $this->request->getConstraintPar("q");
191 $option_questions[] = array(
192 "question_id" => $q,
193 "title" => $survey_questions[$q]["title"],
194 "type_tag" => $survey_questions[$q]["type_tag"]
195 );
196 $this->constraintForm(2, $this->getConstraintParsFromPost(), $survey_questions, $option_questions);
197 }
198
202 public function constraintStep3Object(): void
203 {
204 $survey_questions = $this->object->getSurveyQuestions();
205 $option_questions = array();
206 if ($this->request->getPrecondition() !== '') {
207 if (!$this->validateConstraintForEdit($this->request->getPrecondition())) {
208 $this->ctrl->redirect($this, "constraints");
209 }
210
211 $pc = $this->object->getPrecondition($this->request->getPrecondition());
212 $postvalues = array(
213 "c" => $pc["conjunction"],
214 "q" => $pc["question_fi"],
215 "r" => $pc["relation_id"],
216 "v" => $pc["value"]
217 );
218 $option_questions[] = array("question_id" => $pc["question_fi"],
219 "title" => $survey_questions[$pc["question_fi"]]["title"],
220 "type_tag" => $survey_questions[$pc["question_fi"]]["type_tag"]
221 );
222 $this->constraintForm(3, $postvalues, $survey_questions, $option_questions);
223 } else {
224 $q = $this->request->getConstraintPar("q");
225 $option_questions[] = array(
226 "question_id" => $q,
227 "title" => $survey_questions[$q]["title"],
228 "type_tag" => $survey_questions[$q]["type_tag"]
229 );
230 $this->constraintForm(3, $this->getConstraintParsFromPost(), $survey_questions, $option_questions);
231 }
232 }
233
234 protected function getConstraintParsFromPost(): array
235 {
236 return [
237 "c" => $this->request->getConstraintPar("c"),
238 "q" => $this->request->getConstraintPar("q"),
239 "r" => $this->request->getConstraintPar("r"),
240 "v" => $this->request->getConstraintPar("v")
241 ];
242 }
243
244 // output constraint editing form
245 public function constraintForm(
246 int $step,
247 array $postvalues,
248 array $survey_questions,
249 ?array $questions = null
250 ): void {
251 if ((string) $this->request->getStart() !== '') {
252 $this->ctrl->setParameter($this, "start", $this->request->getStart());
253 }
254 $this->ctrl->saveParameter($this, "precondition");
255 $form = new ilPropertyFormGUI();
256 $form->setFormAction($this->ctrl->getFormAction($this));
257 $form->setTableWidth("100%");
258 $form->setId("constraintsForm");
259
260 $constraint_structure = $this->edit_manager->getConstraintStructure();
261
262 // #9366
263 $title = array();
264 $title_ids = $this->edit_manager->getConstraintElements();
265 if (!$title_ids) {
266 $title_ids = array($this->request->getStart());
267 }
268 foreach ($title_ids as $title_id) {
269 // question block
270 if ($survey_questions[$constraint_structure[$title_id][0]]["questionblock_id"] > 0) {
271 $title[] = $this->lng->txt("questionblock") . ": " . $survey_questions[$constraint_structure[$title_id][0]]["questionblock_title"];
272 }
273 // question
274 else {
275 $title[] = $this->lng->txt($survey_questions[$constraint_structure[$title_id][0]]["type_tag"]) . ": " .
276 $survey_questions[$constraint_structure[$title_id][0]]["title"];
277 }
278 }
279 $header = new ilFormSectionHeaderGUI();
280 $header->setTitle(implode("<br/>", $title));
281 $form->addItem($header);
282
283 $fulfilled = new ilRadioGroupInputGUI($this->lng->txt("constraint_fulfilled"), "c");
284 $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_and"), '0', ''));
285 $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_or"), '1', ''));
286 $fulfilled->setValue((strlen($postvalues['c'])) ? $postvalues['c'] : 0);
287 $form->addItem($fulfilled);
288
289 $step1 = new ilSelectInputGUI($this->lng->txt("step") . " 1: " . $this->lng->txt("select_prior_question"), "q");
290 $options = array();
291 if (is_array($questions)) {
292 foreach ($questions as $question) {
293 $options[$question["question_id"]] = $question["title"] . " (" . SurveyQuestion::_getQuestionTypeName($question["type_tag"]) . ")";
294 }
295 }
296 $step1->setOptions($options);
297 $step1->setValue($postvalues["q"]);
298 $form->addItem($step1);
299
300 if ($step > 1) {
301 $relations = $this->object->getAllRelations();
302 $step2 = new ilSelectInputGUI($this->lng->txt("step") . " 2: " . $this->lng->txt("select_relation"), "r");
303 $options = array();
304 foreach ($relations as $rel_id => $relation) {
305 if (in_array($relation["short"], $survey_questions[$postvalues["q"]]["availableRelations"])) {
306 $options[$rel_id] = $relation['short'];
307 }
308 }
309 $step2->setOptions($options);
310 $step2->setValue($postvalues["r"]);
311 $form->addItem($step2);
312 }
313
314 if ($step > 2) {
315 $variables = $this->object->getVariables($postvalues["q"]);
316 $question_type = $survey_questions[$postvalues["q"]]["type_tag"];
317 SurveyQuestion::_includeClass($question_type);
318 $question = new $question_type();
319 $question->loadFromDb($postvalues["q"]);
320
321 $step3 = $question->getPreconditionSelectValue($postvalues["v"], $this->lng->txt("step") . " 3: " . $this->lng->txt("select_value"), "v");
322 $form->addItem($step3);
323 }
324
325 $cmd_back = "";
326 $cmd_continue = "";
327
328 switch ($step) {
329 case 1:
330 $cmd_continue = "constraintStep2";
331 $cmd_back = "constraints";
332 break;
333 case 2:
334 $cmd_continue = "constraintStep3";
335 $cmd_back = "constraintStep1";
336 break;
337 case 3:
338 $cmd_continue = "constraintsAdd";
339 $cmd_back = "constraintStep2";
340 break;
341 }
342 $form->addCommandButton($cmd_back, $this->lng->txt("back"));
343 $form->addCommandButton($cmd_continue, $this->lng->txt("continue"));
344
345 $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
346 }
347
353 protected function validateConstraintForEdit(
354 int $a_id
355 ): bool {
356 $ilAccess = $this->access;
357
358 if (ilObjSurvey::_hasDatasets($this->object->getSurveyId())) {
359 return false;
360 }
361 if (!$ilAccess->checkAccess("write", "", $this->object->getRefId())) {
362 return false;
363 }
364
365 return true;
366 }
367
371 public function confirmDeleteConstraintsObject(): void
372 {
373 $id = (int) $this->request->getPrecondition();
374 if (!$this->validateConstraintForEdit($id)) {
375 $this->ctrl->redirect($this, "constraints");
376 }
377
378 $constraint = $this->object->getPrecondition($id);
379 $questions = $this->object->getSurveyQuestions();
380 $question = $questions[$constraint["question_fi"]];
381 $relation = $questions[$constraint["ref_question_fi"]];
382 $relation = $relation["title"];
383
384 // see ilSurveyConstraintsTableGUI
385 $question_type = SurveyQuestion::_getQuestionType($constraint["question_fi"]);
386 SurveyQuestion::_includeClass($question_type);
387 $question_obj = new $question_type();
388 $question_obj->loadFromDb($constraint["question_fi"]);
389 $valueoutput = $question_obj->getPreconditionValueOutput($constraint["value"]);
390
391 $title = $question["title"] . " " . $constraint["shortname"] . " " . $valueoutput;
392
393 $this->ctrl->saveParameter($this, "precondition");
394
395 $cgui = new ilConfirmationGUI();
396 $cgui->setHeaderText(sprintf($this->lng->txt("survey_sure_delete_constraint"), $title, $relation));
397
398 $cgui->setFormAction($this->ctrl->getFormAction($this, "deleteConstraints"));
399 $cgui->setCancel($this->lng->txt("cancel"), "constraints");
400 $cgui->setConfirm($this->lng->txt("confirm"), "deleteConstraints");
401
402 $this->tpl->setContent($cgui->getHTML());
403 }
404
405 public function deleteConstraintsObject(): void
406 {
407 $id = (int) $this->request->getPrecondition();
408 if ($this->validateConstraintForEdit($id)) {
409 $this->tpl->setOnScreenMessage('success', $this->lng->txt("survey_constraint_deleted"), true);
410 $this->object->deleteConstraint($id);
411 }
412
413 $this->ctrl->redirect($this, "constraints");
414 }
415
416 public function createConstraintsObject(): void
417 {
418 $include_elements = $this->request->getIncludeElements();
419 if (count($include_elements) === 0) {
420 $this->tpl->setOnScreenMessage('info', $this->lng->txt("constraints_no_questions_or_questionblocks_selected"), true);
421 $this->ctrl->redirect($this, "constraints");
422 } elseif (count($include_elements) >= 1) {
423 $this->edit_manager->setConstraintElements($include_elements);
424 sort($include_elements, SORT_NUMERIC);
425 $this->constraintStep1Object($include_elements[0]);
426 }
427 }
428
432 public function editPreconditionObject(): void
433 {
434 if (!$this->validateConstraintForEdit($this->request->getPrecondition())) {
435 $this->ctrl->redirect($this, "constraints");
436 }
437
438 $this->edit_manager->setConstraintElements([$this->request->getStart()]);
439 $this->ctrl->setParameter($this, "precondition", $this->request->getPrecondition());
440 $this->ctrl->setParameter($this, "start", $this->request->getStart());
441 $this->ctrl->redirect($this, "constraintStep3");
442 }
443}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$structure
TOTAL STRUCTURE.
$relation
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getQuestionTypeName(string $type_tag)
Return the translation for a given question type.
static _includeClass(string $question_type, int $gui=0)
Include the php class file for a given question type.
static _getQuestionType(int $question_id)
Returns the question type of a question with a given id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
getCmd(?string $fallback_command=null)
@inheritDoc
This class represents a section header in a property form.
language handling
@ilCtrl_Calls ilObjSurveyGUI: ilSurveyEvaluationGUI, ilSurveyExecutionGUI @ilCtrl_Calls ilObjSurveyGU...
static _hasDatasets(int $survey_id)
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
constraintStep2Object()
Handles the second step of the precondition add action.
constraintStep3Object()
Handles the third step of the precondition add action.
ILIAS Survey Editing EditManager $edit_manager
constraintStep1Object($start=null)
Handles the first step of the precondition add action.
validateConstraintForEdit(int $a_id)
Validate if given constraint id is part of current survey and there are sufficient permissions to edi...
ilGlobalTemplateInterface $tpl
confirmDeleteConstraintsObject()
Delete constraint confirmation.
constraintsObject()
Administration page for survey constraints.
constraintsAddObject()
Add a precondition for a survey question or question block.
constraintForm(int $step, array $postvalues, array $survey_questions, ?array $questions=null)
ILIAS Survey Editing EditingGUIRequest $request
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23