ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilSurveyPhrasesGUI.php
Go to the documentation of this file.
1<?php
2 /*
3 +----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +----------------------------------------------------------------------------+
22*/
23
36{
40 protected $rbacsystem;
41
45 protected $toolbar;
46
50 protected $db;
51
52 public $object;
54 public $lng;
55 public $tpl;
56 public $ctrl;
57 public $tree;
58 public $ref_id;
59
64 public function __construct($a_object)
65 {
66 global $DIC;
67
68 $this->rbacsystem = $DIC->rbac()->system();
69 $this->toolbar = $DIC->toolbar();
70 $this->db = $DIC->database();
71 $lng = $DIC->language();
72 $tpl = $DIC["tpl"];
73 $ilCtrl = $DIC->ctrl();
74 $tree = $DIC->repositoryTree();
75
76 include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyPhrases.php";
77 $this->lng = $lng;
78 $this->tpl = $tpl;
79 $this->ctrl = $ilCtrl;
80 $this->gui_object = $a_object;
81 $this->object = new ilSurveyPhrases();
82 $this->tree = $tree;
83 $this->ref_id = $a_object->ref_id;
84 $this->ctrl->saveParameter($this, "p_id");
85 }
86
90 public function executeCommand()
91 {
92 $cmd = $this->ctrl->getCmd();
93 $next_class = $this->ctrl->getNextClass($this);
94
95 $cmd = $this->getCommand($cmd);
96 switch ($next_class) {
97 default:
98 $ret = &$this->$cmd();
99 break;
100 }
101 return $ret;
102 }
103
107 public function getCommand($cmd)
108 {
109 return $cmd;
110 }
111
115 public function deletePhrase()
116 {
118
119 $checked_phrases = $_POST['phrase'];
120 if (count($checked_phrases)) {
121 ilUtil::sendQuestion($this->lng->txt("qpl_confirm_delete_phrases"));
122 $this->deletePhrasesForm($checked_phrases);
123 return;
124 } else {
125 ilUtil::sendInfo($this->lng->txt("qpl_delete_phrase_select_none"));
126 $this->phrases();
127 return;
128 }
129 }
130
136 public function phrases()
137 {
139 $ilToolbar = $this->toolbar;
140
141 $this->ctrl->setParameter($this, "p_id", "");
142
143 if ($rbacsystem->checkAccess("write", $this->ref_id)) {
144 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
145 $button = ilLinkButton::getInstance();
146 $button->setCaption("phrase_new");
147 $button->setUrl($this->ctrl->getLinkTarget($this, "newPhrase"));
148 $ilToolbar->addButtonInstance($button);
149
150 include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyPhrasesTableGUI.php";
151 $table_gui = new ilSurveyPhrasesTableGUI($this, 'phrases');
153 $data = array();
154 foreach ($phrases as $phrase_id => $phrase_array) {
155 $categories = &ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
156 array_push($data, array('phrase_id' => $phrase_id, 'phrase' => $phrase_array["title"], 'answers' => join(", ", $categories)));
157 }
158 $table_gui->setData($data);
159 $this->tpl->setContent($table_gui->getHTML());
160 } else {
161 ilUtil::sendInfo($this->lng->txt("cannot_manage_phrases"));
162 }
163 }
164
168 public function cancelDeletePhrase()
169 {
170 $this->ctrl->redirect($this, "phrases");
171 }
172
176 public function confirmDeletePhrase()
177 {
178 $phrases = $_POST['phrase'];
179 $this->object->deletePhrases($phrases);
180 ilUtil::sendSuccess($this->lng->txt("qpl_phrases_deleted"), true);
181 $this->ctrl->redirect($this, "phrases");
182 }
183
184 protected function getCategoriesForPhrase($phrase_id)
185 {
187
188 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
189 $categories = new SurveyCategories();
190 $result = $ilDB->queryF(
191 "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",
192 array('integer'),
193 array($phrase_id)
194 );
195 if ($result->numRows() > 0) {
196 while ($data = $ilDB->fetchAssoc($result)) {
197 $categories->addCategory($data["title"], 0, $data["neutral"], null, $data['sequence']);
198 }
199 }
200 return $categories;
201 }
202
203 protected function getPhraseTitle($phrase_id)
204 {
206
207 $result = $ilDB->queryF(
208 "SELECT svy_phrase.title FROM svy_phrase WHERE svy_phrase.phrase_id = %s",
209 array('integer'),
210 array($phrase_id)
211 );
212 if ($result->numRows() > 0) {
213 $row = $ilDB->fetchAssoc($result);
214 return $row['title'];
215 }
216 return null;
217 }
218
224 public function deletePhrasesForm($checked_phrases)
225 {
226 include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyPhrasesTableGUI.php";
227 $table_gui = new ilSurveyPhrasesTableGUI($this, 'phrases', true);
229 $data = array();
230 foreach ($checked_phrases as $phrase_id) {
231 $phrase_array = $phrases[$phrase_id];
232 $categories = &ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
233 array_push($data, array('phrase_id' => $phrase_id, 'phrase' => $phrase_array["title"], 'answers' => join(", ", $categories)));
234 }
235 $table_gui->setData($data);
236 $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
237 }
238
239 public function cancelEditPhrase()
240 {
241 $this->ctrl->redirect($this, 'phrases');
242 }
243
244 public function saveEditPhrase()
245 {
246 $result = $this->writePostData();
247 if ($result == 0) {
248 if ($_GET['p_id']) {
249 $this->object->updatePhrase($_GET['p_id']);
250 ilUtil::sendSuccess($this->lng->txt('phrase_saved'), true);
251 } else {
252 $this->object->savePhrase();
253 ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
254 }
255 $this->ctrl->redirect($this, 'phrases');
256 }
257 }
258
265 public function writePostData($always = false)
266 {
268 $hasErrors = (!$always) ? $this->phraseEditor(true) : false;
269 if (!$hasErrors) {
270 $this->object->title = $_POST["title"];
271 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
272 $categories = new SurveyCategories();
273 foreach ($_POST['answers']['answer'] as $key => $value) {
274 if (strlen($value)) {
275 $categories->addCategory($value, $_POST['answers']['other'][$key], 0, null, $_POST['answers']['scale'][$key]);
276 }
277 }
278 if (strlen($_POST['answers']['neutral'])) {
279 $categories->addCategory($_POST['answers']['neutral'], 0, 1, null, $_POST['answers_neutral_scale']);
280 }
281 $this->object->categories = $categories;
282 return 0;
283 } else {
284 return 1;
285 }
286 }
287
288 public function newPhrase()
289 {
290 $this->ctrl->redirect($this, 'phraseEditor');
291 }
292
293 public function editPhrase()
294 {
295 if (!array_key_exists('phrase', $_POST)) {
296 ilUtil::sendFailure($this->lng->txt('no_phrase_selected'), true);
297 $this->ctrl->redirect($this, 'phrases');
298 }
299 if ((array_key_exists('phrase', $_POST)) && count($_POST['phrase']) > 1) {
300 ilUtil::sendFailure($this->lng->txt('select_max_one_item'), true);
301 $this->ctrl->redirect($this, 'phrases');
302 }
303 $phrase_id = (array_key_exists('phrase', $_POST)) ? $_POST['phrase'][key($_POST['phrase'])] : null;
304 if ($phrase_id) {
305 $this->ctrl->setParameter($this, 'p_id', $phrase_id);
306 }
307 $this->ctrl->redirect($this, 'phraseEditor');
308 }
309
310 public function phraseEditor($checkonly = false)
311 {
312 $save = (strcmp($this->ctrl->getCmd(), "saveEditPhrase") == 0) ? true : false;
313
314 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
315 $form = new ilPropertyFormGUI();
316 $form->setFormAction($this->ctrl->getFormAction($this, 'phraseEditor'));
317 $form->setTitle($this->lng->txt('edit_phrase'));
318 $form->setMultipart(false);
319 $form->setTableWidth("100%");
320 $form->setId("phraseeditor");
321
322 $phrase_id = $_GET['p_id'];
323
324 // title
325 $title = new ilTextInputGUI($this->lng->txt("title"), "title");
326 $title->setValue($this->getPhraseTitle($phrase_id));
327 $title->setRequired(true);
328 $form->addItem($title);
329
330 // Answers
331 include_once "./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
332 $answers = new ilCategoryWizardInputGUI($this->lng->txt("answers"), "answers");
333 $answers->setRequired(true);
334 $answers->setAllowMove(true);
335 $answers->setShowWizard(false);
336 $answers->setShowSavePhrase(false);
337 $answers->setUseOtherAnswer(false);
338 $answers->setShowNeutralCategory(true);
339 $answers->setNeutralCategoryTitle($this->lng->txt('matrix_neutral_answer'));
340 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
341 $categories = &$this->getCategoriesForPhrase($phrase_id);
342 if (!$categories->getCategoryCount()) {
343 $categories->addCategory("");
344 }
345 $answers->setValues($categories);
346 $answers->setDisabledScale(true);
347 $form->addItem($answers);
348
349 $form->addCommandButton("saveEditPhrase", $this->lng->txt("save"));
350 $form->addCommandButton("cancelEditPhrase", $this->lng->txt("cancel"));
351
352 $errors = false;
353
354 if ($save) {
355 $form->setValuesByPost();
356 $errors = !$form->checkInput();
357 $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
358 if ($errors) {
359 $checkonly = false;
360 }
361 }
362
363 if (!$checkonly) {
364 $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
365 }
366 return $errors;
367 }
368}
$result
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Class SurveyCategories.
This class represents a survey question category wizard property in a property form.
static getInstance()
Factory.
This class represents a property form user interface.
Survey phrases GUI class.
getCommand($cmd)
Retrieves the ilCtrl command.
phrases()
Displays a form to manage the user created phrases.
__construct($a_object)
ilSurveyPhrasesGUI constructor
deletePhrasesForm($checked_phrases)
Creates a confirmation form to delete personal phases from the database.
cancelDeletePhrase()
cancel delete phrases
executeCommand()
execute command
deletePhrase()
Creates a confirmation form to delete personal phases from the database.
phraseEditor($checkonly=false)
writePostData($always=false)
Evaluates a posted edit form and writes the form data in the question object.
confirmDeletePhrase()
confirm delete phrases
Survey phrases class.
static _getAvailablePhrases($useronly=0)
Gets the available phrases from the database.
static _getCategoriesForPhrase($phrase_id)
Gets the available categories for a given phrase.
This class represents a text property in a property form.
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$key
Definition: croninfo.php:18
global $ilCtrl
Definition: ilias.php:18
$errors
Definition: index.php:6
$row
$ret
Definition: parser.php:6
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
global $ilDB
$data
Definition: bench.php:6