ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
16 public function __construct(ilObjSurveyGUI $a_parent_gui)
17 {
18 global $ilCtrl, $lng, $tpl;
19
20 $this->parent_gui = $a_parent_gui;
21 $this->object = $this->parent_gui->object;
22
23 $this->ctrl = $ilCtrl;
24 $this->lng = $lng;
25 $this->tpl = $tpl;
26 }
27
28 public function executeCommand()
29 {
30 global $ilCtrl;
31
32 $cmd = $ilCtrl->getCmd("constraints");
33 $cmd .= "Object";
34
35 $this->$cmd();
36 }
37
41 public function constraintsObject()
42 {
43 $step = 0;
44 if (array_key_exists("step", $_GET))
45 {
46 $step = (int)$_GET["step"];
47 }
48 switch ($step)
49 {
50 case 1:
51 $this->constraintStep1Object();
52 return;
53 break;
54 case 2:
55 return;
56 break;
57 case 3:
58 return;
59 break;
60 }
61
62 $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
63
64 include_once "Modules/Survey/classes/tables/class.SurveyConstraintsTableGUI.php";
65 $tbl = new SurveyConstraintsTableGUI($this, "constraints", $this->object, $hasDatasets);
66 $this->tpl->setContent($tbl->getHTML());
67
68 if ($hasDatasets)
69 {
70 // ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning"));
71 $link = $this->ctrl->getLinkTargetByClass("ilSurveyParticipantsGUI", "maintenance");
72 $link = "<a href=\"".$link."\">".$this->lng->txt("survey_has_datasets_warning_page_view_link")."</a>";
73 ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning_page_view")." ".$link);
74 }
75 else
76 {
77 $_SESSION["constraintstructure"] = $tbl->getStructure();
78 }
79 }
80
84 public function constraintsAddObject()
85 {
86 if (strlen($_POST["v"]) == 0)
87 {
88 ilUtil::sendFailure($this->lng->txt("msg_enter_value_for_valid_constraint"));
89 return $this->constraintStep3Object();
90 }
91 $survey_questions =& $this->object->getSurveyQuestions();
92 $structure =& $_SESSION["constraintstructure"];
93 $include_elements = $_SESSION["includeElements"];
94 foreach ($include_elements as $elementCounter)
95 {
96 if (is_array($structure[$elementCounter]))
97 {
98 if (strlen($_GET["precondition"]))
99 {
100 $this->object->updateConstraint($_GET['precondition'], $_POST["q"], $_POST["r"], $_POST["v"], $_POST['c']);
101 }
102 else
103 {
104 $constraint_id = $this->object->addConstraint($_POST["q"], $_POST["r"], $_POST["v"], $_POST['c']);
105 foreach ($structure[$elementCounter] as $key => $question_id)
106 {
107 $this->object->addConstraintToQuestion($question_id, $constraint_id);
108 }
109 }
110 if (count($structure[$elementCounter]) > 1)
111 {
112 $this->object->updateConjunctionForQuestions($structure[$elementCounter], $_POST['c']);
113 }
114 }
115 }
116 unset($_SESSION["includeElements"]);
117 unset($_SESSION["constraintstructure"]);
118 $this->ctrl->redirect($this, "constraints");
119 }
120
124 public function constraintStep1Object()
125 {
126 $survey_questions =& $this->object->getSurveyQuestions();
127 $structure =& $_SESSION["constraintstructure"];
128 $start = $_GET["start"];
129 $option_questions = array();
130 for ($i = 1; $i < $start; $i++)
131 {
132 if (is_array($structure[$i]))
133 {
134 foreach ($structure[$i] as $key => $question_id)
135 {
136 if ($survey_questions[$question_id]["usableForPrecondition"])
137 {
138 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"]));
139 }
140 }
141 }
142 }
143 if (count($option_questions) == 0)
144 {
145 unset($_SESSION["includeElements"]);
146 unset($_SESSION["constraintstructure"]);
147 ilUtil::sendInfo($this->lng->txt("constraints_no_nonessay_available"), true);
148 $this->ctrl->redirect($this, "constraints");
149 }
150 $this->constraintForm(1, $_POST, $survey_questions, $option_questions);
151 }
152
156 public function constraintStep2Object()
157 {
158 $survey_questions =& $this->object->getSurveyQuestions();
159 $option_questions = array();
160 array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
161 $this->constraintForm(2, $_POST, $survey_questions, $option_questions);
162 }
163
167 public function constraintStep3Object()
168 {
169 $survey_questions =& $this->object->getSurveyQuestions();
170 $option_questions = array();
171 if (strlen($_GET["precondition"]))
172 {
173 if(!$this->validateConstraintForEdit($_GET["precondition"]))
174 {
175 $this->ctrl->redirect($this, "constraints");
176 }
177
178 $pc = $this->object->getPrecondition($_GET["precondition"]);
179 $postvalues = array(
180 "c" => $pc["conjunction"],
181 "q" => $pc["question_fi"],
182 "r" => $pc["relation_id"],
183 "v" => $pc["value"]
184 );
185 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"]));
186 $this->constraintForm(3, $postvalues, $survey_questions, $option_questions);
187 }
188 else
189 {
190 array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
191 $this->constraintForm(3, $_POST, $survey_questions, $option_questions);
192 }
193 }
194
195 public function constraintForm($step, $postvalues, &$survey_questions, $questions = FALSE)
196 {
197 if (strlen($_GET["start"])) $this->ctrl->setParameter($this, "start", $_GET["start"]);
198 $this->ctrl->saveParameter($this, "precondition");
199 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
200 $form = new ilPropertyFormGUI();
201 $form->setFormAction($this->ctrl->getFormAction($this));
202 $form->setTableWidth("100%");
203 $form->setId("constraintsForm");
204
205 // #9366
206 $title = array();
207 $title_ids = $_SESSION["includeElements"];
208 if(!$title_ids)
209 {
210 $title_ids = array($_GET["start"]);
211 }
212 foreach($title_ids as $title_id)
213 {
214 // question block
215 if ($survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["questionblock_id"] > 0)
216 {
217 $title[] = $this->lng->txt("questionblock") . ": " . $survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["questionblock_title"];
218 }
219 // question
220 else
221 {
222 $title[] = $this->lng->txt($survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["type_tag"]) . ": " .
223 $survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["title"];
224 }
225 }
227 $header->setTitle(implode("<br/>", $title));
228 $form->addItem($header);
229
230 $fulfilled = new ilRadioGroupInputGUI($this->lng->txt("constraint_fulfilled"), "c");
231 $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_and"), '0', ''));
232 $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_or"), '1', ''));
233 $fulfilled->setValue((strlen($postvalues['c'])) ? $postvalues['c'] : 0);
234 $form->addItem($fulfilled);
235
236 $step1 = new ilSelectInputGUI($this->lng->txt("step") . " 1: " . $this->lng->txt("select_prior_question"), "q");
237 $options = array();
238 if (is_array($questions))
239 {
240 foreach ($questions as $question)
241 {
242 $options[$question["question_id"]] = $question["title"] . " (" . SurveyQuestion::_getQuestionTypeName($question["type_tag"]) . ")";
243 }
244 }
245 $step1->setOptions($options);
246 $step1->setValue($postvalues["q"]);
247 $form->addItem($step1);
248
249 if ($step > 1)
250 {
251 $relations = $this->object->getAllRelations();
252 $step2 = new ilSelectInputGUI($this->lng->txt("step") . " 2: " . $this->lng->txt("select_relation"), "r");
253 $options = array();
254 foreach ($relations as $rel_id => $relation)
255 {
256 if (in_array($relation["short"], $survey_questions[$postvalues["q"]]["availableRelations"]))
257 {
258 $options[$rel_id] = $relation['short'];
259 }
260 }
261 $step2->setOptions($options);
262 $step2->setValue($postvalues["r"]);
263 $form->addItem($step2);
264 }
265
266 if ($step > 2)
267 {
268 $variables =& $this->object->getVariables($postvalues["q"]);
269 $question_type = $survey_questions[$postvalues["q"]]["type_tag"];
270 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
271 SurveyQuestion::_includeClass($question_type);
272 $question = new $question_type();
273 $question->loadFromDb($postvalues["q"]);
274
275 $step3 = $question->getPreconditionSelectValue($postvalues["v"], $this->lng->txt("step") . " 3: " . $this->lng->txt("select_value"), "v");
276 $form->addItem($step3);
277 }
278
279 switch ($step)
280 {
281 case 1:
282 $cmd_continue = "constraintStep2";
283 $cmd_back = "constraints";
284 break;
285 case 2:
286 $cmd_continue = "constraintStep3";
287 $cmd_back = "constraintStep1";
288 break;
289 case 3:
290 $cmd_continue = "constraintsAdd";
291 $cmd_back = "constraintStep2";
292 break;
293 }
294 $form->addCommandButton($cmd_back, $this->lng->txt("back"));
295 $form->addCommandButton($cmd_continue, $this->lng->txt("continue"));
296
297 $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
298 }
299
306 protected function validateConstraintForEdit($a_id)
307 {
308 global $ilAccess;
309
310 if($this->object->_hasDatasets($this->object->getSurveyId()))
311 {
312 return false;
313 }
314 if(!$ilAccess->checkAccess("write", "", $this->object->getRefId()))
315 {
316 return false;
317 }
318
319 return true;
320 }
321
326 {
327 $id = (int)$_REQUEST["precondition"];
328 if(!$this->validateConstraintForEdit($id))
329 {
330 $this->ctrl->redirect($this, "constraints");
331 }
332
333 $constraint = $this->object->getPrecondition($id);
334 $questions = $this->object->getSurveyQuestions();
335 $question = $questions[$constraint["question_fi"]];
336 $relation = $questions[$constraint["ref_question_fi"]];
337 $relation = $relation["title"];
338
339 // see ilSurveyConstraintsTableGUI
340 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
341 $question_type = SurveyQuestion::_getQuestionType($constraint["question_fi"]);
342 SurveyQuestion::_includeClass($question_type);
343 $question_obj = new $question_type();
344 $question_obj->loadFromDb($constraint["question_fi"]);
345 $valueoutput = $question_obj->getPreconditionValueOutput($constraint["value"]);
346
347 $title = $question["title"]." ".$constraint["shortname"]." ".$valueoutput;
348
349 $this->ctrl->saveParameter($this, "precondition");
350
351 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
352 $cgui = new ilConfirmationGUI();
353 $cgui->setHeaderText(sprintf($this->lng->txt("survey_sure_delete_constraint"), $title, $relation));
354
355 $cgui->setFormAction($this->ctrl->getFormAction($this, "deleteConstraints"));
356 $cgui->setCancel($this->lng->txt("cancel"), "constraints");
357 $cgui->setConfirm($this->lng->txt("confirm"), "deleteConstraints");
358
359 $this->tpl->setContent($cgui->getHTML());
360 }
361
365 public function deleteConstraintsObject()
366 {
367 $id = (int)$_REQUEST["precondition"];
368 if($this->validateConstraintForEdit($id))
369 {
370 ilUtil::sendSuccess($this->lng->txt("survey_constraint_deleted"), true);
371 $this->object->deleteConstraint($id);
372 }
373
374 $this->ctrl->redirect($this, "constraints");
375 }
376
378 {
379 $include_elements = $_POST["includeElements"];
380 if ((!is_array($include_elements)) || (count($include_elements) == 0))
381 {
382 ilUtil::sendInfo($this->lng->txt("constraints_no_questions_or_questionblocks_selected"), true);
383 $this->ctrl->redirect($this, "constraints");
384 }
385 else if (count($include_elements) >= 1)
386 {
387 $_SESSION["includeElements"] = $include_elements;
388 sort($include_elements, SORT_NUMERIC);
389 $_GET["start"] = $include_elements[0];
390 $this->constraintStep1Object();
391 }
392 }
393
395 {
396 if(!$this->validateConstraintForEdit($_GET["precondition"]))
397 {
398 $this->ctrl->redirect($this, "constraints");
399 }
400
401 $_SESSION["includeElements"] = array($_GET["start"]);
402 $this->ctrl->setParameter($this, "precondition", $_GET["precondition"]);
403 $this->ctrl->setParameter($this, "start", $_GET["start"]);
404 $this->ctrl->redirect($this, "constraintStep3");
405 }
406}
407
408?>
global $tpl
Definition: ilias.php:8
$_GET["client_id"]
$_SESSION["AccountId"]
TableGUI class for survey constraints.
_getQuestionType($question_id)
Returns the question type of a question with a given id.
static _getQuestionTypeName($type_tag)
Return the translation for a given question type tag.
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.
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.
constraintForm($step, $postvalues, &$survey_questions, $questions=FALSE)
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...
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$_POST['username']
Definition: cron.php:12
$header
$tbl
Definition: example_048.php:81
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
if(!is_array($argv)) $options