ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyConstraintsTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Table/classes/class.ilTable2GUI.php");
5 
15 {
16  protected $read_only; // [bool]
17  protected $structure; // [array]
18 
19  function __construct($a_parent_obj, $a_parent_cmd = "", ilObjSurvey $a_survey, $a_read_only)
20  {
21  global $ilCtrl, $lng;
22 
23  $this->read_only = (bool)$a_read_only;
24 
25  parent::__construct($a_parent_obj, $a_parent_cmd);
26 
27  $this->setLimit(9999);
28  $this->disable("numinfo");
29 
30  $this->setDescription($lng->txt("constraints_introduction"));
31 
32  if(!$this->read_only)
33  {
34  $this->addColumn("", "", 1);
35  }
36 
37  $this->addColumn("", "", 1);
38  $this->addColumn($lng->txt("constraints_list_of_entities"), "");
39  $this->addColumn($lng->txt("existing_constraints"), "");
40 
41  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
42  $this->setRowTemplate("tpl.svy_constraints_row.html", "Modules/Survey");
43 
44  if(!$this->read_only)
45  {
46  $this->addMultiCommand("createConstraints", $lng->txt("constraint_add"));
47  $this->setSelectAllCheckbox("includeElements");
48  }
49 
50  $this->initItems($a_survey);
51  }
52 
53  protected function initItems(ilObjSurvey $a_survey)
54  {
55  global $lng;
56 
57  $this->structure = array();
58  $tbl_data = array();
59 
60  $survey_questions = $a_survey->getSurveyQuestions();
61 
62  $last_questionblock_id = 0;
63  $counter = 1;
64  foreach ($survey_questions as $data)
65  {
66  $title = $data["title"];
67  $show = true;
68  if ($data["questionblock_id"] > 0)
69  {
70  $title = $data["questionblock_title"];
71  $type = $lng->txt("questionblock");
72  if ($data["questionblock_id"] != $last_questionblock_id)
73  {
74  $last_questionblock_id = $data["questionblock_id"];
75  $this->structure[$counter] = array();
76  array_push($this->structure[$counter], $data["question_id"]);
77  }
78  else
79  {
80  array_push($this->structure[$counter-1], $data["question_id"]);
81  $show = false;
82  }
83  }
84  else
85  {
86  $this->structure[$counter] = array($data["question_id"]);
87  $type = $lng->txt("question");
88  }
89  if ($show)
90  {
91  $id = $content = $parsed = $conjunction = null;
92 
93  if ($counter == 1)
94  {
95  $content = $lng->txt("constraints_first_question_description");
96  }
97  else
98  {
99  $constraints = $a_survey->getConstraints($data["question_id"]);
100  if (count($constraints))
101  {
102  $parsed = array();
103 
104  foreach ($constraints as $constraint)
105  {
106  $parsed[] = array(
107  "id" => $constraint["id"],
108  "title" => $survey_questions[$constraint["question"]]["title"] . " " .
109  $constraint["short"] . " " .
110  $constraint["valueoutput"]
111  );
112  }
113 
114  if (count($constraints) > 1)
115  {
116  $conjunction = ($constraints[0]['conjunction'])
117  ? $lng->txt('conjunction_or_title')
118  : $lng->txt('conjunction_and_title');
119  }
120  }
121  }
122  if ($counter != 1)
123  {
124  $id = $counter;
125  }
126 
127  $icontype = "question.png";
128  if ($data["questionblock_id"] > 0)
129  {
130  $icontype = "questionblock.png";
131  }
132 
133  $tbl_data[] = array(
134  "counter" => $counter,
135  "id" => $id,
136  "title" => $title,
137  "type" => $type,
138  "icon" => ilUtil::getImagePath($icontype, "Modules/Survey"),
139  "content" => $content,
140  "constraints" => $parsed,
141  "conjunction" => $conjunction
142  );
143 
144  $counter++;
145  }
146  }
147 
148  $this->setData($tbl_data);
149  }
150 
151  public function getStructure()
152  {
153  return $this->structure;
154  }
155 
156  protected function fillRow($a_set)
157  {
158  global $ilCtrl, $lng;
159 
160  // $ilCtrl->setParameterByClass("ilObjSurveyAdministrationGUI", "item_id", $a_set["usr_id"]);
161 
162  if(!$this->read_only)
163  {
164  if($a_set["id"])
165  {
166  $this->tpl->setVariable("ID", $a_set["id"]);
167  }
168  else
169  {
170  $this->tpl->touchBlock("checkbox");
171  }
172  }
173 
174  $this->tpl->setVariable("COUNTER", $a_set["counter"]);
175  $this->tpl->setVariable("TITLE", $a_set["title"]);
176  $this->tpl->setVariable("TYPE", $a_set["type"]);
177  $this->tpl->setVariable("ICON_HREF", $a_set["icon"]);
178  $this->tpl->setVariable("ICON_ALT", $a_set["type"]);
179  $this->tpl->setVariable("CONTENT", $a_set["content"]);
180 
181  if(is_array($a_set["constraints"]))
182  {
183  foreach($a_set["constraints"] as $constraint)
184  {
185  if(!$this->read_only)
186  {
187  $ilCtrl->setParameter($this->getParentObject(), "precondition", $constraint["id"]);
188  $ilCtrl->setParameter($this->getParentObject(), "start", $a_set["counter"]);
189  $url = $ilCtrl->getLinkTarget($this->getParentObject(), "editPrecondition");
190  $ilCtrl->setParameter($this->getParentObject(), "precondition", "");
191  $ilCtrl->setParameter($this->getParentObject(), "start", "");
192  $this->tpl->setVariable("TEXT_EDIT_PRECONDITION", $lng->txt("edit"));
193  $this->tpl->setVariable("EDIT_PRECONDITION", $url);
194 
195  $ilCtrl->setParameter($this->getParentObject(), "precondition", $constraint["id"]);
196  $url = $ilCtrl->getLinkTarget($this->getParentObject(), "confirmDeleteConstraints");
197  $ilCtrl->setParameter($this->getParentObject(), "precondition", "");
198  $this->tpl->setVariable("TEXT_DELETE_PRECONDITION", $lng->txt("delete"));
199  $this->tpl->setVariable("DELETE_PRECONDITION", $url);
200  }
201 
202  $this->tpl->setCurrentBlock("constraint");
203  $this->tpl->setVariable("CONSTRAINT_TEXT", $constraint["title"]);
204  $this->tpl->parseCurrentBlock();
205  }
206 
207  if($a_set["conjunction"])
208  {
209  $this->tpl->setCurrentBlock("conjunction");
210  $this->tpl->setVariable("TEXT_CONJUNCTION", $a_set["conjunction"]);
211  $this->tpl->parseCurrentBlock();
212  }
213  }
214  }
215 
216 }
217 ?>