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