ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  global $rbacsystem;
44 
45  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
46  $step = 0;
47  if (array_key_exists("step", $_GET)) $step = $_GET["step"];
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  $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;
65  $counter = 1;
66  $hasPreconditions = FALSE;
67  $structure = array();
68  $colors = array("tblrow1", "tblrow2");
69  foreach ($survey_questions as $question_id => $data)
70  {
71  $title = $data["title"];
72  $show = true;
73  if ($data["questionblock_id"] > 0)
74  {
75  $title = $data["questionblock_title"];
76  $type = $this->lng->txt("questionblock");
77  if ($data["questionblock_id"] != $last_questionblock_id)
78  {
79  $last_questionblock_id = $data["questionblock_id"];
80  $structure[$counter] = array();
81  array_push($structure[$counter], $data["question_id"]);
82  }
83  else
84  {
85  array_push($structure[$counter-1], $data["question_id"]);
86  $show = false;
87  }
88  }
89  else
90  {
91  $structure[$counter] = array($data["question_id"]);
92  $type = $this->lng->txt("question");
93  }
94  if ($show)
95  {
96  if ($counter == 1)
97  {
98  $this->tpl->setCurrentBlock("description");
99  $this->tpl->setVariable("DESCRIPTION", $this->lng->txt("constraints_first_question_description"));
100  $this->tpl->parseCurrentBlock();
101  }
102  else
103  {
104  $constraints =& $this->object->getConstraints($data["question_id"]);
105  $rowcount = 0;
106  if (count($constraints))
107  {
108  $hasPreconditions = TRUE;
109  foreach ($constraints as $constraint)
110  {
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();
122  }
123  if (count($constraints) > 1)
124  {
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();
128  }
129  }
130  }
131  if ($counter != 1)
132  {
133  $this->tpl->setCurrentBlock("include_elements");
134  $this->tpl->setVariable("QUESTION_NR", "$counter");
135  $this->tpl->parseCurrentBlock();
136  }
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)
143  {
144  $icontype = "questionblock.png";
145  }
146  $this->tpl->setVariable("TYPE", "$type: ");
147  include_once "./Services/Utilities/classes/class.ilUtil.php";
148  $this->tpl->setVariable("ICON_HREF", ilUtil::getImagePath($icontype, "Modules/Survey"));
149  $this->tpl->setVariable("ICON_ALT", $type);
150  $this->tpl->parseCurrentBlock();
151  $counter++;
152  }
153  }
154  if (!$hasDatasets)
155  {
156  if ($hasPreconditions)
157  {
158  $this->tpl->setCurrentBlock("selectall_preconditions");
159  $this->tpl->setVariable("SELECT_ALL_PRECONDITIONS", $this->lng->txt("select_all"));
160  $this->tpl->parseCurrentBlock();
161  }
162  $this->tpl->setCurrentBlock("selectall");
163  $counter++;
164  $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
165  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
166  $this->tpl->parseCurrentBlock();
167 
168  if ($hasPreconditions)
169  {
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();
175  }
176 
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();
181  }
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;
189  if ($hasDatasets)
190  {
191  // ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning"));
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);
195  }
196  }
197 
201  public function constraintsAddObject()
202  {
203  if (strlen($_POST["v"]) == 0)
204  {
205  ilUtil::sendFailure($this->lng->txt("msg_enter_value_for_valid_constraint"));
206  return $this->constraintStep3Object();
207  }
208  $survey_questions =& $this->object->getSurveyQuestions();
209  $structure =& $_SESSION["constraintstructure"];
210  $include_elements = $_SESSION["includeElements"];
211  foreach ($include_elements as $elementCounter)
212  {
213  if (is_array($structure[$elementCounter]))
214  {
215  if (strlen($_GET["precondition"]))
216  {
217  $this->object->updateConstraint($_GET['precondition'], $_POST["q"], $_POST["r"], $_POST["v"], $_POST['c']);
218  }
219  else
220  {
221  $constraint_id = $this->object->addConstraint($_POST["q"], $_POST["r"], $_POST["v"], $_POST['c']);
222  foreach ($structure[$elementCounter] as $key => $question_id)
223  {
224  $this->object->addConstraintToQuestion($question_id, $constraint_id);
225  }
226  }
227  if (count($structure[$elementCounter]) > 1)
228  {
229  $this->object->updateConjunctionForQuestions($structure[$elementCounter], $_POST['c']);
230  }
231  }
232  }
233  unset($_SESSION["includeElements"]);
234  unset($_SESSION["constraintstructure"]);
235  $this->ctrl->redirect($this, "constraints");
236  }
237 
241  public function constraintStep1Object()
242  {
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++)
248  {
249  if (is_array($structure[$i]))
250  {
251  foreach ($structure[$i] as $key => $question_id)
252  {
253  if ($survey_questions[$question_id]["usableForPrecondition"])
254  {
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"]));
256  }
257  }
258  }
259  }
260  if (count($option_questions) == 0)
261  {
262  unset($_SESSION["includeElements"]);
263  unset($_SESSION["constraintstructure"]);
264  ilUtil::sendInfo($this->lng->txt("constraints_no_nonessay_available"), true);
265  $this->ctrl->redirect($this, "constraints");
266  }
267  $this->constraintForm(1, $_POST, $survey_questions, $option_questions);
268  }
269 
273  public function constraintStep2Object()
274  {
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);
279  }
280 
284  public function constraintStep3Object()
285  {
286  $survey_questions =& $this->object->getSurveyQuestions();
287  $option_questions = array();
288  if (strlen($_GET["precondition"]))
289  {
290  $pc = $this->object->getPrecondition($_GET["precondition"]);
291  $postvalues = array(
292  "c" => $pc["conjunction"],
293  "q" => $pc["question_fi"],
294  "r" => $pc["relation_id"],
295  "v" => $pc["value"]
296  );
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);
299  }
300  else
301  {
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);
304  }
305  }
306 
307  public function constraintForm($step, $postvalues, &$survey_questions, $questions = FALSE)
308  {
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");
312  $form = new ilPropertyFormGUI();
313  $form->setFormAction($this->ctrl->getFormAction($this));
314  $form->setTableWidth("100%");
315  $form->setId("constraintsForm");
316 
317  // #9366
318  $title = array();
319  $title_ids = $_SESSION["includeElements"];
320  if(!$title_ids)
321  {
322  $title_ids = array($_GET["start"]);
323  }
324  foreach($title_ids as $title_id)
325  {
326  // question block
327  if ($survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["questionblock_id"] > 0)
328  {
329  $title[] = $this->lng->txt("questionblock") . ": " . $survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["questionblock_title"];
330  }
331  // question
332  else
333  {
334  $title[] = $this->lng->txt($survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["type_tag"]) . ": " .
335  $survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["title"];
336  }
337  }
338  $header = new ilFormSectionHeaderGUI();
339  $header->setTitle(implode("<br/>", $title));
340  $form->addItem($header);
341 
342  $fulfilled = new ilRadioGroupInputGUI($this->lng->txt("constraint_fulfilled"), "c");
343  $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_and"), '0', ''));
344  $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_or"), '1', ''));
345  $fulfilled->setValue((strlen($postvalues['c'])) ? $postvalues['c'] : 0);
346  $form->addItem($fulfilled);
347 
348  $step1 = new ilSelectInputGUI($this->lng->txt("step") . " 1: " . $this->lng->txt("select_prior_question"), "q");
349  $options = array();
350  if (is_array($questions))
351  {
352  foreach ($questions as $question)
353  {
354  $options[$question["question_id"]] = $question["title"] . " (" . SurveyQuestion::_getQuestionTypeName($question["type_tag"]) . ")";
355  }
356  }
357  $step1->setOptions($options);
358  $step1->setValue($postvalues["q"]);
359  $form->addItem($step1);
360 
361  if ($step > 1)
362  {
363  $relations = $this->object->getAllRelations();
364  $step2 = new ilSelectInputGUI($this->lng->txt("step") . " 2: " . $this->lng->txt("select_relation"), "r");
365  $options = array();
366  foreach ($relations as $rel_id => $relation)
367  {
368  if (in_array($relation["short"], $survey_questions[$postvalues["q"]]["availableRelations"]))
369  {
370  $options[$rel_id] = $relation['short'];
371  }
372  }
373  $step2->setOptions($options);
374  $step2->setValue($postvalues["r"]);
375  $form->addItem($step2);
376  }
377 
378  if ($step > 2)
379  {
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";
383  SurveyQuestion::_includeClass($question_type);
384  $question = new $question_type();
385  $question->loadFromDb($postvalues["q"]);
386 
387  $step3 = $question->getPreconditionSelectValue($postvalues["v"], $this->lng->txt("step") . " 3: " . $this->lng->txt("select_value"), "v");
388  $form->addItem($step3);
389  }
390 
391  switch ($step)
392  {
393  case 1:
394  $cmd_continue = "constraintStep2";
395  $cmd_back = "constraints";
396  break;
397  case 2:
398  $cmd_continue = "constraintStep3";
399  $cmd_back = "constraintStep1";
400  break;
401  case 3:
402  $cmd_continue = "constraintsAdd";
403  $cmd_back = "constraintStep2";
404  break;
405  }
406  $form->addCommandButton($cmd_back, $this->lng->txt("back"));
407  $form->addCommandButton($cmd_continue, $this->lng->txt("continue"));
408 
409  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
410  }
411 
415  public function deleteConstraintsObject()
416  {
417  $survey_questions =& $this->object->getSurveyQuestions();
418  $structure =& $_SESSION["constraintstructure"];
419  foreach ($_POST as $key => $value)
420  {
421  if (preg_match("/^constraint_(\d+)_(\d+)/", $key, $matches))
422  {
423  $this->object->deleteConstraint($matches[2]);
424  }
425  }
426 
427  $this->ctrl->redirect($this, "constraints");
428  }
429 
431  {
432  $include_elements = $_POST["includeElements"];
433  if ((!is_array($include_elements)) || (count($include_elements) == 0))
434  {
435  ilUtil::sendInfo($this->lng->txt("constraints_no_questions_or_questionblocks_selected"), true);
436  $this->ctrl->redirect($this, "constraints");
437  }
438  else if (count($include_elements) >= 1)
439  {
440  $_SESSION["includeElements"] = $include_elements;
441  sort($include_elements, SORT_NUMERIC);
442  $_GET["start"] = $include_elements[0];
443  $this->constraintStep1Object();
444  }
445  }
446 
448  {
449  $_SESSION["includeElements"] = array($_GET["start"]);
450  $this->ctrl->setParameter($this, "precondition", $_GET["precondition"]);
451  $this->ctrl->setParameter($this, "start", $_GET["start"]);
452  $this->ctrl->redirect($this, "constraintStep3");
453  }
454 }
455 
456 ?>