ILIAS  release_8 Revision v8.24
class.ilSurveyQuestionTableGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected \ILIAS\DI\UIServices $ui;
28 protected bool $read_only;
29
30 public function __construct(
31 object $a_parent_obj,
32 string $a_parent_cmd,
33 ilObjSurvey $a_survey_obj,
34 bool $a_read_only = false
35 ) {
36 global $DIC;
37
38 $this->ctrl = $DIC->ctrl();
39 $this->lng = $DIC->language();
40 $ilCtrl = $DIC->ctrl();
41 $lng = $DIC->language();
42 $this->ui = $DIC->ui();
43
44 $this->object = $a_survey_obj;
45 $this->read_only = $a_read_only;
46
47 parent::__construct($a_parent_obj, $a_parent_cmd);
48
49 $this->setId("il_svy_qst");
50 $this->setLimit(9999);
51
52 $edit_manager = $DIC->survey()
53 ->internal()
54 ->domain()
55 ->edit();
56
57 if (!$this->read_only) {
58 // command dropdown
59 if (count($edit_manager->getMoveSurveyQuestions()) === 0 ||
60 $edit_manager->getMoveSurveyId() !== $this->object->getId()) {
61 $this->addMultiCommand("createQuestionblock", $lng->txt("define_questionblock"));
62 $this->addMultiCommand("unfoldQuestionblock", $lng->txt("unfold"));
63 $this->addMultiCommand("removeQuestions", $lng->txt("remove_question"));
64 $this->addMultiCommand("moveQuestions", $lng->txt("move"));
65 $this->addMultiCommand("copyQuestionsToPool", $lng->txt("survey_copy_questions_to_pool"));
66 } else {
67 $this->addMultiCommand("insertQuestionsBefore", $lng->txt("insert_before"));
68 $this->addMultiCommand("insertQuestionsAfter", $lng->txt("insert_after"));
69 }
70
71 // right side
72 $this->addCommandButton("saveObligatory", $lng->txt("save_obligatory_state"));
73
74 $this->setSelectAllCheckbox("id[]");
75 $this->addColumn("", "");
76 $this->addColumn($lng->txt("survey_order"), "");
77 }
78
79 $this->addColumn($lng->txt("title"), "");
80 $this->addColumn($lng->txt("obligatory"), "");
81 $this->addColumn($lng->txt("description"), "");
82 $this->addColumn($lng->txt("type"), "");
83 $this->addColumn($lng->txt("author"), "");
84 $this->addColumn($lng->txt("survey_question_pool"), "");
85
86 if (!$this->read_only) {
87 $this->addColumn("", "");
88 }
89
90 $this->setDefaultOrderField("order");
91 $this->setDefaultOrderDirection("asc");
92
93 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
94 $this->setRowTemplate("tpl.il_svy_svy_question_table.html", "Modules/Survey");
95
96 $this->setShowRowsSelector(true);
97
98 $this->importData();
99 }
100
101 protected function importData(): void
102 {
103 $ilCtrl = $this->ctrl;
104
105 $table_data = [];
106 $survey_questions = $this->object->getSurveyQuestions();
107 if (count($survey_questions) > 0) {
109
110 $questionpools = $this->object->getQuestionpoolTitles(true);
111
112 $table_data = array();
113 $last_questionblock_id = $position = $block_position = 0;
114 foreach ($survey_questions as $question_id => $data) {
115 // question block
116 if ($data["questionblock_id"] > 0 &&
117 $data["questionblock_id"] != $last_questionblock_id) {
118 $id = "qb_" . $data["questionblock_id"];
119
120 $table_data[$id] = array("id" => $id,
121 "type" => "block",
122 "title" => $data["questionblock_title"]);
123
124 if (!$this->read_only) {
125 // order
126 if (count($survey_questions) > 1) {
127 $position += 10;
128 $table_data[$id]["position"] = $position;
129 }
130
131 $ilCtrl->setParameter($this->parent_obj, "bl_id", $data["questionblock_id"]);
132 $table_data[$id]["url"] = $ilCtrl->getLinkTarget($this->parent_obj, "editQuestionblock");
133 $ilCtrl->setParameter($this->parent_obj, "bl_id", "");
134 }
135
136 $block_position = 0;
137 }
138
139 // question
140
141 $id = $data["question_id"];
142
143 $table_data[$id] = array("id" => $id,
144 "type" => "question",
145 "heading" => $data["heading"],
146 "title" => $data["title"],
147 "description" => $data["description"],
148 "author" => $data["author"],
149 "block_id" => $data["questionblock_id"],
150 "obligatory" => (bool) $data["obligatory"]);
151
152 // question type
153 foreach ($questiontypes as $trans => $typedata) {
154 if (strcmp($typedata["type_tag"], $data["type_tag"]) === 0) {
155 $table_data[$id]["question_type"] = $trans;
156 }
157 }
158
159 // pool title
160 if ($data["original_id"]) {
161 $original_fi = SurveyQuestion::lookupObjFi($data["original_id"]);
162 if (isset($questionpools[$original_fi])) {
163 $table_data[$id]["pool"] = $questionpools[$original_fi];
164 } else {
165 // #11186
166 $table_data[$id]["pool"] = "-";
167 }
168 }
169
170 if (!$this->read_only) {
171 if ($data["obj_fi"] > 0) {
172 // edit url
173 $q_gui = $data["type_tag"] . "GUI";
174 $ilCtrl->setParameterByClass($q_gui, "q_id", $id);
175 $table_data[$id]["url"] = $ilCtrl->getLinkTargetByClass($q_gui, "editQuestion") .
176 $ilCtrl->setParameterByClass($q_gui, "q_id", "");
177 }
178
179 // order
180 if (count($survey_questions) > 1) {
181 if (!$data["questionblock_id"]) {
182 $position += 10;
183 $table_data[$id]["position"] = $position;
184 } else {
185 $block_position += 10;
186 $table_data[$id]["position"] = $block_position;
187 }
188 }
189 }
190
191 $last_questionblock_id = $data["questionblock_id"];
192 }
193 }
194
195 $this->setData($table_data);
196 }
197
198 protected function fillRow(array $a_set): void
199 {
201 $ilCtrl = $this->ctrl;
202
203 $obligatory = "";
204
205 switch ($a_set["type"]) {
206 case "block":
207 if (!$this->read_only) {
208 // checkbox
209 $this->tpl->setCurrentBlock("checkable");
210 $this->tpl->setVariable("QUESTION_ID", $a_set["id"]);
211 $this->tpl->parseCurrentBlock();
212
213 // order
214 if ($a_set["position"]) {
215 $this->tpl->setCurrentBlock("order");
216 $this->tpl->setVariable("ORDER_NAME", "order[" . $a_set["id"] . "]");
217 $this->tpl->setVariable("ORDER_VALUE", $a_set["position"]);
218 $this->tpl->parseCurrentBlock();
219 }
220 }
221
222 $this->tpl->setVariable("TYPE", $lng->txt("questionblock"));
223 break;
224
225 case "question":
226 $this->tpl->setVariable("DESCRIPTION", $a_set["description"]);
227 $this->tpl->setVariable("TYPE", $a_set["question_type"]);
228 $this->tpl->setVariable("AUTHOR", $a_set["author"]);
229 $this->tpl->setVariable("POOL", $a_set["pool"] ?? "");
230
231 if ($a_set["heading"] ?? false) {
232 $this->tpl->setCurrentBlock("heading");
233 $this->tpl->setVariable("TXT_HEADING", $a_set["heading"]);
234 $this->tpl->parseCurrentBlock();
235 }
236
237 if ($a_set["block_id"]) {
238 $this->tpl->setVariable("TITLE_INDENT", " style=\"padding-left:30px\"");
239 }
240
241 if (!$this->read_only) {
242 // checkbox
243 $this->tpl->setCurrentBlock("checkable");
244 $this->tpl->setVariable("QUESTION_ID", $a_set["id"]);
245 $this->tpl->parseCurrentBlock();
246
247 if ($a_set["block_id"]) {
248 $this->tpl->setVariable("CHECKABLE_INDENT", " style=\"padding-left:30px\"");
249 }
250
251 // order
252 if ($a_set["position"] ?? false) {
253 $this->tpl->setCurrentBlock("order");
254 if (!$a_set["block_id"]) {
255 $this->tpl->setVariable("ORDER_NAME", "order[q_" . $a_set["id"] . "]");
256 } else {
257 $this->tpl->setVariable("ORDER_NAME", "block_order[" . $a_set["block_id"] . "][" . $a_set["id"] . "]");
258 }
259 $this->tpl->setVariable("ORDER_VALUE", $a_set["position"]);
260 $this->tpl->parseCurrentBlock();
261 if ($a_set["block_id"]) {
262 $this->tpl->setVariable("ORDER_INDENT", " style=\"padding-left:30px\"");
263 }
264 }
265
266 // obligatory
267 $checked = $a_set["obligatory"] ? " checked=\"checked\"" : "";
268 $obligatory = "<input type=\"checkbox\" name=\"obligatory[" .
269 $a_set["id"] . "]\" value=\"1\"" . $checked . " />";
270 } elseif ($a_set["obligatory"]) {
271 $obligatory = $this->ui->renderer()->render(
272 $this->ui->factory()->symbol()->icon()->custom(ilUtil::getImagePath("icon_checked.svg"), $lng->txt("question_obligatory"))
273 );
274 }
275 $this->tpl->setVariable("OBLIGATORY", $obligatory);
276 break;
277
278 case "heading":
279 if (!$this->read_only) {
280 // checkbox
281 $this->tpl->setCurrentBlock("checkable");
282 $this->tpl->setVariable("QUESTION_ID", $a_set["id"]);
283 $this->tpl->parseCurrentBlock();
284 if ($a_set["in_block"]) {
285 $this->tpl->setVariable("CHECKABLE_INDENT", " style=\"padding-left:30px\"");
286 $this->tpl->setVariable("TITLE_INDENT", " style=\"padding-left:30px\"");
287 }
288 }
289
290 $this->tpl->setVariable("TYPE", $lng->txt("heading"));
291 break;
292 }
293
294 if (!$this->read_only) {
295 $this->tpl->setCurrentBlock("actions");
296
297 $ilCtrl->setParameter($this->parent_obj, "q_id", $a_set["id"]);
298
299 $list = new ilAdvancedSelectionListGUI();
300 $list->setId($a_set["id"]);
301 $list->setListTitle($lng->txt("actions"));
302 if ($a_set["url"]) {
303 $list->addItem($lng->txt("edit"), "", $a_set["url"]);
304 }
305
306 if ($a_set["heading"] ?? false) {
307 $list->addItem(
308 $lng->txt("survey_edit_heading"),
309 "",
310 $ilCtrl->getLinkTarget($this->parent_obj, "editheading")
311 );
312
313 $list->addItem(
314 $lng->txt("survey_delete_heading"),
315 "",
316 $ilCtrl->getLinkTarget($this->parent_obj, "removeheading")
317 );
318 } elseif ($a_set["type"] === "question") {
319 $list->addItem(
320 $lng->txt("add_heading"),
321 "",
322 $ilCtrl->getLinkTarget($this->parent_obj, "addHeading")
323 );
324 }
325
326 $this->tpl->setVariable("ACTION", $list->getHTML());
327
328 $ilCtrl->setParameter($this->parent_obj, "q_id", "");
329
330 $this->tpl->parseCurrentBlock();
331
332 // #11186
333 if ($a_set["url"]) {
334 $this->tpl->setCurrentBlock("title_edit");
335 $this->tpl->setVariable("TITLE", $a_set["title"]);
336 $this->tpl->setVariable("URL_TITLE", $a_set["url"]);
337 } else {
338 $this->tpl->setCurrentBlock("title_static");
339 $this->tpl->setVariable("TITLE", $a_set["title"]);
340 }
341 } else {
342 $this->tpl->setCurrentBlock("title_static");
343 $this->tpl->setVariable("TITLE", $a_set["title"]);
344 }
345 $this->tpl->parseCurrentBlock();
346 }
347}
static lookupObjFi(int $a_qid)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _getQuestiontypes()
Get all available question types.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
fillRow(array $a_set)
Standard Version of Fill Row.
__construct(object $a_parent_obj, string $a_parent_cmd, ilObjSurvey $a_survey_obj, bool $a_read_only=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
addMultiCommand(string $a_cmd, string $a_text)
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setDefaultOrderField(string $a_defaultorderfield)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setData(array $a_data)
Set table data.
ilLanguage $lng
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc