ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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;
53  public $gui_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  $this->lng = $lng;
77  $this->tpl = $tpl;
78  $this->ctrl = $ilCtrl;
79  $this->gui_object = $a_object;
80  $this->object = new ilSurveyPhrases();
81  $this->tree = $tree;
82  $this->ref_id = $a_object->ref_id;
83  $this->ctrl->saveParameter($this, "p_id");
84  }
85 
89  public function executeCommand()
90  {
91  $cmd = $this->ctrl->getCmd();
92  $next_class = $this->ctrl->getNextClass($this);
93 
94  $cmd = $this->getCommand($cmd);
95  switch ($next_class) {
96  default:
97  $ret = &$this->$cmd();
98  break;
99  }
100  return $ret;
101  }
102 
106  public function getCommand($cmd)
107  {
108  return $cmd;
109  }
110 
114  public function deletePhrase()
115  {
117 
118  $checked_phrases = $_POST['phrase'];
119  if (count($checked_phrases)) {
120  ilUtil::sendQuestion($this->lng->txt("qpl_confirm_delete_phrases"));
121  $this->deletePhrasesForm($checked_phrases);
122  return;
123  } else {
124  ilUtil::sendInfo($this->lng->txt("qpl_delete_phrase_select_none"));
125  $this->phrases();
126  return;
127  }
128  }
129 
135  public function phrases()
136  {
138  $ilToolbar = $this->toolbar;
139 
140  $this->ctrl->setParameter($this, "p_id", "");
141 
142  if ($rbacsystem->checkAccess("write", $this->ref_id)) {
143  $button = ilLinkButton::getInstance();
144  $button->setCaption("phrase_new");
145  $button->setUrl($this->ctrl->getLinkTarget($this, "newPhrase"));
146  $ilToolbar->addButtonInstance($button);
147 
148  $table_gui = new ilSurveyPhrasesTableGUI($this, 'phrases');
150  $data = array();
151  foreach ($phrases as $phrase_id => $phrase_array) {
152  $categories = &ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
153  array_push($data, array('phrase_id' => $phrase_id, 'phrase' => $phrase_array["title"], 'answers' => join(", ", $categories)));
154  }
155  $table_gui->setData($data);
156  $this->tpl->setContent($table_gui->getHTML());
157  } else {
158  ilUtil::sendInfo($this->lng->txt("cannot_manage_phrases"));
159  }
160  }
161 
165  public function cancelDeletePhrase()
166  {
167  $this->ctrl->redirect($this, "phrases");
168  }
169 
173  public function confirmDeletePhrase()
174  {
175  $phrases = $_POST['phrase'];
176  $this->object->deletePhrases($phrases);
177  ilUtil::sendSuccess($this->lng->txt("qpl_phrases_deleted"), true);
178  $this->ctrl->redirect($this, "phrases");
179  }
180 
181  protected function getCategoriesForPhrase($phrase_id)
182  {
183  $ilDB = $this->db;
184 
185  $categories = new SurveyCategories();
186  $result = $ilDB->queryF(
187  "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",
188  array('integer'),
189  array($phrase_id)
190  );
191  if ($result->numRows() > 0) {
192  while ($data = $ilDB->fetchAssoc($result)) {
193  $categories->addCategory($data["title"], 0, $data["neutral"], null, $data['sequence']);
194  }
195  }
196  return $categories;
197  }
198 
199  protected function getPhraseTitle($phrase_id)
200  {
201  $ilDB = $this->db;
202 
203  $result = $ilDB->queryF(
204  "SELECT svy_phrase.title FROM svy_phrase WHERE svy_phrase.phrase_id = %s",
205  array('integer'),
206  array($phrase_id)
207  );
208  if ($result->numRows() > 0) {
209  $row = $ilDB->fetchAssoc($result);
210  return $row['title'];
211  }
212  return null;
213  }
214 
220  public function deletePhrasesForm($checked_phrases)
221  {
222  $table_gui = new ilSurveyPhrasesTableGUI($this, 'phrases', true);
224  $data = array();
225  foreach ($checked_phrases as $phrase_id) {
226  $phrase_array = $phrases[$phrase_id];
227  $categories = &ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
228  array_push($data, array('phrase_id' => $phrase_id, 'phrase' => $phrase_array["title"], 'answers' => join(", ", $categories)));
229  }
230  $table_gui->setData($data);
231  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
232  }
233 
234  public function cancelEditPhrase()
235  {
236  $this->ctrl->redirect($this, 'phrases');
237  }
238 
239  public function saveEditPhrase()
240  {
241  $result = $this->writePostData();
242  if ($result == 0) {
243  if ($_GET['p_id']) {
244  $this->object->updatePhrase($_GET['p_id']);
245  ilUtil::sendSuccess($this->lng->txt('phrase_saved'), true);
246  } else {
247  $this->object->savePhrase();
248  ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
249  }
250  $this->ctrl->redirect($this, 'phrases');
251  }
252  }
253 
260  public function writePostData($always = false)
261  {
262  $ilDB = $this->db;
263  $hasErrors = (!$always) ? $this->phraseEditor(true) : false;
264  if (!$hasErrors) {
265  $this->object->title = $_POST["title"];
266  $categories = new SurveyCategories();
267  foreach ($_POST['answers']['answer'] as $key => $value) {
268  if (strlen($value)) {
269  $categories->addCategory($value, $_POST['answers']['other'][$key], 0, null, $_POST['answers']['scale'][$key]);
270  }
271  }
272  if (strlen($_POST['answers']['neutral'])) {
273  $categories->addCategory($_POST['answers']['neutral'], 0, 1, null, $_POST['answers_neutral_scale']);
274  }
275  $this->object->categories = $categories;
276  return 0;
277  } else {
278  return 1;
279  }
280  }
281 
282  public function newPhrase()
283  {
284  $this->ctrl->redirect($this, 'phraseEditor');
285  }
286 
287  public function editPhrase()
288  {
289  if (!array_key_exists('phrase', $_POST)) {
290  ilUtil::sendFailure($this->lng->txt('no_phrase_selected'), true);
291  $this->ctrl->redirect($this, 'phrases');
292  }
293  if ((array_key_exists('phrase', $_POST)) && count($_POST['phrase']) > 1) {
294  ilUtil::sendFailure($this->lng->txt('select_max_one_item'), true);
295  $this->ctrl->redirect($this, 'phrases');
296  }
297  $phrase_id = (array_key_exists('phrase', $_POST)) ? $_POST['phrase'][key($_POST['phrase'])] : null;
298  if ($phrase_id) {
299  $this->ctrl->setParameter($this, 'p_id', $phrase_id);
300  }
301  $this->ctrl->redirect($this, 'phraseEditor');
302  }
303 
304  public function phraseEditor($checkonly = false)
305  {
306  $save = (strcmp($this->ctrl->getCmd(), "saveEditPhrase") == 0) ? true : false;
307 
308  $form = new ilPropertyFormGUI();
309  $form->setFormAction($this->ctrl->getFormAction($this, 'phraseEditor'));
310  $form->setTitle($this->lng->txt('edit_phrase'));
311  $form->setMultipart(false);
312  $form->setTableWidth("100%");
313  $form->setId("phraseeditor");
314 
315  $phrase_id = $_GET['p_id'];
316 
317  // title
318  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
319  $title->setValue($this->getPhraseTitle($phrase_id));
320  $title->setRequired(true);
321  $form->addItem($title);
322 
323  // Answers
324  $answers = new ilCategoryWizardInputGUI($this->lng->txt("answers"), "answers");
325  $answers->setRequired(true);
326  $answers->setAllowMove(true);
327  $answers->setShowWizard(false);
328  $answers->setShowSavePhrase(false);
329  $answers->setUseOtherAnswer(false);
330  $answers->setShowNeutralCategory(true);
331  $answers->setNeutralCategoryTitle($this->lng->txt('matrix_neutral_answer'));
332  $categories = &$this->getCategoriesForPhrase($phrase_id);
333  if (!$categories->getCategoryCount()) {
334  $categories->addCategory("");
335  }
336  $answers->setValues($categories);
337  $answers->setDisabledScale(true);
338  $form->addItem($answers);
339 
340  $form->addCommandButton("saveEditPhrase", $this->lng->txt("save"));
341  $form->addCommandButton("cancelEditPhrase", $this->lng->txt("cancel"));
342 
343  $errors = false;
344 
345  if ($save) {
346  $form->setValuesByPost();
347  $errors = !$form->checkInput();
348  $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
349  if ($errors) {
350  $checkonly = false;
351  }
352  }
353 
354  if (!$checkonly) {
355  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
356  }
357  return $errors;
358  }
359 }
confirmDeletePhrase()
confirm delete phrases
phraseEditor($checkonly=false)
static _getCategoriesForPhrase($phrase_id)
Gets the available categories for a given phrase.
$data
Definition: storeScorm.php:23
$result
$errors
Definition: imgupload.php:49
This class represents a property form user interface.
$_GET["client_id"]
Survey phrases GUI class.
executeCommand()
execute command
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
writePostData($always=false)
Evaluates a posted edit form and writes the form data in the question object.
Class SurveyCategories.
global $DIC
Definition: goto.php:24
__construct($a_object)
ilSurveyPhrasesGUI constructor
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
This class represents a survey question category wizard property in a property form.
deletePhrasesForm($checked_phrases)
Creates a confirmation form to delete personal phases from the database.
cancelDeletePhrase()
cancel delete phrases
global $ilDB
$ret
Definition: parser.php:6
static _getAvailablePhrases($useronly=0)
Gets the available phrases from the database.
phrases()
Displays a form to manage the user created phrases.
getCommand($cmd)
Retrieves the ilCtrl command.
$_POST["username"]
setRequired($a_required)
Set Required.
Survey phrases class.
deletePhrase()
Creates a confirmation form to delete personal phases from the database.