ILIAS  Release_4_2_x_branch Revision 61807
 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  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
100  $form = new ilPropertyFormGUI();
101  $form->setFormAction($this->ctrl->getFormAction($this));
102  $form->setTitle($this->lng->txt($this->getQuestionType()));
103  $form->setMultipart(FALSE);
104  $form->setTableWidth("100%");
105  $form->setId("essay");
106 
107  // title
108  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
109  $title->setValue($this->object->getTitle());
110  $title->setRequired(TRUE);
111  $form->addItem($title);
112 
113  // label
114  $label = new ilTextInputGUI($this->lng->txt("label"), "label");
115  $label->setValue($this->object->label);
116  $label->setInfo($this->lng->txt("label_info"));
117  $label->setRequired(false);
118  $form->addItem($label);
119 
120  // author
121  $author = new ilTextInputGUI($this->lng->txt("author"), "author");
122  $author->setValue($this->object->getAuthor());
123  $author->setRequired(TRUE);
124  $form->addItem($author);
125 
126  // description
127  $description = new ilTextInputGUI($this->lng->txt("description"), "description");
128  $description->setValue($this->object->getDescription());
129  $description->setRequired(FALSE);
130  $form->addItem($description);
131 
132  // questiontext
133  $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
134  $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestiontext()));
135  $question->setRequired(TRUE);
136  $question->setRows(10);
137  $question->setCols(80);
138  $question->setUseRte(TRUE);
139  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
140  $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
141  $question->addPlugin("latex");
142  $question->addButton("latex");
143  $question->addButton("pastelatex");
144  $question->removePlugin("ibrowser");
145  $question->setRTESupport($this->object->getId(), "spl", "survey", null, false, "3.4.7");
146  $form->addItem($question);
147 
148  // maximum number of characters
149  $maxchars = new ilNumberInputGUI($this->lng->txt("maxchars"), "maxchars");
150  $maxchars->setRequired(false);
151  $maxchars->setSize(5);
152  if ($this->object->getMaxChars() > 0)
153  {
154  $maxchars->setValue($this->object->getMaxChars());
155  }
156  $maxchars->setDecimals(0);
157  $form->addItem($maxchars);
158 
159  // textwidth
160  $textwidth = new ilNumberInputGUI($this->lng->txt("width"), "textwidth");
161  $textwidth->setRequired(true);
162  $textwidth->setSize(3);
163  $textwidth->setValue($this->object->getTextWidth());
164  $textwidth->setDecimals(0);
165  $textwidth->setMinValue(10);
166  $form->addItem($textwidth);
167 
168  // textheight
169  $textheight = new ilNumberInputGUI($this->lng->txt("height"), "textheight");
170  $textheight->setRequired(true);
171  $textheight->setSize(3);
172  $textheight->setValue($this->object->getTextHeight());
173  $textheight->setDecimals(0);
174  $textheight->setMinValue(1);
175  $form->addItem($textheight);
176 
177  // obligatory
178  $shuffle = new ilCheckboxInputGUI($this->lng->txt("obligatory"), "obligatory");
179  $shuffle->setValue(1);
180  $shuffle->setChecked($this->object->getObligatory());
181  $shuffle->setRequired(FALSE);
182  $form->addItem($shuffle);
183 
184  $this->addCommandButtons($form);
185 
186  $errors = false;
187 
188  if ($this->isSaveCommand())
189  {
190  $form->setValuesByPost();
191  $errors = !$form->checkInput();
192  $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
193  if ($errors) $checkonly = false;
194  }
195 
196  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
197  return $errors;
198  }
199 
203  public function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
204  {
205  $template = new ilTemplate("tpl.il_svy_out_text.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
206  $template->setCurrentBlock("material_text");
207  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
208  $template->parseCurrentBlock();
209 
210  if ($this->object->getTextHeight() == 1)
211  {
212  $template->setCurrentBlock("textinput");
213  if (is_array($working_data))
214  {
215  if (strlen($working_data[0]["textanswer"]))
216  {
217  $template->setVariable("VALUE_ANSWER", " value=\"" . ilUtil::prepareFormOutput($working_data[0]["textanswer"]) . "\"");
218  }
219  }
220  $template->setVariable("QUESTION_ID", $this->object->getId());
221  $template->setVariable("WIDTH", $this->object->getTextWidth());
222  if ($this->object->getMaxChars())
223  {
224  $template->setVariable("MAXLENGTH", " maxlength=\"" . $this->object->getMaxChars() . "\"");
225  }
226  $template->parseCurrentBlock();
227  }
228  else
229  {
230  $template->setCurrentBlock("textarea");
231  if (is_array($working_data))
232  {
233  $template->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($working_data[0]["textanswer"]));
234  }
235  $template->setVariable("QUESTION_ID", $this->object->getId());
236  $template->setVariable("WIDTH", $this->object->getTextWidth());
237  $template->setVariable("HEIGHT", $this->object->getTextHeight());
238  $template->parseCurrentBlock();
239  }
240  $template->setCurrentBlock("question_data_text");
241  if ($show_questiontext)
242  {
243  $this->outQuestionText($template);
244  }
245  if ($question_title)
246  {
247  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
248  }
249  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
250  $template->setVariable("LABEL_QUESTION_ID", $this->object->getId());
251  if (strcmp($error_message, "") != 0)
252  {
253  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
254  }
255  if ($this->object->getMaxChars())
256  {
257  $template->setVariable("TEXT_MAXCHARS", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxChars()));
258  }
259  $template->parseCurrentBlock();
260  return $template->get();
261  }
262 
266  public function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
267  {
268  $template = new ilTemplate("tpl.il_svy_qpl_text_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
269  if ($show_questiontext)
270  {
271  $this->outQuestionText($template);
272  }
273  if ($question_title)
274  {
275  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
276  }
277  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
278  $template->setVariable("TEXTBOX_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("textbox.png")));
279  $template->setVariable("TEXTBOX", $this->lng->txt("textbox"));
280  $template->setVariable("TEXTBOX_WIDTH", $this->object->getTextWidth()*16);
281  $template->setVariable("TEXTBOX_HEIGHT", $this->object->getTextHeight()*16);
282  $template->setVariable("QUESTION_ID", $this->object->getId());
283  if ($this->object->getMaxChars())
284  {
285  $template->setVariable("TEXT_MAXCHARS", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxChars()));
286  }
287  return $template->get();
288  }
289 
290  function setQuestionTabs()
291  {
292  $this->setQuestionTabsForClass("surveytextquestiongui");
293  }
294 
303  function getCumulatedResultsDetails($survey_id, $counter)
304  {
305  if (count($this->cumulated) == 0)
306  {
307  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
308  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
309  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
310  }
311 
312  $output = "";
313  include_once "./classes/class.ilTemplate.php";
314  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
315 
316  $template->setCurrentBlock("detail_row");
317  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
318  $questiontext = $this->object->getQuestiontext();
319  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
320  $template->parseCurrentBlock();
321  $template->setCurrentBlock("detail_row");
322  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
323  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
324  $template->parseCurrentBlock();
325  $template->setCurrentBlock("detail_row");
326  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
327  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
328  $template->parseCurrentBlock();
329  $template->setCurrentBlock("detail_row");
330  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
331  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
332  $template->parseCurrentBlock();
333 
334  $template->setCurrentBlock("detail_row");
335  $template->setVariable("TEXT_OPTION", $this->lng->txt("given_answers"));
336  $textvalues = "";
337  if (is_array($this->cumulated["textvalues"]))
338  {
339  foreach ($this->cumulated["textvalues"] as $textvalue)
340  {
341  $textvalues .= "<li>" . preg_replace("/\n/", "<br>", $textvalue) . "</li>";
342  }
343  }
344  $textvalues = "<ul>$textvalues</ul>";
345  $template->setVariable("TEXT_OPTION_VALUE", $textvalues);
346  $template->parseCurrentBlock();
347 
348  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
349  return $template->get();
350  }
351 }
352 ?>