ILIAS  Release_4_2_x_branch Revision 61807
 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  $table_data[$id]["pool"] = $questionpools[$data["obj_fi"]];
156  }
157 
158  if (!$this->read_only)
159  {
160  if ($data["obj_fi"] > 0)
161  {
162  // edit url
163  $qpl_ref_id = current(ilObject::_getAllReferences($data["obj_fi"]));
164  $table_data[$id]["url"] = $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd) .
165  "&eqid=".$id."&eqpl=".$qpl_ref_id;
166  }
167 
168  // order
169  if(sizeof($survey_questions) > 1)
170  {
171  if (!$data["questionblock_id"])
172  {
173  $position += 10;
174  $table_data[$id]["position"] = $position;
175  }
176  else
177  {
178  $block_position += 10;
179  $table_data[$id]["position"] = $block_position;
180  }
181  }
182  }
183 
184  $last_questionblock_id = $data["questionblock_id"];
185  }
186  }
187 
188  $this->setData($table_data);
189  }
190 
196  protected function fillRow($a_set)
197  {
198  global $lng, $ilCtrl;
199 
200  switch($a_set["type"])
201  {
202  case "block":
203  if(!$this->read_only)
204  {
205  // checkbox
206  $this->tpl->setCurrentBlock("checkable");
207  $this->tpl->setVariable("QUESTION_ID", $a_set["id"]);
208  $this->tpl->parseCurrentBlock();
209 
210  // order
211  if($a_set["position"])
212  {
213  $this->tpl->setCurrentBlock("order");
214  $this->tpl->setVariable("ORDER_NAME", "order[".$a_set["id"]."]");
215  $this->tpl->setVariable("ORDER_VALUE", $a_set["position"]);
216  $this->tpl->parseCurrentBlock();
217  }
218  }
219 
220  $this->tpl->setVariable("TYPE", $lng->txt("questionblock"));
221  break;
222 
223  case "question":
224  $this->tpl->setVariable("DESCRIPTION", $a_set["description"]);
225  $this->tpl->setVariable("TYPE", $a_set["question_type"]);
226  $this->tpl->setVariable("AUTHOR", $a_set["author"]);
227  $this->tpl->setVariable("POOL", $a_set["pool"]);
228 
229  if($a_set["heading"])
230  {
231  $this->tpl->setCurrentBlock("heading");
232  $this->tpl->setVariable("TXT_HEADING", $a_set["heading"]);
233  $this->tpl->parseCurrentBlock();
234  }
235 
236  if($a_set["block_id"])
237  {
238  $this->tpl->setVariable("TITLE_INDENT", " style=\"padding-left:30px\"");
239  }
240 
241  if(!$this->read_only)
242  {
243  // checkbox
244  $this->tpl->setCurrentBlock("checkable");
245  $this->tpl->setVariable("QUESTION_ID", $a_set["id"]);
246  $this->tpl->parseCurrentBlock();
247 
248  if($a_set["block_id"])
249  {
250  $this->tpl->setVariable("CHECKABLE_INDENT", " style=\"padding-left:30px\"");
251  }
252 
253  // order
254  if($a_set["position"])
255  {
256  $this->tpl->setCurrentBlock("order");
257  if(!$a_set["block_id"])
258  {
259  $this->tpl->setVariable("ORDER_NAME", "order[q_".$a_set["id"]."]");
260  }
261  else
262  {
263  $this->tpl->setVariable("ORDER_NAME", "block_order[".$a_set["block_id"]."][".$a_set["id"]."]");
264  }
265  $this->tpl->setVariable("ORDER_VALUE", $a_set["position"]);
266  $this->tpl->parseCurrentBlock();
267  if($a_set["block_id"])
268  {
269  $this->tpl->setVariable("ORDER_INDENT", " style=\"padding-left:30px\"");
270  }
271  }
272 
273  // obligatory
274  $checked = $a_set["obligatory"] ? " checked=\"checked\"" : "";
275  $obligatory = "<input type=\"checkbox\" name=\"obligatory_".
276  $a_set["id"] . "\" value=\"1\"".$checked." />";
277  }
278  else if($a_set["obligatory"])
279  {
280  $obligatory = "<img src=\"".ilUtil::getImagePath("obligatory.gif", "Modules/Survey").
281  "\" alt=\"".$lng->txt("question_obligatory").
282  "\" title=\"".$lng->txt("question_obligatory")."\" />";
283  }
284  $this->tpl->setVariable("OBLIGATORY", $obligatory);
285  break;
286 
287  case "heading":
288  if(!$this->read_only)
289  {
290  // checkbox
291  $this->tpl->setCurrentBlock("checkable");
292  $this->tpl->setVariable("QUESTION_ID", $a_set["id"]);
293  $this->tpl->parseCurrentBlock();
294  if($a_set["in_block"])
295  {
296  $this->tpl->setVariable("CHECKABLE_INDENT", " style=\"padding-left:30px\"");
297  $this->tpl->setVariable("TITLE_INDENT", " style=\"padding-left:30px\"");
298  }
299  }
300 
301  $this->tpl->setVariable("TYPE", $lng->txt("heading"));
302  break;
303  }
304 
305  if(!$this->read_only)
306  {
307  $this->tpl->setCurrentBlock("actions");
308 
309  include_once "Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php";
310  $list = new ilAdvancedSelectionListGUI();
311  $list->setId($a_set["id"]);
312  $list->setListTitle($lng->txt("actions"));
313  if($a_set["url"])
314  {
315  $list->addItem($lng->txt("edit"), "", $a_set["url"]);
316  }
317 
318  if($a_set["heading"])
319  {
320  $edit = $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd) .
321  "&editheading=" . $a_set["id"];
322  $list->addItem($lng->txt("survey_edit_heading"), "", $edit);
323 
324  $rmv = $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd) .
325  "&removeheading=" . $a_set["id"];
326  $list->addItem($lng->txt("survey_delete_heading"), "", $rmv);
327  }
328  else if($a_set["type"] == "question")
329  {
330  $add = $ilCtrl->getLinkTarget($this->parent_obj, "addHeading") .
331  "&insertbefore=" . $a_set["id"];
332  $list->addItem($lng->txt("add_heading"), "", $add);
333  }
334 
335  $this->tpl->setVariable("ACTION", $list->getHTML());
336 
337  $this->tpl->parseCurrentBlock();
338 
339 
340  $this->tpl->setCurrentBlock("title_edit");
341  $this->tpl->setVariable("TITLE", $a_set["title"]);
342  $this->tpl->setVariable("URL_TITLE", $a_set["url"]);
343  $this->tpl->parseCurrentBlock();
344  }
345  else
346  {
347  $this->tpl->setCurrentBlock("title_static");
348  $this->tpl->setVariable("TITLE", $a_set["title"]);
349  $this->tpl->parseCurrentBlock();
350  }
351  }
352 }
353 
354 ?>