ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
39 var $lng;
40 var $tpl;
41 var $ctrl;
42 var $ilias;
43 var $tree;
45
50 function __construct($a_object)
51 {
52 global $lng, $tpl, $ilCtrl, $ilias, $tree;
53
54 include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyPhrases.php";
55 $this->lng =& $lng;
56 $this->tpl =& $tpl;
57 $this->ctrl =& $ilCtrl;
58 $this->ilias =& $ilias;
59 $this->gui_object =& $a_object;
60 $this->object = new ilSurveyPhrases();
61 $this->tree =& $tree;
62 $this->ref_id = $a_object->ref_id;
63 $this->ctrl->saveParameter($this, "p_id");
64 }
65
69 public function &executeCommand()
70 {
71 $cmd = $this->ctrl->getCmd();
72 $next_class = $this->ctrl->getNextClass($this);
73
74 $cmd = $this->getCommand($cmd);
75 switch($next_class)
76 {
77 default:
78 $ret =& $this->$cmd();
79 break;
80 }
81 return $ret;
82 }
83
87 public function getCommand($cmd)
88 {
89 return $cmd;
90 }
91
95 public function deletePhrase()
96 {
98
99 $checked_phrases = $_POST['phrase'];
100 if (count($checked_phrases))
101 {
102 ilUtil::sendQuestion($this->lng->txt("qpl_confirm_delete_phrases"));
103 $this->deletePhrasesForm($checked_phrases);
104 return;
105 }
106 else
107 {
108 ilUtil::sendInfo($this->lng->txt("qpl_delete_phrase_select_none"));
109 $this->phrases();
110 return;
111 }
112 }
113
119 public function phrases()
120 {
121 global $rbacsystem, $ilToolbar;
122
123 $this->ctrl->setParameter($this, "p_id", "");
124
125 if ($rbacsystem->checkAccess("write", $this->ref_id))
126 {
127 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
128 $button = ilLinkButton::getInstance();
129 $button->setCaption("phrase_new");
130 $button->setUrl($this->ctrl->getLinkTarget($this, "newPhrase"));
131 $ilToolbar->addButtonInstance($button);
132
133 include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyPhrasesTableGUI.php";
134 $table_gui = new ilSurveyPhrasesTableGUI($this, 'phrases');
136 $data = array();
137 foreach ($phrases as $phrase_id => $phrase_array)
138 {
139 $categories =& ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
140 array_push($data, array('phrase_id' => $phrase_id, 'phrase' => $phrase_array["title"], 'answers' => join($categories, ", ")));
141 }
142 $table_gui->setData($data);
143 $this->tpl->setContent($table_gui->getHTML());
144 }
145 else
146 {
147 ilUtil::sendInfo($this->lng->txt("cannot_manage_phrases"));
148 }
149 }
150
154 public function cancelDeletePhrase()
155 {
156 $this->ctrl->redirect($this, "phrases");
157 }
158
162 public function confirmDeletePhrase()
163 {
164 $phrases = $_POST['phrase'];
165 $this->object->deletePhrases($phrases);
166 ilUtil::sendSuccess($this->lng->txt("qpl_phrases_deleted"), true);
167 $this->ctrl->redirect($this, "phrases");
168 }
169
170 protected function getCategoriesForPhrase($phrase_id)
171 {
172 global $ilDB;
173
174 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
175 $categories = new SurveyCategories();
176 $result = $ilDB->queryF("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",
177 array('integer'),
178 array($phrase_id)
179 );
180 if ($result->numRows() > 0)
181 {
182 while ($data = $ilDB->fetchAssoc($result))
183 {
184 $categories->addCategory($data["title"], 0, $data["neutral"], null, $data['sequence']);
185 }
186 }
187 return $categories;
188 }
189
190 protected function getPhraseTitle($phrase_id)
191 {
192 global $ilDB;
193
194 $result = $ilDB->queryF("SELECT svy_phrase.title FROM svy_phrase WHERE svy_phrase.phrase_id = %s",
195 array('integer'),
196 array($phrase_id)
197 );
198 if ($result->numRows() > 0)
199 {
200 $row = $ilDB->fetchAssoc($result);
201 return $row['title'];
202 }
203 return null;
204 }
205
211 public function deletePhrasesForm($checked_phrases)
212 {
213 include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyPhrasesTableGUI.php";
214 $table_gui = new ilSurveyPhrasesTableGUI($this, 'phrases', true);
216 $data = array();
217 foreach ($checked_phrases as $phrase_id)
218 {
219 $phrase_array = $phrases[$phrase_id];
220 $categories =& ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
221 array_push($data, array('phrase_id' => $phrase_id, 'phrase' => $phrase_array["title"], 'answers' => join($categories, ", ")));
222 }
223 $table_gui->setData($data);
224 $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
225 }
226
227 public function cancelEditPhrase()
228 {
229 $this->ctrl->redirect($this, 'phrases');
230 }
231
232 public function saveEditPhrase()
233 {
234 $result = $this->writePostData();
235 if ($result == 0)
236 {
237 if ($_GET['p_id'])
238 {
239 $this->object->updatePhrase($_GET['p_id']);
240 ilUtil::sendSuccess($this->lng->txt('phrase_saved'), true);
241 }
242 else
243 {
244 $this->object->savePhrase();
245 ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
246 }
247 $this->ctrl->redirect($this, 'phrases');
248 }
249 }
250
257 function writePostData($always = false)
258 {
259 global $ilDB;
260 $hasErrors = (!$always) ? $this->phraseEditor(true) : false;
261 if (!$hasErrors)
262 {
263 $this->object->title = $_POST["title"];
264 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
265 $categories = new SurveyCategories();
266 foreach ($_POST['answers']['answer'] as $key => $value)
267 {
268 if (strlen($value)) $categories->addCategory($value, $_POST['answers']['other'][$key], 0, null, $_POST['answers']['scale'][$key]);
269 }
270 if (strlen($_POST['answers']['neutral']))
271 {
272 $categories->addCategory($_POST['answers']['neutral'], 0, 1, null, $_POST['answers_neutral_scale']);
273 }
274 $this->object->categories = $categories;
275 return 0;
276 }
277 else
278 {
279 return 1;
280 }
281 }
282
283 public function newPhrase()
284 {
285 $this->ctrl->redirect($this, 'phraseEditor');
286 }
287
288 public function editPhrase()
289 {
290 if (!array_key_exists('phrase', $_POST))
291 {
292 ilUtil::sendFailure($this->lng->txt('no_phrase_selected'), true);
293 $this->ctrl->redirect($this, 'phrases');
294 }
295 if ((array_key_exists('phrase', $_POST)) && count($_POST['phrase']) > 1)
296 {
297 ilUtil::sendFailure($this->lng->txt('select_max_one_item'), true);
298 $this->ctrl->redirect($this, 'phrases');
299 }
300 $phrase_id = (array_key_exists('phrase', $_POST)) ? $_POST['phrase'][key($_POST['phrase'])] : null;
301 if ($phrase_id)
302 {
303 $this->ctrl->setParameter($this, 'p_id', $phrase_id);
304 }
305 $this->ctrl->redirect($this, 'phraseEditor');
306 }
307
308 public function phraseEditor($checkonly = FALSE)
309 {
310 $save = (strcmp($this->ctrl->getCmd(), "saveEditPhrase") == 0) ? TRUE : FALSE;
311
312 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
313 $form = new ilPropertyFormGUI();
314 $form->setFormAction($this->ctrl->getFormAction($this, 'phraseEditor'));
315 $form->setTitle($this->lng->txt('edit_phrase'));
316 $form->setMultipart(FALSE);
317 $form->setTableWidth("100%");
318 $form->setId("phraseeditor");
319
320 $phrase_id = $_GET['p_id'];
321
322 // title
323 $title = new ilTextInputGUI($this->lng->txt("title"), "title");
324 $title->setValue($this->getPhraseTitle($phrase_id));
325 $title->setRequired(TRUE);
326 $form->addItem($title);
327
328 // Answers
329 include_once "./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
330 $answers = new ilCategoryWizardInputGUI($this->lng->txt("answers"), "answers");
331 $answers->setRequired(true);
332 $answers->setAllowMove(true);
333 $answers->setShowWizard(false );
334 $answers->setShowSavePhrase(false);
335 $answers->setUseOtherAnswer(false);
336 $answers->setShowNeutralCategory(true);
337 $answers->setNeutralCategoryTitle($this->lng->txt('matrix_neutral_answer'));
338 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
339 $categories =& $this->getCategoriesForPhrase($phrase_id);
340 if (!$categories->getCategoryCount())
341 {
342 $categories->addCategory("");
343 }
344 $answers->setValues($categories);
345 $answers->setDisabledScale(true);
346 $form->addItem($answers);
347
348 $form->addCommandButton("saveEditPhrase", $this->lng->txt("save"));
349 $form->addCommandButton("cancelEditPhrase", $this->lng->txt("cancel"));
350
351 $errors = false;
352
353 if ($save)
354 {
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) $checkonly = false;
359 }
360
361 if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
362 return $errors;
363 }
364
365}
366?>
$result
$_GET["client_id"]
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
phraseEditor($checkonly=FALSE)
deletePhrase()
Creates a confirmation form to delete personal phases from the database.
writePostData($always=false)
Evaluates a posted edit form and writes the form data in the question object.
confirmDeletePhrase()
confirm delete phrases
& executeCommand()
execute command
Survey phrases class.
static & _getCategoriesForPhrase($phrase_id)
Gets the available categories for a given phrase.
static & _getAvailablePhrases($useronly=0)
Gets the available phrases from the database.
This class represents a text property in a property form.
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message 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.
$_POST['username']
Definition: cron.php:12
$data
global $ilCtrl
Definition: ilias.php:18
redirection script todo: (a better solution should control the processing via a xml file)
$cmd
Definition: sahs_server.php:35
global $ilDB
$errors