ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 include_once "Modules/Survey/classes/tables/class.SurveyConstraintsTableGUI.php";
88 $tbl = new SurveyConstraintsTableGUI($this, "constraints", $this->object, $hasDatasets);
89
90 $mess = "";
91 if ($hasDatasets) {
93 $mess = $mbox->getHTML();
94 } else {
95 $_SESSION["constraintstructure"] = $tbl->getStructure();
96 }
97
98 $this->tpl->setContent($mess . $tbl->getHTML());
99 }
100
104 public function constraintsAddObject()
105 {
106 if (strlen($_POST["v"]) == 0) {
107 ilUtil::sendFailure($this->lng->txt("msg_enter_value_for_valid_constraint"));
108 return $this->constraintStep3Object();
109 }
110 $survey_questions = &$this->object->getSurveyQuestions();
111 $structure = &$_SESSION["constraintstructure"];
112 $include_elements = $_SESSION["includeElements"];
113 foreach ($include_elements as $elementCounter) {
114 if (is_array($structure[$elementCounter])) {
115 if (strlen($_GET["precondition"])) {
116 $this->object->updateConstraint($_GET['precondition'], $_POST["q"], $_POST["r"], $_POST["v"], $_POST['c']);
117 } else {
118 $constraint_id = $this->object->addConstraint($_POST["q"], $_POST["r"], $_POST["v"], $_POST['c']);
119 foreach ($structure[$elementCounter] as $key => $question_id) {
120 $this->object->addConstraintToQuestion($question_id, $constraint_id);
121 }
122 }
123 if (count($structure[$elementCounter]) > 1) {
124 $this->object->updateConjunctionForQuestions($structure[$elementCounter], $_POST['c']);
125 }
126 }
127 }
128 unset($_SESSION["includeElements"]);
129 unset($_SESSION["constraintstructure"]);
130 $this->ctrl->redirect($this, "constraints");
131 }
132
136 public function constraintStep1Object()
137 {
138 $survey_questions = &$this->object->getSurveyQuestions();
139 $structure = &$_SESSION["constraintstructure"];
140 $start = $_GET["start"];
141 $option_questions = array();
142 for ($i = 1; $i < $start; $i++) {
143 if (is_array($structure[$i])) {
144 foreach ($structure[$i] as $key => $question_id) {
145 if ($survey_questions[$question_id]["usableForPrecondition"]) {
146 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"]));
147 }
148 }
149 }
150 }
151 if (count($option_questions) == 0) {
152 unset($_SESSION["includeElements"]);
153 unset($_SESSION["constraintstructure"]);
154 ilUtil::sendInfo($this->lng->txt("constraints_no_nonessay_available"), true);
155 $this->ctrl->redirect($this, "constraints");
156 }
157 $this->constraintForm(1, $_POST, $survey_questions, $option_questions);
158 }
159
163 public function constraintStep2Object()
164 {
165 $survey_questions = &$this->object->getSurveyQuestions();
166 $option_questions = array();
167 array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
168 $this->constraintForm(2, $_POST, $survey_questions, $option_questions);
169 }
170
174 public function constraintStep3Object()
175 {
176 $survey_questions = &$this->object->getSurveyQuestions();
177 $option_questions = array();
178 if (strlen($_GET["precondition"])) {
179 if (!$this->validateConstraintForEdit($_GET["precondition"])) {
180 $this->ctrl->redirect($this, "constraints");
181 }
182
183 $pc = $this->object->getPrecondition($_GET["precondition"]);
184 $postvalues = array(
185 "c" => $pc["conjunction"],
186 "q" => $pc["question_fi"],
187 "r" => $pc["relation_id"],
188 "v" => $pc["value"]
189 );
190 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"]));
191 $this->constraintForm(3, $postvalues, $survey_questions, $option_questions);
192 } else {
193 array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
194 $this->constraintForm(3, $_POST, $survey_questions, $option_questions);
195 }
196 }
197
198 public function constraintForm($step, $postvalues, &$survey_questions, $questions = false)
199 {
200 if (strlen($_GET["start"])) {
201 $this->ctrl->setParameter($this, "start", $_GET["start"]);
202 }
203 $this->ctrl->saveParameter($this, "precondition");
204 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
205 $form = new ilPropertyFormGUI();
206 $form->setFormAction($this->ctrl->getFormAction($this));
207 $form->setTableWidth("100%");
208 $form->setId("constraintsForm");
209
210 // #9366
211 $title = array();
212 $title_ids = $_SESSION["includeElements"];
213 if (!$title_ids) {
214 $title_ids = array($_GET["start"]);
215 }
216 foreach ($title_ids as $title_id) {
217 // question block
218 if ($survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["questionblock_id"] > 0) {
219 $title[] = $this->lng->txt("questionblock") . ": " . $survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["questionblock_title"];
220 }
221 // question
222 else {
223 $title[] = $this->lng->txt($survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["type_tag"]) . ": " .
224 $survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["title"];
225 }
226 }
228 $header->setTitle(implode("<br/>", $title));
229 $form->addItem($header);
230
231 $fulfilled = new ilRadioGroupInputGUI($this->lng->txt("constraint_fulfilled"), "c");
232 $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_and"), '0', ''));
233 $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_or"), '1', ''));
234 $fulfilled->setValue((strlen($postvalues['c'])) ? $postvalues['c'] : 0);
235 $form->addItem($fulfilled);
236
237 $step1 = new ilSelectInputGUI($this->lng->txt("step") . " 1: " . $this->lng->txt("select_prior_question"), "q");
238 $options = array();
239 if (is_array($questions)) {
240 foreach ($questions as $question) {
241 $options[$question["question_id"]] = $question["title"] . " (" . SurveyQuestion::_getQuestionTypeName($question["type_tag"]) . ")";
242 }
243 }
244 $step1->setOptions($options);
245 $step1->setValue($postvalues["q"]);
246 $form->addItem($step1);
247
248 if ($step > 1) {
249 $relations = $this->object->getAllRelations();
250 $step2 = new ilSelectInputGUI($this->lng->txt("step") . " 2: " . $this->lng->txt("select_relation"), "r");
251 $options = array();
252 foreach ($relations as $rel_id => $relation) {
253 if (in_array($relation["short"], $survey_questions[$postvalues["q"]]["availableRelations"])) {
254 $options[$rel_id] = $relation['short'];
255 }
256 }
257 $step2->setOptions($options);
258 $step2->setValue($postvalues["r"]);
259 $form->addItem($step2);
260 }
261
262 if ($step > 2) {
263 $variables = &$this->object->getVariables($postvalues["q"]);
264 $question_type = $survey_questions[$postvalues["q"]]["type_tag"];
265 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
266 SurveyQuestion::_includeClass($question_type);
267 $question = new $question_type();
268 $question->loadFromDb($postvalues["q"]);
269
270 $step3 = $question->getPreconditionSelectValue($postvalues["v"], $this->lng->txt("step") . " 3: " . $this->lng->txt("select_value"), "v");
271 $form->addItem($step3);
272 }
273
274 switch ($step) {
275 case 1:
276 $cmd_continue = "constraintStep2";
277 $cmd_back = "constraints";
278 break;
279 case 2:
280 $cmd_continue = "constraintStep3";
281 $cmd_back = "constraintStep1";
282 break;
283 case 3:
284 $cmd_continue = "constraintsAdd";
285 $cmd_back = "constraintStep2";
286 break;
287 }
288 $form->addCommandButton($cmd_back, $this->lng->txt("back"));
289 $form->addCommandButton($cmd_continue, $this->lng->txt("continue"));
290
291 $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
292 }
293
300 protected function validateConstraintForEdit($a_id)
301 {
302 $ilAccess = $this->access;
303
304 if (ilObjSurvey::_hasDatasets($this->object->getSurveyId())) {
305 return false;
306 }
307 if (!$ilAccess->checkAccess("write", "", $this->object->getRefId())) {
308 return false;
309 }
310
311 return true;
312 }
313
318 {
319 $id = (int) $_REQUEST["precondition"];
320 if (!$this->validateConstraintForEdit($id)) {
321 $this->ctrl->redirect($this, "constraints");
322 }
323
324 $constraint = $this->object->getPrecondition($id);
325 $questions = $this->object->getSurveyQuestions();
326 $question = $questions[$constraint["question_fi"]];
327 $relation = $questions[$constraint["ref_question_fi"]];
328 $relation = $relation["title"];
329
330 // see ilSurveyConstraintsTableGUI
331 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
332 $question_type = SurveyQuestion::_getQuestionType($constraint["question_fi"]);
333 SurveyQuestion::_includeClass($question_type);
334 $question_obj = new $question_type();
335 $question_obj->loadFromDb($constraint["question_fi"]);
336 $valueoutput = $question_obj->getPreconditionValueOutput($constraint["value"]);
337
338 $title = $question["title"] . " " . $constraint["shortname"] . " " . $valueoutput;
339
340 $this->ctrl->saveParameter($this, "precondition");
341
342 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
343 $cgui = new ilConfirmationGUI();
344 $cgui->setHeaderText(sprintf($this->lng->txt("survey_sure_delete_constraint"), $title, $relation));
345
346 $cgui->setFormAction($this->ctrl->getFormAction($this, "deleteConstraints"));
347 $cgui->setCancel($this->lng->txt("cancel"), "constraints");
348 $cgui->setConfirm($this->lng->txt("confirm"), "deleteConstraints");
349
350 $this->tpl->setContent($cgui->getHTML());
351 }
352
356 public function deleteConstraintsObject()
357 {
358 $id = (int) $_REQUEST["precondition"];
359 if ($this->validateConstraintForEdit($id)) {
360 ilUtil::sendSuccess($this->lng->txt("survey_constraint_deleted"), true);
361 $this->object->deleteConstraint($id);
362 }
363
364 $this->ctrl->redirect($this, "constraints");
365 }
366
367 public function createConstraintsObject()
368 {
369 $include_elements = $_POST["includeElements"];
370 if ((!is_array($include_elements)) || (count($include_elements) == 0)) {
371 ilUtil::sendInfo($this->lng->txt("constraints_no_questions_or_questionblocks_selected"), true);
372 $this->ctrl->redirect($this, "constraints");
373 } elseif (count($include_elements) >= 1) {
374 $_SESSION["includeElements"] = $include_elements;
375 sort($include_elements, SORT_NUMERIC);
376 $_GET["start"] = $include_elements[0];
377 $this->constraintStep1Object();
378 }
379 }
380
381 public function editPreconditionObject()
382 {
383 if (!$this->validateConstraintForEdit($_GET["precondition"])) {
384 $this->ctrl->redirect($this, "constraints");
385 }
386
387 $_SESSION["includeElements"] = array($_GET["start"]);
388 $this->ctrl->setParameter($this, "precondition", $_GET["precondition"]);
389 $this->ctrl->setParameter($this, "start", $_GET["start"]);
390 $this->ctrl->redirect($this, "constraintStep3");
391 }
392}
$_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.
$key
Definition: croninfo.php:18
foreach($_REQUEST as $var) foreach(array('_POST'=> 'HTTP_POST_VARS', '_GET'=> 'HTTP_GET_VARS', '_COOKIE'=> 'HTTP_COOKIE_VARS', '_SERVER'=> 'HTTP_SERVER_VARS', '_ENV'=> 'HTTP_ENV_VARS', '_FILES'=> 'HTTP_POST_FILES') as $array=> $other) $step
Definition: cssgen.php:155
$i
Definition: disco.tpl.php:19
$tbl
Definition: example_048.php:81
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilCtrl
Definition: ilias.php:18
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$start
Definition: bench.php:8