ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyMetricQuestionGUI.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 {
49  $id = -1
50  )
51 
52  {
53  $this->SurveyQuestionGUI();
54  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyMetricQuestion.php";
55  $this->object = new SurveyMetricQuestion();
56  if ($id >= 0)
57  {
58  $this->object->loadFromDb($id);
59  }
60  }
61 
68  function writePostData($always = false)
69  {
70  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
71  if (!$hasErrors)
72  {
73  $this->object->setTitle($_POST["title"]);
74  $this->object->setAuthor($_POST["author"]);
75  $this->object->setDescription($_POST["description"]);
76  $questiontext = $_POST["question"];
77  $this->object->setQuestiontext($questiontext);
78  $this->object->setObligatory(($_POST["obligatory"]) ? 1 : 0);
79  $this->object->setOrientation($_POST["orientation"]);
80  $this->object->label = $_POST['label'];
81 
82  $this->object->setSubtype($_POST["type"]);
83  $this->object->setMinimum($_POST["minimum"]);
84  $this->object->setMaximum($_POST["maximum"]);
85  return 0;
86  }
87  else
88  {
89  return 1;
90  }
91  }
92 
98  public function editQuestion($checkonly = 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("multiplechoice");
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  // label
115  $label = new ilTextInputGUI($this->lng->txt("label"), "label");
116  $label->setValue($this->object->label);
117  $label->setInfo($this->lng->txt("label_info"));
118  $label->setRequired(false);
119  $form->addItem($label);
120 
121  // author
122  $author = new ilTextInputGUI($this->lng->txt("author"), "author");
123  $author->setValue($this->object->getAuthor());
124  $author->setRequired(TRUE);
125  $form->addItem($author);
126 
127  // description
128  $description = new ilTextInputGUI($this->lng->txt("description"), "description");
129  $description->setValue($this->object->getDescription());
130  $description->setRequired(FALSE);
131  $form->addItem($description);
132 
133  // questiontext
134  $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
135  $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestiontext()));
136  $question->setRequired(TRUE);
137  $question->setRows(10);
138  $question->setCols(80);
139  $question->setUseRte(TRUE);
140  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
141  $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
142  $question->addPlugin("latex");
143  $question->addButton("latex");
144  $question->addButton("pastelatex");
145  $question->removePlugin("ibrowser");
146  $question->setRTESupport($this->object->getId(), "spl", "survey", null, false, "3.4.7");
147  $form->addItem($question);
148 
149  // subtype
150  $subtype = new ilRadioGroupInputGUI($this->lng->txt("subtype"), "type");
151  $subtype->setRequired(true);
152  $subtype->setValue($this->object->getSubtype());
153  $subtype->addOption(new ilRadioOption($this->lng->txt('non_ratio'), 3, $this->lng->txt("metric_subtype_description_interval")));
154  $subtype->addOption(new ilRadioOption($this->lng->txt('ratio_non_absolute'), 4, $this->lng->txt("metric_subtype_description_rationonabsolute")));
155  $subtype->addOption(new ilRadioOption($this->lng->txt('ratio_absolute'), 5, $this->lng->txt("metric_subtype_description_ratioabsolute")));
156  $form->addItem($subtype);
157 
158  // minimum value
159  $minimum = new ilNumberInputGUI($this->lng->txt("minimum"), "minimum");
160  $minimum->setValue($this->object->getMinimum());
161  $minimum->setRequired(false);
162  $minimum->setSize(6);
163  if ($this->object->getSubtype() > 3)
164  {
165  $minimum->setMinValue(0);
166  }
167  if ($this->object->getSubtype() == 5)
168  {
169  $minimum->setDecimals(0);
170  }
171  $form->addItem($minimum);
172 
173  // maximum value
174  $maximum = new ilNumberInputGUI($this->lng->txt("maximum"), "maximum");
175  if ($this->object->getSubtype() == 5)
176  {
177  $maximum->setDecimals(0);
178  }
179  $maximum->setValue($this->object->getMaximum());
180  $maximum->setRequired(false);
181  $maximum->setSize(6);
182  $form->addItem($maximum);
183 
184  // obligatory
185  $shuffle = new ilCheckboxInputGUI($this->lng->txt("obligatory"), "obligatory");
186  $shuffle->setValue(1);
187  $shuffle->setChecked($this->object->getObligatory());
188  $shuffle->setRequired(FALSE);
189  $form->addItem($shuffle);
190 
191  $this->addCommandButtons($form);
192 
193  $errors = false;
194 
195  if ($this->isSaveCommand())
196  {
197  $form->setValuesByPost();
198  $errors = !$form->checkInput();
199  $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
200  if ($errors) $checkonly = false;
201  }
202 
203  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
204  return $errors;
205  }
206 
214  function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
215  {
216  $template = new ilTemplate("tpl.il_svy_qpl_metric_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
217  $template->setVariable("MIN_MAX", $this->object->getMinMaxText());
218 
219  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
220  if ($show_questiontext)
221  {
222  $this->outQuestionText($template);
223  }
224  if ($question_title)
225  {
226  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
227  }
228  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
229  $template->setVariable("QUESTION_ID", $this->object->getId());
230 
231  $solution_text = "";
232  $len = 10;
233  for ($i = 0; $i < 10; $i++) $solution_text .= "&#160;";
234  $template->setVariable("TEXT_SOLUTION", $solution_text);
235 
236  $template->parseCurrentBlock();
237  return $template->get();
238  }
239 
247  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
248  {
249  $template = new ilTemplate("tpl.il_svy_out_metric.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
250  $template->setCurrentBlock("material_metric");
251  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
252  $template->parseCurrentBlock();
253  $template->setVariable("MIN_MAX", $this->object->getMinMaxText());
254  /*if (strlen($this->object->getMinimum()))
255  {
256  $template->setCurrentBlock("minimum");
257  $template->setVariable("TEXT_MINIMUM", $this->lng->txt("minimum"));
258  $template->setVariable("VALUE_MINIMUM", $this->object->getMinimum());
259  $template->parseCurrentBlock();
260  }
261  if (strlen($this->object->getMaximum()))
262  {
263  $template->setCurrentBlock("maximum");
264  $template->setVariable("TEXT_MAXIMUM", $this->lng->txt("maximum"));
265  $template->setVariable("VALUE_MAXIMUM", $this->object->getMaximum());
266  $template->parseCurrentBlock();
267  }*/
268 
269  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
270  if ($show_questiontext)
271  {
272  $this->outQuestionText($template);
273  }
274  if ($question_title)
275  {
276  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
277  }
278  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
279  $template->setVariable("QUESTION_ID", $this->object->getId());
280  if (is_array($working_data))
281  {
282  $template->setVariable("VALUE_METRIC", $working_data[0]["value"]);
283  }
284 
285  $template->setVariable("INPUT_SIZE", 10);
286 
287  if (strcmp($error_message, "") != 0)
288  {
289  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
290  }
291  $template->parseCurrentBlock();
292  return $template->get();
293  }
294 
295  function setQuestionTabs()
296  {
297  $this->setQuestionTabsForClass("surveymetricquestiongui");
298  }
299 
308  function getCumulatedResultsDetails($survey_id, $counter)
309  {
310  if (count($this->cumulated) == 0)
311  {
312  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
313  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
314  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
315  }
316 
317  $output = "";
318  include_once "./classes/class.ilTemplate.php";
319  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
320 
321  $template->setCurrentBlock("detail_row");
322  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
323  $questiontext = $this->object->getQuestiontext();
324  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
325  $template->parseCurrentBlock();
326  $template->setCurrentBlock("detail_row");
327  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
328  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
329  $template->parseCurrentBlock();
330  $template->setCurrentBlock("detail_row");
331  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
332  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
333  $template->parseCurrentBlock();
334  $template->setCurrentBlock("detail_row");
335  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
336  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
337  $template->parseCurrentBlock();
338  $template->setCurrentBlock("detail_row");
339  $template->setVariable("TEXT_OPTION", $this->lng->txt("subtype"));
340  switch ($this->object->getSubType())
341  {
342  case SUBTYPE_NON_RATIO:
343  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("non_ratio"));
344  break;
346  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("ratio_non_absolute"));
347  break;
349  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("ratio_absolute"));
350  break;
351  }
352  $template->parseCurrentBlock();
353 
354  /*
355  $template->setCurrentBlock("detail_row");
356  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
357  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE"]);
358  $template->parseCurrentBlock();
359  $template->setCurrentBlock("detail_row");
360  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
361  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
362  $template->parseCurrentBlock();
363  */
364  $template->setCurrentBlock("detail_row");
365  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
366  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MEDIAN"]);
367  $template->parseCurrentBlock();
368  $template->setCurrentBlock("detail_row");
369  $template->setVariable("TEXT_OPTION", $this->lng->txt("arithmetic_mean"));
370  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["ARITHMETIC_MEAN"]);
371  $template->parseCurrentBlock();
372 
373  $template->setCurrentBlock("detail_row");
374  $template->setVariable("TEXT_OPTION", $this->lng->txt("values"));
375  $values = "";
376  if (is_array($this->cumulated["values"]))
377  {
378  foreach ($this->cumulated["values"] as $key => $value)
379  {
380  $values .= "<li>" . $value["value"] . ": n=" . $value["selected"] .
381  " (" . sprintf("%.2f", 100*$value["percentage"]) . "%)</li>";
382  }
383  }
384  $values = "<ol>$values</ol>";
385  $template->setVariable("TEXT_OPTION_VALUE", $values);
386  $template->parseCurrentBlock();
387 
388 
389  // chart
390  $template->setCurrentBlock("detail_row");
391  $template->setVariable("TEXT_OPTION", $this->lng->txt("chart"));
392  $template->setVariable("TEXT_OPTION_VALUE", $this->renderChart("svy_ch_".$this->object->getId(), $this->cumulated["values"]));
393  $template->parseCurrentBlock();
394 
395 
396  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
397  return $template->get();
398  }
399 
400  protected function renderChart($a_id, $a_values)
401  {
402  include_once "Services/Chart/classes/class.ilChart.php";
403  $chart = new ilChart($a_id, 700, 400);
404 
405  $legend = new ilChartLegend();
406  $chart->setLegend($legend);
407 
408  $data = new ilChartData("bars");
409  $data->setLabel($this->lng->txt("users_answered"));
410  $data->setBarOptions(0.1, "center");
411 
412  if($a_values)
413  {
414  $labels = array();
415  foreach($a_values as $idx => $answer)
416  {
417  $data->addPoint($answer["value"], $answer["selected"]);
418  $labels[$answer["value"]] = $answer["value"];
419  }
420  $chart->addData($data);
421 
422  $chart->setTicks($labels, false, true);
423  }
424 
425  return "<div style=\"margin:10px\">".$chart->getHTML()."</div>";
426  }
427 }
428 ?>