ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSurveyQuestionTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2010 Leifos, GPL, see docs/LICENSE */
3 
4 include_once("./Services/Table/classes/class.ilTable2GUI.php");
5 
15 {
16  protected $object;
17  protected $read_only;
18 
25  function __construct($a_parent_obj, $a_parent_cmd, ilObjSurvey $a_survey_obj, $a_read_only = false)
26  {
27  global $ilCtrl, $lng;
28 
29  $this->object = $a_survey_obj;
30  $this->read_only = (bool)$a_read_only;
31 
32  parent::__construct($a_parent_obj, $a_parent_cmd);
33 
34  $this->setId("il_svy_qst");
35  $this->setLimit(9999);
36 
37  // $this->setTitle($lng->txt("survey_questions"));
38 
39  if(!$this->read_only)
40  {
41  // command dropdown
42  if(!array_key_exists("move_questions", $_SESSION))
43  {
44  $this->addMultiCommand("defineQuestionblock", $lng->txt("define_questionblock"));
45  $this->addMultiCommand("unfoldQuestionblock", $lng->txt("unfold"));
46  $this->addMultiCommand("removeQuestions", $lng->txt("remove_question"));
47  $this->addMultiCommand("moveQuestions", $lng->txt("move"));
48  $this->addMultiCommand("copyQuestionsToPool", $lng->txt("survey_copy_questions_to_pool"));
49  }
50  else
51  {
52  $this->addMultiCommand("insertQuestionsBefore", $lng->txt("insert_before"));
53  $this->addMultiCommand("insertQuestionsAfter", $lng->txt("insert_after"));
54  }
55 
56  // right side
57  $this->addCommandButton("saveObligatory", $lng->txt("save_obligatory_state"));
58 
59  $this->setSelectAllCheckbox("id[]");
60  $this->addColumn("", "");
61  $this->addColumn($lng->txt("survey_order"), "");
62  }
63 
64  $this->addColumn($lng->txt("title"), "");
65  $this->addColumn($lng->txt("obligatory"), "");
66  $this->addColumn($lng->txt("description"), "");
67  $this->addColumn($lng->txt("type"), "");
68  $this->addColumn($lng->txt("author"), "");
69  $this->addColumn($lng->txt("survey_question_pool"), "");
70 
71  if(!$this->read_only)
72  {
73  $this->addColumn("", "");
74  }
75 
76  $this->setDefaultOrderField("order");
77  $this->setDefaultOrderDirection("asc");
78 
79  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
80  $this->setRowTemplate("tpl.il_svy_svy_question_table.html", "Modules/Survey");
81 
82  $this->importData();
83  }
84 
88  protected function importData()
89  {
90  global $ilCtrl, $lng;
91 
92  $survey_questions = $this->object->getSurveyQuestions();
93  if (count($survey_questions) > 0)
94  {
95  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
97 
98  $questionpools = $this->object->getQuestionpoolTitles(true);
99 
100  $table_data = array();
101  $last_questionblock_id = $position = $block_position = 0;
102  foreach ($survey_questions as $question_id => $data)
103  {
104  // question block
105  if ($data["questionblock_id"] > 0 &&
106  $data["questionblock_id"] != $last_questionblock_id)
107  {
108  $id = "qb_" . $data["questionblock_id"];
109 
110  $table_data[$id] = array("id" => $id,
111  "type" => "block",
112  "title" => $data["questionblock_title"]);
113 
114  if (!$this->read_only)
115  {
116  // order
117  if(sizeof($survey_questions) > 1)
118  {
119  $position += 10;
120  $table_data[$id]["position"] = $position;
121  }
122 
123  $table_data[$id]["url"] = $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd).
124  "&editblock=".$data["questionblock_id"];
125  }
126 
127  $block_position = 0;
128  }
129 
130  // question
131 
132  $id = $data["question_id"];
133 
134  $table_data[$id] = array("id" => $id,
135  "type" => "question",
136  "heading" => $data["heading"],
137  "title" => $data["title"],
138  "description" => $data["description"],
139  "author" => $data["author"],
140  "block_id" => $data["questionblock_id"],
141  "obligatory" => (bool)$data["obligatory"]);
142 
143  // question type
144  foreach ($questiontypes as $trans => $typedata)
145  {
146  if (strcmp($typedata["type_tag"], $data["type_tag"]) == 0)
147  {
148  $table_data[$id]["question_type"] = $trans;
149  }
150  }
151 
152  // pool title
153  if($data["original_id"])
154  {
155  if(isset($questionpools[$data["obj_fi"]]))
156  {
157  $table_data[$id]["pool"] = $questionpools[$data["obj_fi"]];
158  }
159  else
160  {
161  // #11186
162  $table_data[$id]["pool"] = $this->lng->txt("status_no_permission");
163  }
164  }
165 
166  if (!$this->read_only)
167  {
168  if ($data["obj_fi"] > 0)
169  {
170  // edit url
171  $qpl_ref_id = current(ilObject::_getAllReferences($data["obj_fi"]));
172  $table_data[$id]["url"] = $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd) .
173  "&eqid=".$id."&eqpl=".$qpl_ref_id;
174  }
175 
176  // order
177  if(sizeof($survey_questions) > 1)
178  {
179  if (!$data["questionblock_id"])
180  {
181  $position += 10;
182  $table_data[$id]["position"] = $position;
183  }
184  else
185  {
186  $block_position += 10;
187  $table_data[$id]["position"] = $block_position;
188  }
189  }
190  }
191 
192  $last_questionblock_id = $data["questionblock_id"];
193  }
194  }
195 
196  $this->setData($table_data);
197  }
198 
204  protected function fillRow($a_set)
205  {
206  global $lng, $ilCtrl;
207 
208  switch($a_set["type"])
209  {
210  case "block":
211  if(!$this->read_only)
212  {
213  // checkbox
214  $this->tpl->setCurrentBlock("checkable");
215  $this->tpl->setVariable("QUESTION_ID", $a_set["id"]);
216  $this->tpl->parseCurrentBlock();
217 
218  // order
219  if($a_set["position"])
220  {
221  $this->tpl->setCurrentBlock("order");
222  $this->tpl->setVariable("ORDER_NAME", "order[".$a_set["id"]."]");
223  $this->tpl->setVariable("ORDER_VALUE", $a_set["position"]);
224  $this->tpl->parseCurrentBlock();
225  }
226  }
227 
228  $this->tpl->setVariable("TYPE", $lng->txt("questionblock"));
229  break;
230 
231  case "question":
232  $this->tpl->setVariable("DESCRIPTION", $a_set["description"]);
233  $this->tpl->setVariable("TYPE", $a_set["question_type"]);
234  $this->tpl->setVariable("AUTHOR", $a_set["author"]);
235  $this->tpl->setVariable("POOL", $a_set["pool"]);
236 
237  if($a_set["heading"])
238  {
239  $this->tpl->setCurrentBlock("heading");
240  $this->tpl->setVariable("TXT_HEADING", $a_set["heading"]);
241  $this->tpl->parseCurrentBlock();
242  }
243 
244  if($a_set["block_id"])
245  {
246  $this->tpl->setVariable("TITLE_INDENT", " style=\"padding-left:30px\"");
247  }
248 
249  if(!$this->read_only)
250  {
251  // checkbox
252  $this->tpl->setCurrentBlock("checkable");
253  $this->tpl->setVariable("QUESTION_ID", $a_set["id"]);
254  $this->tpl->parseCurrentBlock();
255 
256  if($a_set["block_id"])
257  {
258  $this->tpl->setVariable("CHECKABLE_INDENT", " style=\"padding-left:30px\"");
259  }
260 
261  // order
262  if($a_set["position"])
263  {
264  $this->tpl->setCurrentBlock("order");
265  if(!$a_set["block_id"])
266  {
267  $this->tpl->setVariable("ORDER_NAME", "order[q_".$a_set["id"]."]");
268  }
269  else
270  {
271  $this->tpl->setVariable("ORDER_NAME", "block_order[".$a_set["block_id"]."][".$a_set["id"]."]");
272  }
273  $this->tpl->setVariable("ORDER_VALUE", $a_set["position"]);
274  $this->tpl->parseCurrentBlock();
275  if($a_set["block_id"])
276  {
277  $this->tpl->setVariable("ORDER_INDENT", " style=\"padding-left:30px\"");
278  }
279  }
280 
281  // obligatory
282  $checked = $a_set["obligatory"] ? " checked=\"checked\"" : "";
283  $obligatory = "<input type=\"checkbox\" name=\"obligatory_".
284  $a_set["id"] . "\" value=\"1\"".$checked." />";
285  }
286  else if($a_set["obligatory"])
287  {
288  $obligatory = "<img src=\"".ilUtil::getImagePath("obligatory.png", "Modules/Survey").
289  "\" alt=\"".$lng->txt("question_obligatory").
290  "\" title=\"".$lng->txt("question_obligatory")."\" />";
291  }
292  $this->tpl->setVariable("OBLIGATORY", $obligatory);
293  break;
294 
295  case "heading":
296  if(!$this->read_only)
297  {
298  // checkbox
299  $this->tpl->setCurrentBlock("checkable");
300  $this->tpl->setVariable("QUESTION_ID", $a_set["id"]);
301  $this->tpl->parseCurrentBlock();
302  if($a_set["in_block"])
303  {
304  $this->tpl->setVariable("CHECKABLE_INDENT", " style=\"padding-left:30px\"");
305  $this->tpl->setVariable("TITLE_INDENT", " style=\"padding-left:30px\"");
306  }
307  }
308 
309  $this->tpl->setVariable("TYPE", $lng->txt("heading"));
310  break;
311  }
312 
313  if(!$this->read_only)
314  {
315  $this->tpl->setCurrentBlock("actions");
316 
317  include_once "Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php";
318  $list = new ilAdvancedSelectionListGUI();
319  $list->setId($a_set["id"]);
320  $list->setListTitle($lng->txt("actions"));
321  if($a_set["url"])
322  {
323  $list->addItem($lng->txt("edit"), "", $a_set["url"]);
324  }
325 
326  if($a_set["heading"])
327  {
328  $edit = $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd) .
329  "&editheading=" . $a_set["id"];
330  $list->addItem($lng->txt("survey_edit_heading"), "", $edit);
331 
332  $rmv = $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd) .
333  "&removeheading=" . $a_set["id"];
334  $list->addItem($lng->txt("survey_delete_heading"), "", $rmv);
335  }
336  else if($a_set["type"] == "question")
337  {
338  $add = $ilCtrl->getLinkTarget($this->parent_obj, "addHeading") .
339  "&insertbefore=" . $a_set["id"];
340  $list->addItem($lng->txt("add_heading"), "", $add);
341  }
342 
343  $this->tpl->setVariable("ACTION", $list->getHTML());
344 
345  $this->tpl->parseCurrentBlock();
346 
347  // #11186
348  if($a_set["url"])
349  {
350  $this->tpl->setCurrentBlock("title_edit");
351  $this->tpl->setVariable("TITLE", $a_set["title"]);
352  $this->tpl->setVariable("URL_TITLE", $a_set["url"]);
353  $this->tpl->parseCurrentBlock();
354  }
355  else
356  {
357  $this->tpl->setCurrentBlock("title_static");
358  $this->tpl->setVariable("TITLE", $a_set["title"]);
359  $this->tpl->parseCurrentBlock();
360  }
361  }
362  else
363  {
364  $this->tpl->setCurrentBlock("title_static");
365  $this->tpl->setVariable("TITLE", $a_set["title"]);
366  $this->tpl->parseCurrentBlock();
367  }
368  }
369 }
370 
371 ?>