ILIAS  release_8 Revision v8.24
class.ilSurveyPhrasesGUI.php
Go to the documentation of this file.
1<?php
2
20
29{
34 protected ilDBInterface $db;
35
37 protected ilLanguage $lng;
39 protected ilCtrl $ctrl;
40 protected ilTree $tree;
41 protected int $ref_id;
42
43 public function __construct(
45 ) {
46 global $DIC;
47
48 $this->rbacsystem = $DIC->rbac()->system();
49 $this->toolbar = $DIC->toolbar();
50 $this->db = $DIC->database();
51 $lng = $DIC->language();
52 $tpl = $DIC["tpl"];
53 $ilCtrl = $DIC->ctrl();
54 $tree = $DIC->repositoryTree();
55
56 $this->lng = $lng;
57 $this->tpl = $tpl;
58 $this->ctrl = $ilCtrl;
59 $this->object = new ilSurveyPhrases();
60 $this->tree = $tree;
61 $this->ref_id = $a_object->getRefId();
62 $this->ctrl->saveParameter($this, "p_id");
63 $this->request = $DIC->surveyQuestionPool()
64 ->internal()
65 ->gui()
66 ->editing()
67 ->request();
68 }
69
70 public function executeCommand(): string
71 {
72 $cmd = $this->ctrl->getCmd();
73 $next_class = $this->ctrl->getNextClass($this);
74
75 switch ($next_class) {
76 default:
77 $ret = $this->$cmd();
78 break;
79 }
80 return (string) $ret;
81 }
82
86 public function deletePhrase(): void
87 {
88 $checked_phrases = $this->request->getPhraseIds();
89 if (count($checked_phrases) > 0) {
90 $this->tpl->setOnScreenMessage('question', $this->lng->txt("qpl_confirm_delete_phrases"));
91 $this->deletePhrasesForm($checked_phrases);
92 } else {
93 $this->tpl->setOnScreenMessage('info', $this->lng->txt("qpl_delete_phrase_select_none"));
94 $this->phrases();
95 }
96 }
97
101 public function phrases(): void
102 {
104 $ilToolbar = $this->toolbar;
105
106 $this->ctrl->setParameter($this, "p_id", "");
107
108 if ($rbacsystem->checkAccess("write", $this->ref_id)) {
109 $button = ilLinkButton::getInstance();
110 $button->setCaption("phrase_new");
111 $button->setUrl($this->ctrl->getLinkTarget($this, "newPhrase"));
112 $ilToolbar->addButtonInstance($button);
113
114 $table_gui = new ilSurveyPhrasesTableGUI($this, 'phrases');
116 $data = array();
117 foreach ($phrases as $phrase_id => $phrase_array) {
118 $categories = ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
119 $data[] = array('phrase_id' => $phrase_id,
120 'phrase' => $phrase_array["title"],
121 'answers' => implode(", ", $categories)
122 );
123 }
124 $table_gui->setData($data);
125 $this->tpl->setContent($table_gui->getHTML());
126 } else {
127 $this->tpl->setOnScreenMessage('info', $this->lng->txt("cannot_manage_phrases"));
128 }
129 }
130
131 public function cancelDeletePhrase(): void
132 {
133 $this->ctrl->redirect($this, "phrases");
134 }
135
136 public function confirmDeletePhrase(): void
137 {
138 $phrases = $this->request->getPhraseIds();
139 $this->object->deletePhrases($phrases);
140 $this->tpl->setOnScreenMessage('success', $this->lng->txt("qpl_phrases_deleted"), true);
141 $this->ctrl->redirect($this, "phrases");
142 }
143
149 protected function getCategoriesForPhrase(
150 int $phrase_id
152 $ilDB = $this->db;
153
154 $categories = new SurveyCategories();
155 $result = $ilDB->queryF(
156 "SELECT svy_category.title, svy_category.neutral, svy_phrase_cat.sequence FROM svy_phrase_cat, svy_category WHERE svy_phrase_cat.phrase_fi = %s AND svy_phrase_cat.category_fi = svy_category.category_id ORDER BY svy_phrase_cat.sequence ASC",
157 array('integer'),
158 array($phrase_id)
159 );
160 if ($result->numRows() > 0) {
161 while ($data = $ilDB->fetchAssoc($result)) {
162 $categories->addCategory($data["title"], 0, $data["neutral"], null, $data['sequence']);
163 }
164 }
165 return $categories;
166 }
167
171 protected function getPhraseTitle(
172 int $phrase_id
173 ): string {
174 $ilDB = $this->db;
175
176 $result = $ilDB->queryF(
177 "SELECT svy_phrase.title FROM svy_phrase WHERE svy_phrase.phrase_id = %s",
178 array('integer'),
179 array($phrase_id)
180 );
181 if ($result->numRows() > 0) {
182 $row = $ilDB->fetchAssoc($result);
183 return $row['title'];
184 }
185 return "";
186 }
187
192 public function deletePhrasesForm(
193 array $checked_phrases
194 ): void {
195 $table_gui = new ilSurveyPhrasesTableGUI($this, 'phrases', true);
197 $data = array();
198 foreach ($checked_phrases as $phrase_id) {
199 $phrase_array = $phrases[$phrase_id];
200 $categories = ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
201 $data[] = array('phrase_id' => $phrase_id,
202 'phrase' => $phrase_array["title"],
203 'answers' => implode(", ", $categories)
204 );
205 }
206 $table_gui->setData($data);
207 $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
208 }
209
210 public function cancelEditPhrase(): void
211 {
212 $this->ctrl->redirect($this, 'phrases');
213 }
214
215 public function saveEditPhrase(): void
216 {
217 $result = $this->writePostData();
218 if ($result === 0) {
219 if ($this->request->getPhraseId()) {
220 $this->object->updatePhrase($this->request->getPhraseId());
221 $this->tpl->setOnScreenMessage('success', $this->lng->txt('phrase_saved'), true);
222 } else {
223 $this->object->savePhrase();
224 $this->tpl->setOnScreenMessage('success', $this->lng->txt('phrase_added'), true);
225 }
226 $this->ctrl->redirect($this, 'phrases');
227 }
228 }
229
234 public function writePostData(
235 bool $always = false
236 ): int {
237 $hasErrors = !$always && $this->phraseEditor(true);
238 if (!$hasErrors) {
239 $form = $this->form;
240 $this->object->title = $form->getInput("title");
241 $categories = new SurveyCategories();
242
243 $answers = $this->request->getAnswers();
244 foreach ($answers['answer'] as $key => $value) {
245 if (strlen($value)) {
246 $categories->addCategory($value, $answers['other'][$key] ?? 0, 0, null, $answers['scale'][$key] ?? null);
247 }
248 }
249 if ($this->request->getNeutral() !== "") {
250 $categories->addCategory(
251 $this->request->getNeutral(),
252 0,
253 1,
254 null,
255 $this->request->getNeutralScale() ? (int) $this->request->getNeutralScale() : null
256 );
257 }
258 $this->object->categories = $categories;
259 return 0;
260 }
261
262 return 1;
263 }
264
265 public function newPhrase(): void
266 {
267 $this->ctrl->redirect($this, 'phraseEditor');
268 }
269
270 public function editPhrase(): void
271 {
272 $ids = $this->request->getPhraseIds();
273 if (count($ids) === 0) {
274 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('no_phrase_selected'), true);
275 $this->ctrl->redirect($this, 'phrases');
276 }
277 if (count($ids) > 1) {
278 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_max_one_item'), true);
279 $this->ctrl->redirect($this, 'phrases');
280 }
281 $phrase_id = $ids[key($ids)];
282 if ($phrase_id) {
283 $this->ctrl->setParameter($this, 'p_id', $phrase_id);
284 }
285 $this->ctrl->redirect($this, 'phraseEditor');
286 }
287
288 public function phraseEditor(
289 bool $checkonly = false
290 ): bool {
291 $save = strcmp($this->ctrl->getCmd(), "saveEditPhrase") === 0;
292
293 $form = new ilPropertyFormGUI();
294 $form->setFormAction($this->ctrl->getFormAction($this, 'phraseEditor'));
295 $form->setTitle($this->lng->txt('edit_phrase'));
296 $form->setMultipart(false);
297 $form->setTableWidth("100%");
298 $form->setId("phraseeditor");
299
300 $phrase_id = $this->request->getPhraseId();
301
302 // title
303 $title = new ilTextInputGUI($this->lng->txt("title"), "title");
304 $title->setValue($this->getPhraseTitle($phrase_id));
305 $title->setRequired(true);
306 $form->addItem($title);
307
308 // Answers
309 $answers = new ilCategoryWizardInputGUI($this->lng->txt("answers"), "answers");
310 $answers->setRequired(true);
311 $answers->setAllowMove(true);
312 $answers->setShowWizard(false);
313 $answers->setShowSavePhrase(false);
314 $answers->setUseOtherAnswer(false);
315 $answers->setShowNeutralCategory(true);
316 $answers->setNeutralCategoryTitle($this->lng->txt('matrix_neutral_answer'));
317 $categories = $this->getCategoriesForPhrase($phrase_id);
318 if (!$categories->getCategoryCount()) {
319 $categories->addCategory("");
320 }
321 $answers->setValues($categories);
322 $answers->setDisabledScale(true);
323 $form->addItem($answers);
324
325 $form->addCommandButton("saveEditPhrase", $this->lng->txt("save"));
326 $form->addCommandButton("cancelEditPhrase", $this->lng->txt("cancel"));
327
328 $errors = false;
329
330 if ($save) {
331 $form->setValuesByPost();
332 $errors = !$form->checkInput();
333 $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and we need this if we don't want to have duplication of backslashes
334 if ($errors) {
335 $checkonly = false;
336 }
337 }
338
339 if (!$checkonly) {
340 $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
341 }
342 $this->form = $form;
343 return $errors;
344 }
345}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
return true
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
setFormAction(string $a_formaction)
setMultipart(bool $a_multipart)
setId(string $a_id)
language handling
Class ilObjSurveyQuestionPoolGUI.
This class represents a property form user interface.
setTableWidth(string $a_width)
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
checkAccess(string $a_operations, int $a_ref_id, string $a_type="")
checkAccess represents the main method of the RBAC-system in ILIAS3 developers want to use With this ...
Survey phrases GUI class The ilSurveyPhrases GUI class creates the GUI output for survey phrases (col...
writePostData(bool $always=false)
Evaluates a posted edit form and writes the form data in the question object.
deletePhrasesForm(array $checked_phrases)
Creates a confirmation form to delete personal phases from the database.
phraseEditor(bool $checkonly=false)
deletePhrase()
Creates a confirmation form to delete personal phases from the database.
ilGlobalTemplateInterface $tpl
getCategoriesForPhrase(int $phrase_id)
__construct(ilObjSurveyQuestionPoolGUI $a_object)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getAvailablePhrases(bool $useronly=false)
Gets the available phrases from the database.
static _getCategoriesForPhrase(int $phrase_id)
Gets the available categories for a given phrase.
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
$errors
Definition: imgupload.php:65
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $key
Consumer key/client ID value.
Definition: System.php:193
form( $class_path, string $cmd)