ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
38 {
39  protected function initObject()
40  {
41  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyTextQuestion.php";
42  $this->object = new SurveyTextQuestion();
43  }
44 
45 
46  //
47  // EDITOR
48  //
49 
50  public function setQuestionTabs()
51  {
52  $this->setQuestionTabsForClass("surveytextquestiongui");
53  }
54 
55  protected function addFieldsToEditForm(ilPropertyFormGUI $a_form)
56  {
57  // maximum number of characters
58  $maxchars = new ilNumberInputGUI($this->lng->txt("maxchars"), "maxchars");
59  $maxchars->setRequired(false);
60  $maxchars->setSize(5);
61  $maxchars->setDecimals(0);
62  $a_form->addItem($maxchars);
63 
64  // textwidth
65  $textwidth = new ilNumberInputGUI($this->lng->txt("width"), "textwidth");
66  $textwidth->setRequired(true);
67  $textwidth->setSize(3);
68  $textwidth->setDecimals(0);
69  $textwidth->setMinValue(10, true);
70  $a_form->addItem($textwidth);
71 
72  // textheight
73  $textheight = new ilNumberInputGUI($this->lng->txt("height"), "textheight");
74  $textheight->setRequired(true);
75  $textheight->setSize(3);
76 
77  $textheight->setDecimals(0);
78  $textheight->setMinValue(1);
79  $a_form->addItem($textheight);
80 
81  // values
82  if ($this->object->getMaxChars() > 0)
83  {
84  $maxchars->setValue($this->object->getMaxChars());
85  }
86  $textwidth->setValue($this->object->getTextWidth());
87  $textheight->setValue($this->object->getTextHeight());
88  }
89 
90  protected function importEditFormValues(ilPropertyFormGUI $a_form)
91  {
92  $max = $a_form->getInput("maxchars");
93  $this->object->setMaxChars(strlen($max) ? $max : null);
94  $this->object->setTextWidth($a_form->getInput("textwidth"));
95  $this->object->setTextHeight($a_form->getInput("textheight"));
96  }
97 
98  public function getParsedAnswers(array $a_working_data = null, $a_only_user_anwers = false)
99  {
100  $res = array();
101 
102  if(is_array($a_working_data))
103  {
104  $res[] = array("textanswer"=>trim($a_working_data[0]["textanswer"]));
105  }
106 
107  return $res;
108  }
109 
110  public function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null, array $a_working_data = null)
111  {
112  $user_answer = null;
113  if($a_working_data)
114  {
115  $user_answer = $this->getParsedAnswers($a_working_data);
116  $user_answer = $user_answer[0]["textanswer"];
117  }
118 
119  $template = new ilTemplate("tpl.il_svy_qpl_text_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
120  if ($show_questiontext)
121  {
122  $this->outQuestionText($template);
123  }
124  if ($question_title)
125  {
126  $template->setVariable("QUESTION_TITLE", $this->getPrintViewQuestionTitle($question_title));
127  }
128  $template->setVariable("QUESTION_ID", $this->object->getId());
129  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
130  if(is_array($a_working_data) && trim($user_answer))
131  {
132  $template->setVariable("TEXT", nl2br($user_answer));
133  }
134  else
135  {
136  $template->setVariable("TEXTBOX_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("textbox.png")));
137  $template->setVariable("TEXTBOX", $this->lng->txt("textbox"));
138  $template->setVariable("TEXTBOX_WIDTH", $this->object->getTextWidth()*16);
139  $template->setVariable("TEXTBOX_HEIGHT", $this->object->getTextHeight()*16);
140  }
141  if ($this->object->getMaxChars())
142  {
143  $template->setVariable("TEXT_MAXCHARS", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxChars()));
144  }
145  return $template->get();
146  }
147 
148 
149  //
150  // EXECUTION
151  //
152 
156  public function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
157  {
158  $template = new ilTemplate("tpl.il_svy_out_text.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
159  $template->setCurrentBlock("material_text");
160  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
161  $template->parseCurrentBlock();
162 
163  if ($this->object->getTextHeight() == 1)
164  {
165  $template->setCurrentBlock("textinput");
166  if (is_array($working_data))
167  {
168  if (strlen($working_data[0]["textanswer"]))
169  {
170  $template->setVariable("VALUE_ANSWER", " value=\"" . ilUtil::prepareFormOutput($working_data[0]["textanswer"]) . "\"");
171  }
172  }
173  $template->setVariable("QUESTION_ID", $this->object->getId());
174  $template->setVariable("WIDTH", $this->object->getTextWidth());
175  if ($this->object->getMaxChars())
176  {
177  $template->setVariable("MAXLENGTH", " maxlength=\"" . $this->object->getMaxChars() . "\"");
178  }
179  $template->parseCurrentBlock();
180  }
181  else
182  {
183  $template->setCurrentBlock("textarea");
184  if (is_array($working_data))
185  {
186  $template->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($working_data[0]["textanswer"]));
187  }
188  $template->setVariable("QUESTION_ID", $this->object->getId());
189  $template->setVariable("WIDTH", $this->object->getTextWidth());
190  $template->setVariable("HEIGHT", $this->object->getTextHeight());
191  $template->parseCurrentBlock();
192  }
193  $template->setCurrentBlock("question_data_text");
194  if ($show_questiontext)
195  {
196  $this->outQuestionText($template);
197  }
198  if ($question_title)
199  {
200  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
201  }
202  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
203  $template->setVariable("LABEL_QUESTION_ID", $this->object->getId());
204  if (strcmp($error_message, "") != 0)
205  {
206  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
207  }
208  if ($this->object->getMaxChars())
209  {
210  $template->setVariable("TEXT_MAXCHARS", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxChars()));
211  }
212  $template->parseCurrentBlock();
213  return $template->get();
214  }
215 }
216 
217 ?>
addFieldsToEditForm(ilPropertyFormGUI $a_form)
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getMaterialOutput()
Creates the HTML output of the question material(s)
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
Text survey question GUI representation.
getWorkingForm($working_data="", $question_title=1, $show_questiontext=1, $error_message="", $survey_id=null)
Creates the question output form for the learner.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
This class represents a number property in a property form.
special template class to simplify handling of ITX/PEAR
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
static getHtmlPath($relative_path)
get url of path
Create styles array
The data for the language used.
getParsedAnswers(array $a_working_data=null, $a_only_user_anwers=false)
Create new PHPExcel object
obj_idprivate
Text survey question.
importEditFormValues(ilPropertyFormGUI $a_form)
getPrintViewQuestionTitle($question_title=1)
getPrintView($question_title=1, $show_questiontext=1, $survey_id=null, array $a_working_data=null)
Basic class for all survey question types.
setRequired($a_required)
Set Required.