ILIAS  release_4-3 Revision
 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->setRTESupport($this->object->getId(), "spl", "survey", null, false, "3.4.7");
145  $form->addItem($question);
146 
147  // maximum number of characters
148  $maxchars = new ilNumberInputGUI($this->lng->txt("maxchars"), "maxchars");
149  $maxchars->setRequired(false);
150  $maxchars->setSize(5);
151  if ($this->object->getMaxChars() > 0)
152  {
153  $maxchars->setValue($this->object->getMaxChars());
154  }
155  $maxchars->setDecimals(0);
156  $form->addItem($maxchars);
157 
158  // textwidth
159  $textwidth = new ilNumberInputGUI($this->lng->txt("width"), "textwidth");
160  $textwidth->setRequired(true);
161  $textwidth->setSize(3);
162  $textwidth->setValue($this->object->getTextWidth());
163  $textwidth->setDecimals(0);
164  $textwidth->setMinValue(10);
165  $form->addItem($textwidth);
166 
167  // textheight
168  $textheight = new ilNumberInputGUI($this->lng->txt("height"), "textheight");
169  $textheight->setRequired(true);
170  $textheight->setSize(3);
171  $textheight->setValue($this->object->getTextHeight());
172  $textheight->setDecimals(0);
173  $textheight->setMinValue(1);
174  $form->addItem($textheight);
175 
176  // obligatory
177  $shuffle = new ilCheckboxInputGUI($this->lng->txt("obligatory"), "obligatory");
178  $shuffle->setValue(1);
179  $shuffle->setChecked($this->object->getObligatory());
180  $shuffle->setRequired(FALSE);
181  $form->addItem($shuffle);
182 
183  $this->addCommandButtons($form);
184 
185  $errors = false;
186 
187  if ($this->isSaveCommand())
188  {
189  $form->setValuesByPost();
190  $errors = !$form->checkInput();
191  $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
192  if ($errors) $checkonly = false;
193  }
194 
195  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
196  return $errors;
197  }
198 
202  public function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
203  {
204  $template = new ilTemplate("tpl.il_svy_out_text.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
205  $template->setCurrentBlock("material_text");
206  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
207  $template->parseCurrentBlock();
208 
209  if ($this->object->getTextHeight() == 1)
210  {
211  $template->setCurrentBlock("textinput");
212  if (is_array($working_data))
213  {
214  if (strlen($working_data[0]["textanswer"]))
215  {
216  $template->setVariable("VALUE_ANSWER", " value=\"" . ilUtil::prepareFormOutput($working_data[0]["textanswer"]) . "\"");
217  }
218  }
219  $template->setVariable("QUESTION_ID", $this->object->getId());
220  $template->setVariable("WIDTH", $this->object->getTextWidth());
221  if ($this->object->getMaxChars())
222  {
223  $template->setVariable("MAXLENGTH", " maxlength=\"" . $this->object->getMaxChars() . "\"");
224  }
225  $template->parseCurrentBlock();
226  }
227  else
228  {
229  $template->setCurrentBlock("textarea");
230  if (is_array($working_data))
231  {
232  $template->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($working_data[0]["textanswer"]));
233  }
234  $template->setVariable("QUESTION_ID", $this->object->getId());
235  $template->setVariable("WIDTH", $this->object->getTextWidth());
236  $template->setVariable("HEIGHT", $this->object->getTextHeight());
237  $template->parseCurrentBlock();
238  }
239  $template->setCurrentBlock("question_data_text");
240  if ($show_questiontext)
241  {
242  $this->outQuestionText($template);
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  $this->outQuestionText($template);
271  }
272  if ($question_title)
273  {
274  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
275  }
276  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
277  $template->setVariable("TEXTBOX_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("textbox.png")));
278  $template->setVariable("TEXTBOX", $this->lng->txt("textbox"));
279  $template->setVariable("TEXTBOX_WIDTH", $this->object->getTextWidth()*16);
280  $template->setVariable("TEXTBOX_HEIGHT", $this->object->getTextHeight()*16);
281  $template->setVariable("QUESTION_ID", $this->object->getId());
282  if ($this->object->getMaxChars())
283  {
284  $template->setVariable("TEXT_MAXCHARS", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxChars()));
285  }
286  return $template->get();
287  }
288 
289  function setQuestionTabs()
290  {
291  $this->setQuestionTabsForClass("surveytextquestiongui");
292  }
293 
302  function getCumulatedResultsDetails($survey_id, $counter)
303  {
304  if (count($this->cumulated) == 0)
305  {
306  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
307  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
308  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
309  }
310 
311  $output = "";
312  include_once "./Services/UICore/classes/class.ilTemplate.php";
313  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
314 
315  $template->setCurrentBlock("detail_row");
316  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
317  $questiontext = $this->object->getQuestiontext();
318  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
319  $template->parseCurrentBlock();
320  $template->setCurrentBlock("detail_row");
321  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
322  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
323  $template->parseCurrentBlock();
324  $template->setCurrentBlock("detail_row");
325  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
326  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
327  $template->parseCurrentBlock();
328  $template->setCurrentBlock("detail_row");
329  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
330  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
331  $template->parseCurrentBlock();
332 
333  $template->setCurrentBlock("detail_row");
334  $template->setVariable("TEXT_OPTION", $this->lng->txt("given_answers"));
335  $textvalues = "";
336  if (is_array($this->cumulated["textvalues"]))
337  {
338  foreach ($this->cumulated["textvalues"] as $textvalue)
339  {
340  $textvalues .= "<li>" . preg_replace("/\n/", "<br>", $textvalue) . "</li>";
341  }
342  }
343  $textvalues = "<ul>$textvalues</ul>";
344  $template->setVariable("TEXT_OPTION_VALUE", $textvalues);
345  $template->parseCurrentBlock();
346 
347  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
348  return $template->get();
349  }
350 }
351 ?>