ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSurveyQuestionTableGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected \ILIAS\Survey\InternalGUIService $gui;
27 protected \ILIAS\DI\UIServices $ui;
29 protected bool $read_only;
30
31 public function __construct(
32 object $a_parent_obj,
33 string $a_parent_cmd,
34 ilObjSurvey $a_survey_obj,
35 bool $a_read_only = false
36 ) {
37 global $DIC;
38
39 $this->ctrl = $DIC->ctrl();
40 $this->lng = $DIC->language();
41 $ilCtrl = $DIC->ctrl();
42 $lng = $DIC->language();
43 $this->ui = $DIC->ui();
44
45 $this->object = $a_survey_obj;
46 $this->read_only = $a_read_only;
47
48 parent::__construct($a_parent_obj, $a_parent_cmd);
49
50 $this->setId("il_svy_qst");
51 $this->setLimit(9999);
52
53 $edit_manager = $DIC->survey()
54 ->internal()
55 ->domain()
56 ->edit();
57
58 $this->gui = $DIC->survey()
59 ->internal()
60 ->gui();
61 if (!$this->read_only) {
62 // command dropdown
63 if ((!($edit_manager->getQuestionClipboardMode($this->object->getRefId()) === "copy" && count($edit_manager->getQuestionClipboardQuestions($this->object->getRefId())) > 0))
64 && (count($edit_manager->getMoveSurveyQuestions()) === 0 ||
65 $edit_manager->getMoveSurveyId() !== $this->object->getId())) {
66 $this->addMultiCommand("createQuestionblock", $lng->txt("define_questionblock"));
67 $this->addMultiCommand("unfoldQuestionblock", $lng->txt("unfold"));
68 $this->addMultiCommand("removeQuestions", $lng->txt("remove_question"));
69 $this->addMultiCommand("moveQuestions", $lng->txt("move"));
70 $this->addMultiCommand("copyQuestionsToPool", $lng->txt("survey_copy_questions_to_pool"));
71 } else {
72 $this->addMultiCommand("insertQuestionsBefore", $lng->txt("insert_before"));
73 $this->addMultiCommand("insertQuestionsAfter", $lng->txt("insert_after"));
74 }
75
76 // right side
77 $this->addCommandButton("saveObligatory", $lng->txt("save_obligatory_state"));
78
79 $this->setSelectAllCheckbox("id[]");
80 $this->addColumn("", "");
81 $this->addColumn($lng->txt("survey_order"), "");
82 }
83
84 $this->addColumn($lng->txt("title"), "");
85 $this->addColumn($lng->txt("obligatory"), "");
86 $this->addColumn($lng->txt("description"), "");
87 $this->addColumn($lng->txt("type"), "");
88 $this->addColumn($lng->txt("author"), "");
89 $this->addColumn($lng->txt("survey_question_pool"), "");
90
91 if (!$this->read_only) {
92 $this->addColumn($lng->txt("actions"), "");
93 }
94
95 $this->setDefaultOrderField("order");
96 $this->setDefaultOrderDirection("asc");
97
98 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
99 $this->setRowTemplate("tpl.il_svy_svy_question_table.html", "components/ILIAS/Survey");
100
101 $this->setShowRowsSelector(true);
102
103 $this->importData();
104 }
105
106 protected function importData(): void
107 {
108 $ilCtrl = $this->ctrl;
109
110 $table_data = [];
111 $survey_questions = $this->object->getSurveyQuestions();
112 if (count($survey_questions) > 0) {
114
115 $questionpools = $this->object->getQuestionpoolTitles(true);
116
117 $table_data = array();
118 $last_questionblock_id = $position = $block_position = 0;
119 foreach ($survey_questions as $question_id => $data) {
120 // question block
121 if ($data["questionblock_id"] > 0 &&
122 $data["questionblock_id"] != $last_questionblock_id) {
123 $id = "qb_" . $data["questionblock_id"];
124
125 $table_data[$id] = array("id" => $id,
126 "type" => "block",
127 "title" => $data["questionblock_title"]);
128
129 if (!$this->read_only) {
130 // order
131 if (count($survey_questions) > 1) {
132 $position += 10;
133 $table_data[$id]["position"] = $position;
134 }
135
136 $ilCtrl->setParameter($this->parent_obj, "bl_id", $data["questionblock_id"]);
137 $table_data[$id]["url"] = $ilCtrl->getLinkTarget($this->parent_obj, "editQuestionblock");
138 $ilCtrl->setParameter($this->parent_obj, "bl_id", "");
139 }
140
141 $block_position = 0;
142 }
143
144 // question
145
146 $id = $data["question_id"];
147
148 $table_data[$id] = array("id" => $id,
149 "type" => "question",
150 "heading" => $data["heading"],
151 "title" => $data["title"],
152 "description" => $data["description"],
153 "author" => $data["author"],
154 "block_id" => $data["questionblock_id"],
155 "obligatory" => (bool) $data["obligatory"]);
156
157 // question type
158 foreach ($questiontypes as $trans => $typedata) {
159 if (strcmp($typedata["type_tag"], $data["type_tag"]) === 0) {
160 $table_data[$id]["question_type"] = $trans;
161 }
162 }
163
164 // pool title
165 if ($data["original_id"]) {
166 $original_fi = SurveyQuestion::lookupObjFi($data["original_id"]);
167 if (isset($questionpools[$original_fi])) {
168 $table_data[$id]["pool"] = $questionpools[$original_fi];
169 } else {
170 // #11186
171 $table_data[$id]["pool"] = "-";
172 }
173 }
174
175 if (!$this->read_only) {
176 if ($data["obj_fi"] > 0) {
177 // edit url
178 $q_gui = $data["type_tag"] . "GUI";
179 $ilCtrl->setParameterByClass($q_gui, "q_id", $id);
180 $table_data[$id]["url"] = $ilCtrl->getLinkTargetByClass($q_gui, "editQuestion") .
181 $ilCtrl->setParameterByClass($q_gui, "q_id", "");
182 }
183
184 // order
185 if (count($survey_questions) > 1) {
186 if (!$data["questionblock_id"]) {
187 $position += 10;
188 $table_data[$id]["position"] = $position;
189 } else {
190 $block_position += 10;
191 $table_data[$id]["position"] = $block_position;
192 }
193 }
194 }
195
196 $last_questionblock_id = $data["questionblock_id"];
197 }
198 }
199
200 $this->setData($table_data);
201 }
202
203 protected function fillRow(array $a_set): void
204 {
206 $ilCtrl = $this->ctrl;
207 $ui_factory = $this->gui->ui()->factory();
208 $ui_renderer = $this->gui->ui()->renderer();
209
210 $obligatory = "";
211
212 switch ($a_set["type"]) {
213 case "block":
214 if (!$this->read_only) {
215 // checkbox
216 $this->tpl->setCurrentBlock("checkable");
217 $this->tpl->setVariable("QUESTION_ID", $a_set["id"]);
218 $this->tpl->parseCurrentBlock();
219
220 // order
221 if ($a_set["position"]) {
222 $this->tpl->setCurrentBlock("order");
223 $this->tpl->setVariable("ORDER_NAME", "order[" . $a_set["id"] . "]");
224 $this->tpl->setVariable("ORDER_VALUE", $a_set["position"]);
225 $this->tpl->parseCurrentBlock();
226 }
227 }
228
229 $this->tpl->setVariable("TYPE", $lng->txt("questionblock"));
230 break;
231
232 case "question":
233 $this->tpl->setVariable("DESCRIPTION", $a_set["description"]);
234 $this->tpl->setVariable("TYPE", $a_set["question_type"]);
235 $this->tpl->setVariable("AUTHOR", $a_set["author"]);
236 $this->tpl->setVariable("POOL", $a_set["pool"] ?? "");
237
238 if ($a_set["heading"] ?? false) {
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 $this->tpl->setVariable("TITLE_INDENT", " style=\"padding-left:30px\"");
246 }
247
248 if (!$this->read_only) {
249 // checkbox
250 $this->tpl->setCurrentBlock("checkable");
251 $this->tpl->setVariable("QUESTION_ID", $a_set["id"]);
252 $this->tpl->parseCurrentBlock();
253
254 if ($a_set["block_id"]) {
255 $this->tpl->setVariable("CHECKABLE_INDENT", " style=\"padding-left:30px\"");
256 }
257
258 // order
259 if ($a_set["position"] ?? false) {
260 $this->tpl->setCurrentBlock("order");
261 if (!$a_set["block_id"]) {
262 $this->tpl->setVariable("ORDER_NAME", "order[q_" . $a_set["id"] . "]");
263 } else {
264 $this->tpl->setVariable("ORDER_NAME", "block_order[" . $a_set["block_id"] . "][" . $a_set["id"] . "]");
265 }
266 $this->tpl->setVariable("ORDER_VALUE", $a_set["position"]);
267 $this->tpl->parseCurrentBlock();
268 if ($a_set["block_id"]) {
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 } elseif ($a_set["obligatory"]) {
278 $obligatory = $this->ui->renderer()->render(
279 $this->ui->factory()->symbol()->icon()->custom(ilUtil::getImagePath("standard/icon_checked.svg"), $lng->txt("question_obligatory"))
280 );
281 }
282 $this->tpl->setVariable("OBLIGATORY", $obligatory);
283 break;
284
285 case "heading":
286 if (!$this->read_only) {
287 // checkbox
288 $this->tpl->setCurrentBlock("checkable");
289 $this->tpl->setVariable("QUESTION_ID", $a_set["id"]);
290 $this->tpl->parseCurrentBlock();
291 if ($a_set["in_block"]) {
292 $this->tpl->setVariable("CHECKABLE_INDENT", " style=\"padding-left:30px\"");
293 $this->tpl->setVariable("TITLE_INDENT", " style=\"padding-left:30px\"");
294 }
295 }
296
297 $this->tpl->setVariable("TYPE", $lng->txt("heading"));
298 break;
299 }
300
301 if (!$this->read_only) {
302 $this->tpl->setCurrentBlock("actions");
303
304 $ilCtrl->setParameter($this->parent_obj, "q_id", $a_set["id"]);
305
306 $actions = [];
307
308 if ($a_set["url"]) {
309 $actions[] = $ui_factory->link()->standard(
310 $lng->txt("edit"),
311 $a_set["url"]
312 );
313 }
314
315 if ($a_set["heading"] ?? false) {
316 $actions[] = $ui_factory->link()->standard(
317 $lng->txt("survey_edit_heading"),
318 $ilCtrl->getLinkTarget($this->parent_obj, "editheading")
319 );
320
321 $actions[] = $ui_factory->link()->standard(
322 $lng->txt("survey_delete_heading"),
323 $ilCtrl->getLinkTarget($this->parent_obj, "removeheading")
324 );
325 } elseif ($a_set["type"] === "question") {
326 $actions[] = $ui_factory->link()->standard(
327 $lng->txt("add_heading"),
328 $ilCtrl->getLinkTarget($this->parent_obj, "addHeading")
329 );
330 $actions[] = $ui_factory->link()->standard(
331 $lng->txt("copy"),
332 $ilCtrl->getLinkTarget($this->parent_obj, "copyQuestion")
333 );
334 }
335
336 $dd = $ui_factory->dropdown()->standard($actions);
337
338 $this->tpl->setVariable("ACTION", $ui_renderer->render($dd));
339
340 $ilCtrl->setParameter($this->parent_obj, "q_id", "");
341
342 $this->tpl->parseCurrentBlock();
343
344 // #11186
345 if ($a_set["url"]) {
346 $this->tpl->setCurrentBlock("title_edit");
347 $this->tpl->setVariable("TITLE", $a_set["title"]);
348 $this->tpl->setVariable("URL_TITLE", $a_set["url"]);
349 } else {
350 $this->tpl->setCurrentBlock("title_static");
351 $this->tpl->setVariable("TITLE", $a_set["title"]);
352 }
353 } else {
354 $this->tpl->setCurrentBlock("title_static");
355 $this->tpl->setVariable("TITLE", $a_set["title"]);
356 }
357 $this->tpl->parseCurrentBlock();
358 }
359}
static lookupObjFi(int $a_qid)
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.
ILIAS Survey InternalGUIService $gui
__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 $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26