ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyTextQuestionGUI.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 
24 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
25 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
26 
39 {
40 
50  $id = -1
51  )
52 
53  {
54  $this->SurveyQuestionGUI();
55  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyTextQuestion.php";
56  $this->object = new SurveyTextQuestion();
57  if ($id >= 0)
58  {
59  $this->object->loadFromDb($id);
60  }
61  }
62 
69  function writePostData($always = false)
70  {
71  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
72  if (!$hasErrors)
73  {
74  $this->object->setTitle($_POST["title"]);
75  $this->object->label = $_POST['label'];
76  $this->object->setAuthor($_POST["author"]);
77  $this->object->setDescription($_POST["description"]);
78  $questiontext = $_POST["question"];
79  $this->object->setQuestiontext($questiontext);
80  $this->object->setObligatory(($_POST["obligatory"]) ? 1 : 0);
81 
82  $this->object->setMaxChars((strlen($_POST["maxchars"])) ? $_POST["maxchars"] : null);
83  $this->object->setTextWidth($_POST["textwidth"]);
84  $this->object->setTextHeight($_POST["textheight"]);
85 
86  return 0;
87  }
88  else
89  {
90  return 1;
91  }
92  }
93 
97  public function editQuestion()
98  {
99  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
100 
101  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
102  $form = new ilPropertyFormGUI();
103  $form->setFormAction($this->ctrl->getFormAction($this));
104  $form->setTitle($this->lng->txt($this->getQuestionType()));
105  $form->setMultipart(FALSE);
106  $form->setTableWidth("100%");
107  $form->setId("essay");
108 
109  // title
110  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
111  $title->setValue($this->object->getTitle());
112  $title->setRequired(TRUE);
113  $form->addItem($title);
114 
115  // label
116  $label = new ilTextInputGUI($this->lng->txt("label"), "label");
117  $label->setValue($this->object->label);
118  $label->setInfo($this->lng->txt("label_info"));
119  $label->setRequired(false);
120  $form->addItem($label);
121 
122  // author
123  $author = new ilTextInputGUI($this->lng->txt("author"), "author");
124  $author->setValue($this->object->getAuthor());
125  $author->setRequired(TRUE);
126  $form->addItem($author);
127 
128  // description
129  $description = new ilTextInputGUI($this->lng->txt("description"), "description");
130  $description->setValue($this->object->getDescription());
131  $description->setRequired(FALSE);
132  $form->addItem($description);
133 
134  // questiontext
135  $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
136  $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestiontext()));
137  $question->setRequired(TRUE);
138  $question->setRows(10);
139  $question->setCols(80);
140  $question->setUseRte(TRUE);
141  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
142  $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
143  $question->addPlugin("latex");
144  $question->addButton("latex");
145  $question->addButton("pastelatex");
146  $question->removePlugin("ibrowser");
147  $question->setRTESupport($this->object->getId(), "spl", "survey");
148  $form->addItem($question);
149 
150  // maximum number of characters
151  $maxchars = new ilNumberInputGUI($this->lng->txt("maxchars"), "maxchars");
152  $maxchars->setRequired(false);
153  $maxchars->setSize(5);
154  if ($this->object->getMaxChars() > 0)
155  {
156  $maxchars->setValue($this->object->getMaxChars());
157  }
158  $maxchars->setDecimals(0);
159  $form->addItem($maxchars);
160 
161  // textwidth
162  $textwidth = new ilNumberInputGUI($this->lng->txt("width"), "textwidth");
163  $textwidth->setRequired(true);
164  $textwidth->setSize(3);
165  $textwidth->setValue($this->object->getTextWidth());
166  $textwidth->setDecimals(0);
167  $textwidth->setMinValue(10);
168  $form->addItem($textwidth);
169 
170  // textheight
171  $textheight = new ilNumberInputGUI($this->lng->txt("height"), "textheight");
172  $textheight->setRequired(true);
173  $textheight->setSize(3);
174  $textheight->setValue($this->object->getTextHeight());
175  $textheight->setDecimals(0);
176  $textheight->setMinValue(1);
177  $form->addItem($textheight);
178 
179  // obligatory
180  $shuffle = new ilCheckboxInputGUI($this->lng->txt("obligatory"), "obligatory");
181  $shuffle->setValue(1);
182  $shuffle->setChecked($this->object->getObligatory());
183  $shuffle->setRequired(FALSE);
184  $form->addItem($shuffle);
185 
186  $form->addCommandButton("save", $this->lng->txt("save"));
187 
188  $errors = false;
189 
190  if ($save)
191  {
192  $form->setValuesByPost();
193  $errors = !$form->checkInput();
194  $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
195  if ($errors) $checkonly = false;
196  }
197 
198  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
199  return $errors;
200  }
201 
205  public function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
206  {
207  $template = new ilTemplate("tpl.il_svy_out_text.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
208  $template->setCurrentBlock("material_text");
209  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
210  $template->parseCurrentBlock();
211 
212  if ($this->object->getTextHeight() == 1)
213  {
214  $template->setCurrentBlock("textinput");
215  if (is_array($working_data))
216  {
217  if (strlen($working_data[0]["textanswer"]))
218  {
219  $template->setVariable("VALUE_ANSWER", " value=\"" . ilUtil::prepareFormOutput($working_data[0]["textanswer"]) . "\"");
220  }
221  }
222  $template->setVariable("QUESTION_ID", $this->object->getId());
223  $template->setVariable("WIDTH", $this->object->getTextWidth());
224  if ($this->object->getMaxChars())
225  {
226  $template->setVariable("MAXLENGTH", " maxlength=\"" . $this->object->getMaxChars() . "\"");
227  }
228  $template->parseCurrentBlock();
229  }
230  else
231  {
232  $template->setCurrentBlock("textarea");
233  if (is_array($working_data))
234  {
235  $template->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($working_data[0]["textanswer"]));
236  }
237  $template->setVariable("QUESTION_ID", $this->object->getId());
238  $template->setVariable("WIDTH", $this->object->getTextWidth());
239  $template->setVariable("HEIGHT", $this->object->getTextHeight());
240  $template->parseCurrentBlock();
241  }
242  $template->setCurrentBlock("question_data_text");
243  if ($show_questiontext)
244  {
245  $this->outQuestionText($template);
246  }
247  if ($question_title)
248  {
249  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
250  }
251  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
252  $template->setVariable("LABEL_QUESTION_ID", $this->object->getId());
253  if (strcmp($error_message, "") != 0)
254  {
255  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
256  }
257  if ($this->object->getMaxChars())
258  {
259  $template->setVariable("TEXT_MAXCHARS", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxChars()));
260  }
261  $template->parseCurrentBlock();
262  return $template->get();
263  }
264 
268  public function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
269  {
270  $template = new ilTemplate("tpl.il_svy_qpl_text_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
271  if ($show_questiontext)
272  {
273  $this->outQuestionText($template);
274  }
275  if ($question_title)
276  {
277  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
278  }
279  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
280  $template->setVariable("TEXTBOX_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("textbox.png")));
281  $template->setVariable("TEXTBOX", $this->lng->txt("textbox"));
282  $template->setVariable("TEXTBOX_WIDTH", $this->object->getTextWidth()*16);
283  $template->setVariable("TEXTBOX_HEIGHT", $this->object->getTextHeight()*16);
284  $template->setVariable("QUESTION_ID", $this->object->getId());
285  if ($this->object->getMaxChars())
286  {
287  $template->setVariable("TEXT_MAXCHARS", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxChars()));
288  }
289  return $template->get();
290  }
291 
299  function preview()
300  {
301  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", "Modules/SurveyQuestionPool");
302  $question_output = $this->getWorkingForm();
303  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
304  }
305 
306  function setQuestionTabs()
307  {
308  $this->setQuestionTabsForClass("surveytextquestiongui");
309  }
310 
319  function getCumulatedResultsDetails($survey_id, $counter)
320  {
321  if (count($this->cumulated) == 0)
322  {
323  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
324  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
325  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
326  }
327 
328  $output = "";
329  include_once "./classes/class.ilTemplate.php";
330  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
331 
332  $template->setCurrentBlock("detail_row");
333  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
334  $questiontext = $this->object->getQuestiontext();
335  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
336  $template->parseCurrentBlock();
337  $template->setCurrentBlock("detail_row");
338  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
339  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
340  $template->parseCurrentBlock();
341  $template->setCurrentBlock("detail_row");
342  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
343  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
344  $template->parseCurrentBlock();
345  $template->setCurrentBlock("detail_row");
346  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
347  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
348  $template->parseCurrentBlock();
349 
350  $template->setCurrentBlock("detail_row");
351  $template->setVariable("TEXT_OPTION", $this->lng->txt("given_answers"));
352  $textvalues = "";
353  if (is_array($this->cumulated["textvalues"]))
354  {
355  foreach ($this->cumulated["textvalues"] as $textvalue)
356  {
357  $textvalues .= "<li>" . preg_replace("/\n/", "<br>", $textvalue) . "</li>";
358  }
359  }
360  $textvalues = "<ul>$textvalues</ul>";
361  $template->setVariable("TEXT_OPTION_VALUE", $textvalues);
362  $template->parseCurrentBlock();
363 
364  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
365  return $template->get();
366  }
367 }
368 ?>