20 $this->parent_gui = $a_parent_gui;
21 $this->
object = $this->parent_gui->object;
32 $cmd = $ilCtrl->getCmd(
"constraints");
45 $hasDatasets = $this->
object->_hasDatasets($this->object->getSurveyId());
47 if (array_key_exists(
"step",
$_GET)) $step =
$_GET[
"step"];
62 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.il_svy_svy_constraints_list.html",
"Modules/Survey");
63 $survey_questions =& $this->
object->getSurveyQuestions();
64 $last_questionblock_id = 0;
66 $hasPreconditions = FALSE;
68 $colors = array(
"tblrow1",
"tblrow2");
69 foreach ($survey_questions as $question_id => $data)
71 $title = $data[
"title"];
73 if ($data[
"questionblock_id"] > 0)
75 $title = $data[
"questionblock_title"];
76 $type = $this->lng->txt(
"questionblock");
77 if ($data[
"questionblock_id"] != $last_questionblock_id)
79 $last_questionblock_id = $data[
"questionblock_id"];
80 $structure[$counter] = array();
81 array_push($structure[$counter], $data[
"question_id"]);
85 array_push($structure[$counter-1], $data[
"question_id"]);
91 $structure[$counter] = array($data[
"question_id"]);
92 $type = $this->lng->txt(
"question");
98 $this->tpl->setCurrentBlock(
"description");
99 $this->tpl->setVariable(
"DESCRIPTION", $this->lng->txt(
"constraints_first_question_description"));
100 $this->tpl->parseCurrentBlock();
104 $constraints =& $this->
object->getConstraints($data[
"question_id"]);
106 if (count($constraints))
108 $hasPreconditions = TRUE;
109 foreach ($constraints as $constraint)
111 $this->tpl->setCurrentBlock(
"constraint");
112 $this->tpl->setVariable(
"SEQUENCE_ID", $counter);
113 $this->tpl->setVariable(
"CONSTRAINT_ID", $constraint[
"id"]);
114 $this->tpl->setVariable(
"CONSTRAINT_TEXT", $survey_questions[$constraint[
"question"]][
"title"] .
" " . $constraint[
"short"] .
" " . $constraint[
"valueoutput"]);
115 $this->tpl->setVariable(
"TEXT_EDIT_PRECONDITION", $this->lng->txt(
"edit"));
116 $this->ctrl->setParameter($this,
"precondition", $constraint[
"id"]);
117 $this->ctrl->setParameter($this,
"start", $counter);
118 $this->tpl->setVariable(
"EDIT_PRECONDITION", $this->ctrl->getLinkTarget($this,
"editPrecondition"));
119 $this->ctrl->setParameter($this,
"precondition",
"");
120 $this->ctrl->setParameter($this,
"start",
"");
121 $this->tpl->parseCurrentBlock();
123 if (count($constraints) > 1)
125 $this->tpl->setCurrentBlock(
"conjunction");
126 $this->tpl->setVariable(
"TEXT_CONJUNCTION", ($constraints[0][
'conjunction']) ? $this->lng->txt(
'conjunction_or_title') : $this->lng->txt(
'conjunction_and_title'));
127 $this->tpl->parseCurrentBlock();
133 $this->tpl->setCurrentBlock(
"include_elements");
134 $this->tpl->setVariable(
"QUESTION_NR",
"$counter");
135 $this->tpl->parseCurrentBlock();
137 $this->tpl->setCurrentBlock(
"constraint_section");
138 $this->tpl->setVariable(
"COLOR_CLASS", $colors[$counter % 2]);
139 $this->tpl->setVariable(
"QUESTION_NR",
"$counter");
140 $this->tpl->setVariable(
"TITLE",
"$title");
141 $icontype =
"question.png";
142 if ($data[
"questionblock_id"] > 0)
144 $icontype =
"questionblock.png";
146 $this->tpl->setVariable(
"TYPE",
"$type: ");
147 include_once
"./Services/Utilities/classes/class.ilUtil.php";
149 $this->tpl->setVariable(
"ICON_ALT", $type);
150 $this->tpl->parseCurrentBlock();
156 if ($hasPreconditions)
158 $this->tpl->setCurrentBlock(
"selectall_preconditions");
159 $this->tpl->setVariable(
"SELECT_ALL_PRECONDITIONS", $this->lng->txt(
"select_all"));
160 $this->tpl->parseCurrentBlock();
162 $this->tpl->setCurrentBlock(
"selectall");
164 $this->tpl->setVariable(
"SELECT_ALL", $this->lng->txt(
"select_all"));
165 $this->tpl->setVariable(
"COLOR_CLASS", $colors[$counter % 2]);
166 $this->tpl->parseCurrentBlock();
168 if ($hasPreconditions)
170 $this->tpl->setCurrentBlock(
"delete_button");
171 $this->tpl->setVariable(
"BTN_DELETE", $this->lng->txt(
"delete"));
172 include_once
"./Services/Utilities/classes/class.ilUtil.php";
173 $this->tpl->setVariable(
"ARROW",
"<img src=\"" .
ilUtil::getImagePath(
"arrow_downright.png") .
"\" alt=\"".$this->lng->txt(
"arrow_downright").
"\">");
174 $this->tpl->parseCurrentBlock();
177 $this->tpl->setCurrentBlock(
"buttons");
178 $this->tpl->setVariable(
"ARROW",
"<img src=\"" .
ilUtil::getImagePath(
"arrow_downright.png") .
"\" alt=\"".$this->lng->txt(
"arrow_downright").
"\">");
179 $this->tpl->setVariable(
"BTN_CREATE_CONSTRAINTS", $this->lng->txt(
"constraint_add"));
180 $this->tpl->parseCurrentBlock();
182 $this->tpl->setCurrentBlock(
"adm_content");
183 $this->tpl->setVariable(
"CONSTRAINTS_INTRODUCTION", $this->lng->txt(
"constraints_introduction"));
184 $this->tpl->setVariable(
"DEFINED_PRECONDITIONS", $this->lng->txt(
"existing_constraints"));
185 $this->tpl->setVariable(
"FORM_ACTION", $this->ctrl->getFormAction($this,
"constraints"));
186 $this->tpl->setVariable(
"CONSTRAINTS_HEADER", $this->lng->txt(
"constraints_list_of_entities"));
187 $this->tpl->parseCurrentBlock();
188 $_SESSION[
"constraintstructure"] = $structure;
192 $link = $this->ctrl->getLinkTargetByClass(
"ilSurveyParticipantsGUI",
"maintenance");
193 $link =
"<a href=\"".$link.
"\">".$this->lng->txt(
"survey_has_datasets_warning_page_view_link").
"</a>";
194 ilUtil::sendInfo($this->lng->txt(
"survey_has_datasets_warning_page_view").
" ".$link);
203 if (strlen(
$_POST[
"v"]) == 0)
208 $survey_questions =& $this->
object->getSurveyQuestions();
209 $structure =&
$_SESSION[
"constraintstructure"];
210 $include_elements =
$_SESSION[
"includeElements"];
211 foreach ($include_elements as $elementCounter)
213 if (is_array($structure[$elementCounter]))
215 if (strlen(
$_GET[
"precondition"]))
222 foreach ($structure[$elementCounter] as $key => $question_id)
224 $this->
object->addConstraintToQuestion($question_id, $constraint_id);
227 if (count($structure[$elementCounter]) > 1)
229 $this->
object->updateConjunctionForQuestions($structure[$elementCounter],
$_POST[
'c']);
235 $this->ctrl->redirect($this,
"constraints");
243 $survey_questions =& $this->
object->getSurveyQuestions();
244 $structure =&
$_SESSION[
"constraintstructure"];
245 $start =
$_GET[
"start"];
246 $option_questions = array();
247 for ($i = 1; $i < $start; $i++)
249 if (is_array($structure[$i]))
251 foreach ($structure[$i] as $key => $question_id)
253 if ($survey_questions[$question_id][
"usableForPrecondition"])
255 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"]));
260 if (count($option_questions) == 0)
264 ilUtil::sendInfo($this->lng->txt(
"constraints_no_nonessay_available"),
true);
265 $this->ctrl->redirect($this,
"constraints");
275 $survey_questions =& $this->
object->getSurveyQuestions();
276 $option_questions = array();
277 array_push($option_questions, array(
"question_id" =>
$_POST[
"q"],
"title" => $survey_questions[
$_POST[
"q"]][
"title"],
"type_tag" => $survey_questions[$_POST[
"q"]][
"type_tag"]));
278 $this->
constraintForm(2, $_POST, $survey_questions, $option_questions);
286 $survey_questions =& $this->
object->getSurveyQuestions();
287 $option_questions = array();
288 if (strlen(
$_GET[
"precondition"]))
290 $pc = $this->
object->getPrecondition(
$_GET[
"precondition"]);
292 "c" => $pc[
"conjunction"],
293 "q" => $pc[
"question_fi"],
294 "r" => $pc[
"relation_id"],
297 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"]));
298 $this->
constraintForm(3, $postvalues, $survey_questions, $option_questions);
302 array_push($option_questions, array(
"question_id" =>
$_POST[
"q"],
"title" => $survey_questions[
$_POST[
"q"]][
"title"],
"type_tag" => $survey_questions[$_POST[
"q"]][
"type_tag"]));
303 $this->
constraintForm(3, $_POST, $survey_questions, $option_questions);
307 public function constraintForm($step, $postvalues, &$survey_questions, $questions = FALSE)
309 if (strlen(
$_GET[
"start"])) $this->ctrl->setParameter($this,
"start",
$_GET[
"start"]);
310 $this->ctrl->saveParameter($this,
"precondition");
311 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
313 $form->setFormAction($this->ctrl->getFormAction($this));
314 $form->setTableWidth(
"100%");
315 $form->setId(
"constraintsForm");
319 $title_ids =
$_SESSION[
"includeElements"];
322 $title_ids = array(
$_GET[
"start"]);
324 foreach($title_ids as $title_id)
327 if ($survey_questions[
$_SESSION[
"constraintstructure"][$title_id][0]][
"questionblock_id"] > 0)
329 $title[] = $this->lng->txt(
"questionblock") .
": " . $survey_questions[
$_SESSION[
"constraintstructure"][$title_id][0]][
"questionblock_title"];
334 $title[] = $this->lng->txt($survey_questions[
$_SESSION[
"constraintstructure"][$title_id][0]][
"type_tag"]) .
": " .
335 $survey_questions[
$_SESSION[
"constraintstructure"][$title_id][0]][
"title"];
339 $header->setTitle(implode(
"<br/>", $title));
340 $form->addItem($header);
344 $fulfilled->addOption(
new ilRadioOption($this->lng->txt(
"conjunction_or"),
'1',
''));
345 $fulfilled->setValue((strlen($postvalues[
'c'])) ? $postvalues[
'c'] : 0);
346 $form->addItem($fulfilled);
348 $step1 =
new ilSelectInputGUI($this->lng->txt(
"step") .
" 1: " . $this->lng->txt(
"select_prior_question"),
"q");
350 if (is_array($questions))
352 foreach ($questions as $question)
357 $step1->setOptions($options);
358 $step1->setValue($postvalues[
"q"]);
359 $form->addItem($step1);
363 $relations = $this->
object->getAllRelations();
364 $step2 =
new ilSelectInputGUI($this->lng->txt(
"step") .
" 2: " . $this->lng->txt(
"select_relation"),
"r");
366 foreach ($relations as $rel_id => $relation)
368 if (in_array($relation[
"short"], $survey_questions[$postvalues[
"q"]][
"availableRelations"]))
370 $options[$rel_id] = $relation[
'short'];
374 $step2->setValue($postvalues[
"r"]);
375 $form->addItem($step2);
380 $variables =& $this->
object->getVariables($postvalues[
"q"]);
381 $question_type = $survey_questions[$postvalues[
"q"]][
"type_tag"];
382 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
384 $question =
new $question_type();
385 $question->loadFromDb($postvalues[
"q"]);
387 $step3 = $question->getPreconditionSelectValue($postvalues[
"v"], $this->lng->txt(
"step") .
" 3: " . $this->lng->txt(
"select_value"),
"v");
388 $form->addItem($step3);
394 $cmd_continue =
"constraintStep2";
395 $cmd_back =
"constraints";
398 $cmd_continue =
"constraintStep3";
399 $cmd_back =
"constraintStep1";
402 $cmd_continue =
"constraintsAdd";
403 $cmd_back =
"constraintStep2";
406 $form->addCommandButton($cmd_back, $this->lng->txt(
"back"));
407 $form->addCommandButton($cmd_continue, $this->lng->txt(
"continue"));
409 $this->tpl->setVariable(
"ADM_CONTENT", $form->getHTML());
417 $survey_questions =& $this->
object->getSurveyQuestions();
418 $structure =&
$_SESSION[
"constraintstructure"];
419 foreach (
$_POST as $key => $value)
421 if (preg_match(
"/^constraint_(\d+)_(\d+)/", $key, $matches))
423 $this->
object->deleteConstraint($matches[2]);
427 $this->ctrl->redirect($this,
"constraints");
432 $include_elements =
$_POST[
"includeElements"];
433 if ((!is_array($include_elements)) || (count($include_elements) == 0))
435 ilUtil::sendInfo($this->lng->txt(
"constraints_no_questions_or_questionblocks_selected"),
true);
436 $this->ctrl->redirect($this,
"constraints");
438 else if (count($include_elements) >= 1)
440 $_SESSION[
"includeElements"] = $include_elements;
441 sort($include_elements, SORT_NUMERIC);
442 $_GET[
"start"] = $include_elements[0];
450 $this->ctrl->setParameter($this,
"precondition",
$_GET[
"precondition"]);
451 $this->ctrl->setParameter($this,
"start",
$_GET[
"start"]);
452 $this->ctrl->redirect($this,
"constraintStep3");