ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  public function __construct($a_parent_obj, $a_parent_cmd, ilObjSurvey $a_survey_obj, $a_read_only = false)
26  {
27  global $DIC;
28 
29  $this->ctrl = $DIC->ctrl();
30  $this->lng = $DIC->language();
31  $ilCtrl = $DIC->ctrl();
32  $lng = $DIC->language();
33 
34  $this->object = $a_survey_obj;
35  $this->read_only = (bool) $a_read_only;
36 
37  parent::__construct($a_parent_obj, $a_parent_cmd);
38 
39  $this->setId("il_svy_qst");
40  $this->setLimit(9999);
41 
42  // $this->setTitle($lng->txt("survey_questions"));
43 
44  if (!$this->read_only) {
45  // command dropdown
46  if (!array_key_exists("move_questions", $_SESSION)) {
47  $this->addMultiCommand("createQuestionblock", $lng->txt("define_questionblock"));
48  $this->addMultiCommand("unfoldQuestionblock", $lng->txt("unfold"));
49  $this->addMultiCommand("removeQuestions", $lng->txt("remove_question"));
50  $this->addMultiCommand("moveQuestions", $lng->txt("move"));
51  $this->addMultiCommand("copyQuestionsToPool", $lng->txt("survey_copy_questions_to_pool"));
52  } else {
53  $this->addMultiCommand("insertQuestionsBefore", $lng->txt("insert_before"));
54  $this->addMultiCommand("insertQuestionsAfter", $lng->txt("insert_after"));
55  }
56 
57  // right side
58  $this->addCommandButton("saveObligatory", $lng->txt("save_obligatory_state"));
59 
60  $this->setSelectAllCheckbox("id[]");
61  $this->addColumn("", "");
62  $this->addColumn($lng->txt("survey_order"), "");
63  }
64 
65  $this->addColumn($lng->txt("title"), "");
66  $this->addColumn($lng->txt("obligatory"), "");
67  $this->addColumn($lng->txt("description"), "");
68  $this->addColumn($lng->txt("type"), "");
69  $this->addColumn($lng->txt("author"), "");
70  $this->addColumn($lng->txt("survey_question_pool"), "");
71 
72  if (!$this->read_only) {
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->setShowRowsSelector(true);
83 
84  $this->importData();
85  }
86 
90  protected function importData()
91  {
93  $lng = $this->lng;
94 
95  $survey_questions = $this->object->getSurveyQuestions();
96  if (count($survey_questions) > 0) {
97  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
99 
100  $questionpools = $this->object->getQuestionpoolTitles(true);
101 
102  $table_data = array();
103  $last_questionblock_id = $position = $block_position = 0;
104  foreach ($survey_questions as $question_id => $data) {
105  // question block
106  if ($data["questionblock_id"] > 0 &&
107  $data["questionblock_id"] != $last_questionblock_id) {
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  // order
116  if (sizeof($survey_questions) > 1) {
117  $position += 10;
118  $table_data[$id]["position"] = $position;
119  }
120 
121  $ilCtrl->setParameter($this->parent_obj, "bl_id", $data["questionblock_id"]);
122  $table_data[$id]["url"] = $ilCtrl->getLinkTarget($this->parent_obj, "editQuestionblock");
123  $ilCtrl->setParameter($this->parent_obj, "bl_id", "");
124  }
125 
126  $block_position = 0;
127  }
128 
129  // question
130 
131  $id = $data["question_id"];
132 
133  $table_data[$id] = array("id" => $id,
134  "type" => "question",
135  "heading" => $data["heading"],
136  "title" => $data["title"],
137  "description" => $data["description"],
138  "author" => $data["author"],
139  "block_id" => $data["questionblock_id"],
140  "obligatory" => (bool) $data["obligatory"]);
141 
142  // question type
143  foreach ($questiontypes as $trans => $typedata) {
144  if (strcmp($typedata["type_tag"], $data["type_tag"]) == 0) {
145  $table_data[$id]["question_type"] = $trans;
146  }
147  }
148 
149  // pool title
150  if ($data["original_id"]) {
151  $original_fi = SurveyQuestion::lookupObjFi($data["original_id"]);
152  if (isset($questionpools[$original_fi])) {
153  $table_data[$id]["pool"] = $questionpools[$original_fi];
154  } else {
155  // #11186
156  $table_data[$id]["pool"] = $this->lng->txt("status_no_permission");
157  }
158  }
159 
160  if (!$this->read_only) {
161  if ($data["obj_fi"] > 0) {
162  // edit url
163  $q_gui = $data["type_tag"] . "GUI";
164  $ilCtrl->setParameterByClass($q_gui, "q_id", $id);
165  $table_data[$id]["url"] = $ilCtrl->getLinkTargetByClass($q_gui, "editQuestion") .
166  $ilCtrl->setParameterByClass($q_gui, "q_id", "");
167  }
168 
169  // order
170  if (sizeof($survey_questions) > 1) {
171  if (!$data["questionblock_id"]) {
172  $position += 10;
173  $table_data[$id]["position"] = $position;
174  } else {
175  $block_position += 10;
176  $table_data[$id]["position"] = $block_position;
177  }
178  }
179  }
180 
181  $last_questionblock_id = $data["questionblock_id"];
182  }
183  }
184 
185  $this->setData($table_data);
186  }
187 
193  protected function fillRow($a_set)
194  {
195  $lng = $this->lng;
197 
198  switch ($a_set["type"]) {
199  case "block":
200  if (!$this->read_only) {
201  // checkbox
202  $this->tpl->setCurrentBlock("checkable");
203  $this->tpl->setVariable("QUESTION_ID", $a_set["id"]);
204  $this->tpl->parseCurrentBlock();
205 
206  // order
207  if ($a_set["position"]) {
208  $this->tpl->setCurrentBlock("order");
209  $this->tpl->setVariable("ORDER_NAME", "order[" . $a_set["id"] . "]");
210  $this->tpl->setVariable("ORDER_VALUE", $a_set["position"]);
211  $this->tpl->parseCurrentBlock();
212  }
213  }
214 
215  $this->tpl->setVariable("TYPE", $lng->txt("questionblock"));
216  break;
217 
218  case "question":
219  $this->tpl->setVariable("DESCRIPTION", $a_set["description"]);
220  $this->tpl->setVariable("TYPE", $a_set["question_type"]);
221  $this->tpl->setVariable("AUTHOR", $a_set["author"]);
222  $this->tpl->setVariable("POOL", $a_set["pool"]);
223 
224  if ($a_set["heading"]) {
225  $this->tpl->setCurrentBlock("heading");
226  $this->tpl->setVariable("TXT_HEADING", $a_set["heading"]);
227  $this->tpl->parseCurrentBlock();
228  }
229 
230  if ($a_set["block_id"]) {
231  $this->tpl->setVariable("TITLE_INDENT", " style=\"padding-left:30px\"");
232  }
233 
234  if (!$this->read_only) {
235  // checkbox
236  $this->tpl->setCurrentBlock("checkable");
237  $this->tpl->setVariable("QUESTION_ID", $a_set["id"]);
238  $this->tpl->parseCurrentBlock();
239 
240  if ($a_set["block_id"]) {
241  $this->tpl->setVariable("CHECKABLE_INDENT", " style=\"padding-left:30px\"");
242  }
243 
244  // order
245  if ($a_set["position"]) {
246  $this->tpl->setCurrentBlock("order");
247  if (!$a_set["block_id"]) {
248  $this->tpl->setVariable("ORDER_NAME", "order[q_" . $a_set["id"] . "]");
249  } else {
250  $this->tpl->setVariable("ORDER_NAME", "block_order[" . $a_set["block_id"] . "][" . $a_set["id"] . "]");
251  }
252  $this->tpl->setVariable("ORDER_VALUE", $a_set["position"]);
253  $this->tpl->parseCurrentBlock();
254  if ($a_set["block_id"]) {
255  $this->tpl->setVariable("ORDER_INDENT", " style=\"padding-left:30px\"");
256  }
257  }
258 
259  // obligatory
260  $checked = $a_set["obligatory"] ? " checked=\"checked\"" : "";
261  $obligatory = "<input type=\"checkbox\" name=\"obligatory_" .
262  $a_set["id"] . "\" value=\"1\"" . $checked . " />";
263  } elseif ($a_set["obligatory"]) {
264  $obligatory = "<img src=\"" . ilUtil::getImagePath("obligatory.png", "Modules/Survey") .
265  "\" alt=\"" . $lng->txt("question_obligatory") .
266  "\" title=\"" . $lng->txt("question_obligatory") . "\" />";
267  }
268  $this->tpl->setVariable("OBLIGATORY", $obligatory);
269  break;
270 
271  case "heading":
272  if (!$this->read_only) {
273  // checkbox
274  $this->tpl->setCurrentBlock("checkable");
275  $this->tpl->setVariable("QUESTION_ID", $a_set["id"]);
276  $this->tpl->parseCurrentBlock();
277  if ($a_set["in_block"]) {
278  $this->tpl->setVariable("CHECKABLE_INDENT", " style=\"padding-left:30px\"");
279  $this->tpl->setVariable("TITLE_INDENT", " style=\"padding-left:30px\"");
280  }
281  }
282 
283  $this->tpl->setVariable("TYPE", $lng->txt("heading"));
284  break;
285  }
286 
287  if (!$this->read_only) {
288  $this->tpl->setCurrentBlock("actions");
289 
290  $ilCtrl->setParameter($this->parent_obj, "q_id", $a_set["id"]);
291 
292  include_once "Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php";
294  $list->setId($a_set["id"]);
295  $list->setListTitle($lng->txt("actions"));
296  if ($a_set["url"]) {
297  $list->addItem($lng->txt("edit"), "", $a_set["url"]);
298  }
299 
300  if ($a_set["heading"]) {
301  $list->addItem(
302  $lng->txt("survey_edit_heading"),
303  "",
304  $ilCtrl->getLinkTarget($this->parent_obj, "editheading")
305  );
306 
307  $list->addItem(
308  $lng->txt("survey_delete_heading"),
309  "",
310  $ilCtrl->getLinkTarget($this->parent_obj, "removeheading")
311  );
312  } elseif ($a_set["type"] == "question") {
313  $list->addItem(
314  $lng->txt("add_heading"),
315  "",
316  $ilCtrl->getLinkTarget($this->parent_obj, "addHeading")
317  );
318  }
319 
320  $this->tpl->setVariable("ACTION", $list->getHTML());
321 
322  $ilCtrl->setParameter($this->parent_obj, "q_id", "");
323 
324  $this->tpl->parseCurrentBlock();
325 
326  // #11186
327  if ($a_set["url"]) {
328  $this->tpl->setCurrentBlock("title_edit");
329  $this->tpl->setVariable("TITLE", $a_set["title"]);
330  $this->tpl->setVariable("URL_TITLE", $a_set["url"]);
331  $this->tpl->parseCurrentBlock();
332  } else {
333  $this->tpl->setCurrentBlock("title_static");
334  $this->tpl->setVariable("TITLE", $a_set["title"]);
335  $this->tpl->parseCurrentBlock();
336  }
337  } else {
338  $this->tpl->setCurrentBlock("title_static");
339  $this->tpl->setVariable("TITLE", $a_set["title"]);
340  $this->tpl->parseCurrentBlock();
341  }
342  }
343 }
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
$_SESSION["AccountId"]
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
static lookupObjFi($a_qid)
Lookip obj fi.
setId($a_val)
Set id.
global $ilCtrl
Definition: ilias.php:18
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
Class ilTable2GUI.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
addMultiCommand($a_cmd, $a_text)
Add Command button.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
Create styles array
The data for the language used.
Survey question table GUI class.
__construct($a_parent_obj, $a_parent_cmd, ilObjSurvey $a_survey_obj, $a_read_only=false)
Constructor.
User interface class for advanced drop-down selection lists.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
static _getQuestiontypes()
Creates a list of all available question types.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
setLimit($a_limit=0, $a_default_limit=0)