ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilSurveyConstraintsGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
15{
19 protected $ctrl;
20
24 protected $lng;
25
29 protected $tpl;
30
34 protected $access;
35
36 public function __construct(ilObjSurveyGUI $a_parent_gui)
37 {
38 global $DIC;
39
40 $this->access = $DIC->access();
41 $ilCtrl = $DIC->ctrl();
42 $lng = $DIC->language();
43 $tpl = $DIC["tpl"];
44
45 $this->parent_gui = $a_parent_gui;
46 $this->object = $this->parent_gui->object;
47
48 $this->ctrl = $ilCtrl;
49 $this->lng = $lng;
50 $this->tpl = $tpl;
51 }
52
53 public function executeCommand()
54 {
56
57 $cmd = $ilCtrl->getCmd("constraints");
58 $cmd .= "Object";
59
60 $this->$cmd();
61 }
62
66 public function constraintsObject()
67 {
68 $step = 0;
69 if (array_key_exists("step", $_GET)) {
70 $step = (int) $_GET["step"];
71 }
72 switch ($step) {
73 case 1:
74 $this->constraintStep1Object();
75 return;
76 break;
77 case 2:
78 return;
79 break;
80 case 3:
81 return;
82 break;
83 }
84
85 $hasDatasets = ilObjSurvey::_hasDatasets($this->object->getSurveyId());
86
87 $tbl = new SurveyConstraintsTableGUI($this, "constraints", $this->object, $hasDatasets);
88
89 $mess = "";
90 if ($hasDatasets) {
92 $mess = $mbox->getHTML();
93 } else {
94 $_SESSION["constraintstructure"] = $tbl->getStructure();
95 }
96
97 $this->tpl->setContent($mess . $tbl->getHTML());
98 }
99
103 public function constraintsAddObject()
104 {
105 if (strlen($_POST["v"]) == 0) {
106 ilUtil::sendFailure($this->lng->txt("msg_enter_value_for_valid_constraint"));
107 return $this->constraintStep3Object();
108 }
109 $survey_questions = &$this->object->getSurveyQuestions();
110 $structure = &$_SESSION["constraintstructure"];
111 $include_elements = $_SESSION["includeElements"];
112 foreach ($include_elements as $elementCounter) {
113 if (is_array($structure[$elementCounter])) {
114 if (strlen($_GET["precondition"])) {
115 $this->object->updateConstraint($_GET['precondition'], $_POST["q"], $_POST["r"], $_POST["v"], $_POST['c']);
116 } else {
117 $constraint_id = $this->object->addConstraint($_POST["q"], $_POST["r"], $_POST["v"], $_POST['c']);
118 foreach ($structure[$elementCounter] as $key => $question_id) {
119 $this->object->addConstraintToQuestion($question_id, $constraint_id);
120 }
121 }
122 if (count($structure[$elementCounter]) > 1) {
123 $this->object->updateConjunctionForQuestions($structure[$elementCounter], $_POST['c']);
124 }
125 }
126 }
127 unset($_SESSION["includeElements"]);
128 unset($_SESSION["constraintstructure"]);
129 $this->ctrl->redirect($this, "constraints");
130 }
131
135 public function constraintStep1Object()
136 {
137 $survey_questions = &$this->object->getSurveyQuestions();
138 $structure = &$_SESSION["constraintstructure"];
139 $start = $_GET["start"];
140 $option_questions = array();
141 for ($i = 1; $i < $start; $i++) {
142 if (is_array($structure[$i])) {
143 foreach ($structure[$i] as $key => $question_id) {
144 if ($survey_questions[$question_id]["usableForPrecondition"]) {
145 array_push($option_questions, array("question_id" => $survey_questions[$question_id]["question_id"], "title" => $survey_questions[$question_id]["title"], "type_tag" => $survey_questions[$question_id]["type_tag"]));
146 }
147 }
148 }
149 }
150 if (count($option_questions) == 0) {
151 unset($_SESSION["includeElements"]);
152 unset($_SESSION["constraintstructure"]);
153 ilUtil::sendInfo($this->lng->txt("constraints_no_nonessay_available"), true);
154 $this->ctrl->redirect($this, "constraints");
155 }
156 $this->constraintForm(1, $_POST, $survey_questions, $option_questions);
157 }
158
162 public function constraintStep2Object()
163 {
164 $survey_questions = &$this->object->getSurveyQuestions();
165 $option_questions = array();
166 array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
167 $this->constraintForm(2, $_POST, $survey_questions, $option_questions);
168 }
169
173 public function constraintStep3Object()
174 {
175 $survey_questions = &$this->object->getSurveyQuestions();
176 $option_questions = array();
177 if (strlen($_GET["precondition"])) {
178 if (!$this->validateConstraintForEdit($_GET["precondition"])) {
179 $this->ctrl->redirect($this, "constraints");
180 }
181
182 $pc = $this->object->getPrecondition($_GET["precondition"]);
183 $postvalues = array(
184 "c" => $pc["conjunction"],
185 "q" => $pc["question_fi"],
186 "r" => $pc["relation_id"],
187 "v" => $pc["value"]
188 );
189 array_push($option_questions, array("question_id" => $pc["question_fi"], "title" => $survey_questions[$pc["question_fi"]]["title"], "type_tag" => $survey_questions[$pc["question_fi"]]["type_tag"]));
190 $this->constraintForm(3, $postvalues, $survey_questions, $option_questions);
191 } else {
192 array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
193 $this->constraintForm(3, $_POST, $survey_questions, $option_questions);
194 }
195 }
196
197 public function constraintForm($step, $postvalues, &$survey_questions, $questions = false)
198 {
199 if (strlen($_GET["start"])) {
200 $this->ctrl->setParameter($this, "start", $_GET["start"]);
201 }
202 $this->ctrl->saveParameter($this, "precondition");
203 $form = new ilPropertyFormGUI();
204 $form->setFormAction($this->ctrl->getFormAction($this));
205 $form->setTableWidth("100%");
206 $form->setId("constraintsForm");
207
208 // #9366
209 $title = array();
210 $title_ids = $_SESSION["includeElements"];
211 if (!$title_ids) {
212 $title_ids = array($_GET["start"]);
213 }
214 foreach ($title_ids as $title_id) {
215 // question block
216 if ($survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["questionblock_id"] > 0) {
217 $title[] = $this->lng->txt("questionblock") . ": " . $survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["questionblock_title"];
218 }
219 // question
220 else {
221 $title[] = $this->lng->txt($survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["type_tag"]) . ": " .
222 $survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["title"];
223 }
224 }
225 $header = new ilFormSectionHeaderGUI();
226 $header->setTitle(implode("<br/>", $title));
227 $form->addItem($header);
228
229 $fulfilled = new ilRadioGroupInputGUI($this->lng->txt("constraint_fulfilled"), "c");
230 $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_and"), '0', ''));
231 $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_or"), '1', ''));
232 $fulfilled->setValue((strlen($postvalues['c'])) ? $postvalues['c'] : 0);
233 $form->addItem($fulfilled);
234
235 $step1 = new ilSelectInputGUI($this->lng->txt("step") . " 1: " . $this->lng->txt("select_prior_question"), "q");
236 $options = array();
237 if (is_array($questions)) {
238 foreach ($questions as $question) {
239 $options[$question["question_id"]] = $question["title"] . " (" . SurveyQuestion::_getQuestionTypeName($question["type_tag"]) . ")";
240 }
241 }
242 $step1->setOptions($options);
243 $step1->setValue($postvalues["q"]);
244 $form->addItem($step1);
245
246 if ($step > 1) {
247 $relations = $this->object->getAllRelations();
248 $step2 = new ilSelectInputGUI($this->lng->txt("step") . " 2: " . $this->lng->txt("select_relation"), "r");
249 $options = array();
250 foreach ($relations as $rel_id => $relation) {
251 if (in_array($relation["short"], $survey_questions[$postvalues["q"]]["availableRelations"])) {
252 $options[$rel_id] = $relation['short'];
253 }
254 }
255 $step2->setOptions($options);
256 $step2->setValue($postvalues["r"]);
257 $form->addItem($step2);
258 }
259
260 if ($step > 2) {
261 $variables = &$this->object->getVariables($postvalues["q"]);
262 $question_type = $survey_questions[$postvalues["q"]]["type_tag"];
263 SurveyQuestion::_includeClass($question_type);
264 $question = new $question_type();
265 $question->loadFromDb($postvalues["q"]);
266
267 $step3 = $question->getPreconditionSelectValue($postvalues["v"], $this->lng->txt("step") . " 3: " . $this->lng->txt("select_value"), "v");
268 $form->addItem($step3);
269 }
270
271 switch ($step) {
272 case 1:
273 $cmd_continue = "constraintStep2";
274 $cmd_back = "constraints";
275 break;
276 case 2:
277 $cmd_continue = "constraintStep3";
278 $cmd_back = "constraintStep1";
279 break;
280 case 3:
281 $cmd_continue = "constraintsAdd";
282 $cmd_back = "constraintStep2";
283 break;
284 }
285 $form->addCommandButton($cmd_back, $this->lng->txt("back"));
286 $form->addCommandButton($cmd_continue, $this->lng->txt("continue"));
287
288 $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
289 }
290
297 protected function validateConstraintForEdit($a_id)
298 {
299 $ilAccess = $this->access;
300
301 if (ilObjSurvey::_hasDatasets($this->object->getSurveyId())) {
302 return false;
303 }
304 if (!$ilAccess->checkAccess("write", "", $this->object->getRefId())) {
305 return false;
306 }
307
308 return true;
309 }
310
315 {
316 $id = (int) $_REQUEST["precondition"];
317 if (!$this->validateConstraintForEdit($id)) {
318 $this->ctrl->redirect($this, "constraints");
319 }
320
321 $constraint = $this->object->getPrecondition($id);
322 $questions = $this->object->getSurveyQuestions();
323 $question = $questions[$constraint["question_fi"]];
324 $relation = $questions[$constraint["ref_question_fi"]];
325 $relation = $relation["title"];
326
327 // see ilSurveyConstraintsTableGUI
328 $question_type = SurveyQuestion::_getQuestionType($constraint["question_fi"]);
329 SurveyQuestion::_includeClass($question_type);
330 $question_obj = new $question_type();
331 $question_obj->loadFromDb($constraint["question_fi"]);
332 $valueoutput = $question_obj->getPreconditionValueOutput($constraint["value"]);
333
334 $title = $question["title"] . " " . $constraint["shortname"] . " " . $valueoutput;
335
336 $this->ctrl->saveParameter($this, "precondition");
337
338 $cgui = new ilConfirmationGUI();
339 $cgui->setHeaderText(sprintf($this->lng->txt("survey_sure_delete_constraint"), $title, $relation));
340
341 $cgui->setFormAction($this->ctrl->getFormAction($this, "deleteConstraints"));
342 $cgui->setCancel($this->lng->txt("cancel"), "constraints");
343 $cgui->setConfirm($this->lng->txt("confirm"), "deleteConstraints");
344
345 $this->tpl->setContent($cgui->getHTML());
346 }
347
351 public function deleteConstraintsObject()
352 {
353 $id = (int) $_REQUEST["precondition"];
354 if ($this->validateConstraintForEdit($id)) {
355 ilUtil::sendSuccess($this->lng->txt("survey_constraint_deleted"), true);
356 $this->object->deleteConstraint($id);
357 }
358
359 $this->ctrl->redirect($this, "constraints");
360 }
361
362 public function createConstraintsObject()
363 {
364 $include_elements = $_POST["includeElements"];
365 if ((!is_array($include_elements)) || (count($include_elements) == 0)) {
366 ilUtil::sendInfo($this->lng->txt("constraints_no_questions_or_questionblocks_selected"), true);
367 $this->ctrl->redirect($this, "constraints");
368 } elseif (count($include_elements) >= 1) {
369 $_SESSION["includeElements"] = $include_elements;
370 sort($include_elements, SORT_NUMERIC);
371 $_GET["start"] = $include_elements[0];
372 $this->constraintStep1Object();
373 }
374 }
375
376 public function editPreconditionObject()
377 {
378 if (!$this->validateConstraintForEdit($_GET["precondition"])) {
379 $this->ctrl->redirect($this, "constraints");
380 }
381
382 $_SESSION["includeElements"] = array($_GET["start"]);
383 $this->ctrl->setParameter($this, "precondition", $_GET["precondition"]);
384 $this->ctrl->setParameter($this, "start", $_GET["start"]);
385 $this->ctrl->redirect($this, "constraintStep3");
386 }
387}
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
TableGUI class for survey constraints.
static _getQuestionTypeName($type_tag)
Return the translation for a given question type tag.
static _getQuestionType($question_id)
Returns the question type of a question with a given id.
static _includeClass($question_type, $gui=0)
Include the php class file for a given question type.
Confirmation screen class.
This class represents a section header in a property form.
Class ilObjSurveyGUI.
static _hasDatasets($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.
Class ilSurveyConstraintsGUI.
constraintStep2Object()
Handles the second step of the precondition add action.
constraintStep3Object()
Handles the third step of the precondition add action.
deleteConstraintsObject()
Delete constraints of a survey.
__construct(ilObjSurveyGUI $a_parent_gui)
constraintStep1Object()
Handles the first step of the precondition add action.
confirmDeleteConstraintsObject()
Delete constraint confirmation.
constraintsObject()
Administration page for survey constraints.
constraintsAddObject()
Add a precondition for a survey question or question block.
validateConstraintForEdit($a_id)
Validate if given constraint id is part of current survey and there are sufficient permissions to edi...
constraintForm($step, $postvalues, &$survey_questions, $questions=false)
Message box for survey, when data is alrady available.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $ilCtrl
Definition: ilias.php:18
$i
Definition: metadata.php:24
$DIC
Definition: xapitoken.php:46