ILIAS  release_4-3 Revision
 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".(int)$_POST["type"]]);
84  $this->object->setMaximum($_POST["maximum".(int)$_POST["type"]]);
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->setRTESupport($this->object->getId(), "spl", "survey", null, false, "3.4.7");
146  $form->addItem($question);
147 
148 
149  // subtype
150  $subtype = new ilRadioGroupInputGUI($this->lng->txt("subtype"), "type");
151  $subtype->setRequired(true);
152  $subtype->setValue($this->object->getSubtype());
153  $form->addItem($subtype);
154 
155  // #10652
156  $opt = new ilRadioOption($this->lng->txt('non_ratio'), 3, $this->lng->txt("metric_subtype_description_interval"));
157  $subtype->addOption($opt);
158 
159  // minimum value
160  $minimum = new ilNumberInputGUI($this->lng->txt("minimum"), "minimum3");
161  if($this->object->getSubtype() == 3)
162  {
163  $minimum->setValue($this->object->getMinimum());
164  }
165  $minimum->setRequired(false);
166  $minimum->setSize(6);
167  $opt->addSubItem($minimum);
168 
169  // maximum value
170  $maximum = new ilNumberInputGUI($this->lng->txt("maximum"), "maximum3");
171  if($this->object->getSubtype() == 3)
172  {
173  $maximum->setValue($this->object->getMaximum());
174  }
175  $maximum->setRequired(false);
176  $maximum->setSize(6);
177  $opt->addSubItem($maximum);
178 
179  $opt = new ilRadioOption($this->lng->txt('ratio_non_absolute'), 4, $this->lng->txt("metric_subtype_description_rationonabsolute"));
180  $subtype->addOption($opt);
181 
182  // minimum value
183  $minimum = new ilNumberInputGUI($this->lng->txt("minimum"), "minimum4");
184  if($this->object->getSubtype() == 4)
185  {
186  $minimum->setValue($this->object->getMinimum());
187  }
188  $minimum->setRequired(false);
189  $minimum->setSize(6);
190  $minimum->setMinValue(0);
191  $opt->addSubItem($minimum);
192 
193  // maximum value
194  $maximum = new ilNumberInputGUI($this->lng->txt("maximum"), "maximum4");
195  if($this->object->getSubtype() == 4)
196  {
197  $maximum->setValue($this->object->getMaximum());
198  }
199  $maximum->setRequired(false);
200  $maximum->setSize(6);
201  $opt->addSubItem($maximum);
202 
203  $opt = new ilRadioOption($this->lng->txt('ratio_absolute'), 5, $this->lng->txt("metric_subtype_description_ratioabsolute"));
204  $subtype->addOption($opt);
205 
206  // minimum value
207  $minimum = new ilNumberInputGUI($this->lng->txt("minimum"), "minimum5");
208  if($this->object->getSubtype() == 5)
209  {
210  $minimum->setValue($this->object->getMinimum());
211  }
212  $minimum->setRequired(false);
213  $minimum->setSize(6);
214  $minimum->setMinValue(0);
215  $minimum->setDecimals(0);
216  $opt->addSubItem($minimum);
217 
218  // maximum value
219  $maximum = new ilNumberInputGUI($this->lng->txt("maximum"), "maximum5");
220  $maximum->setDecimals(0);
221  if($this->object->getSubtype() == 5)
222  {
223  $maximum->setValue($this->object->getMaximum());
224  }
225  $maximum->setRequired(false);
226  $maximum->setSize(6);
227  $opt->addSubItem($maximum);
228 
229 
230  // obligatory
231  $shuffle = new ilCheckboxInputGUI($this->lng->txt("obligatory"), "obligatory");
232  $shuffle->setValue(1);
233  $shuffle->setChecked($this->object->getObligatory());
234  $shuffle->setRequired(FALSE);
235  $form->addItem($shuffle);
236 
237  $this->addCommandButtons($form);
238 
239  $errors = false;
240 
241  if ($this->isSaveCommand())
242  {
243  $form->setValuesByPost();
244  $errors = !$form->checkInput();
245  $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
246  if ($errors) $checkonly = false;
247  }
248 
249  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
250  return $errors;
251  }
252 
260  function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
261  {
262  $template = new ilTemplate("tpl.il_svy_qpl_metric_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
263  $template->setVariable("MIN_MAX", $this->object->getMinMaxText());
264 
265  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
266  if ($show_questiontext)
267  {
268  $this->outQuestionText($template);
269  }
270  if ($question_title)
271  {
272  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
273  }
274  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
275  $template->setVariable("QUESTION_ID", $this->object->getId());
276 
277  $solution_text = "";
278  $len = 10;
279  for ($i = 0; $i < 10; $i++) $solution_text .= "&#160;";
280  $template->setVariable("TEXT_SOLUTION", $solution_text);
281 
282  $template->parseCurrentBlock();
283  return $template->get();
284  }
285 
293  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
294  {
295  $template = new ilTemplate("tpl.il_svy_out_metric.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
296  $template->setCurrentBlock("material_metric");
297  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
298  $template->parseCurrentBlock();
299  $template->setVariable("MIN_MAX", $this->object->getMinMaxText());
300  /*if (strlen($this->object->getMinimum()))
301  {
302  $template->setCurrentBlock("minimum");
303  $template->setVariable("TEXT_MINIMUM", $this->lng->txt("minimum"));
304  $template->setVariable("VALUE_MINIMUM", $this->object->getMinimum());
305  $template->parseCurrentBlock();
306  }
307  if (strlen($this->object->getMaximum()))
308  {
309  $template->setCurrentBlock("maximum");
310  $template->setVariable("TEXT_MAXIMUM", $this->lng->txt("maximum"));
311  $template->setVariable("VALUE_MAXIMUM", $this->object->getMaximum());
312  $template->parseCurrentBlock();
313  }*/
314 
315  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
316  if ($show_questiontext)
317  {
318  $this->outQuestionText($template);
319  }
320  if ($question_title)
321  {
322  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
323  }
324  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
325  $template->setVariable("QUESTION_ID", $this->object->getId());
326  if (is_array($working_data))
327  {
328  $template->setVariable("VALUE_METRIC", $working_data[0]["value"]);
329  }
330 
331  $template->setVariable("INPUT_SIZE", 10);
332 
333  if (strcmp($error_message, "") != 0)
334  {
335  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
336  }
337  $template->parseCurrentBlock();
338  return $template->get();
339  }
340 
341  function setQuestionTabs()
342  {
343  $this->setQuestionTabsForClass("surveymetricquestiongui");
344  }
345 
354  function getCumulatedResultsDetails($survey_id, $counter)
355  {
356  if (count($this->cumulated) == 0)
357  {
358  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
359  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
360  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
361  }
362 
363  $output = "";
364  include_once "./Services/UICore/classes/class.ilTemplate.php";
365  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
366 
367  $template->setCurrentBlock("detail_row");
368  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
369  $questiontext = $this->object->getQuestiontext();
370  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
371  $template->parseCurrentBlock();
372  $template->setCurrentBlock("detail_row");
373  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
374  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
375  $template->parseCurrentBlock();
376  $template->setCurrentBlock("detail_row");
377  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
378  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
379  $template->parseCurrentBlock();
380  $template->setCurrentBlock("detail_row");
381  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
382  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
383  $template->parseCurrentBlock();
384  $template->setCurrentBlock("detail_row");
385  $template->setVariable("TEXT_OPTION", $this->lng->txt("subtype"));
386  switch ($this->object->getSubType())
387  {
388  case SUBTYPE_NON_RATIO:
389  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("non_ratio"));
390  break;
392  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("ratio_non_absolute"));
393  break;
395  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("ratio_absolute"));
396  break;
397  }
398  $template->parseCurrentBlock();
399 
400  /*
401  $template->setCurrentBlock("detail_row");
402  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
403  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE"]);
404  $template->parseCurrentBlock();
405  $template->setCurrentBlock("detail_row");
406  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
407  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
408  $template->parseCurrentBlock();
409  */
410  $template->setCurrentBlock("detail_row");
411  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
412  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MEDIAN"]);
413  $template->parseCurrentBlock();
414  $template->setCurrentBlock("detail_row");
415  $template->setVariable("TEXT_OPTION", $this->lng->txt("arithmetic_mean"));
416  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["ARITHMETIC_MEAN"]);
417  $template->parseCurrentBlock();
418 
419  $template->setCurrentBlock("detail_row");
420  $template->setVariable("TEXT_OPTION", $this->lng->txt("values"));
421  $values = "";
422  if (is_array($this->cumulated["values"]))
423  {
424  foreach ($this->cumulated["values"] as $key => $value)
425  {
426  $values .= "<li>" . $value["value"] . ": n=" . $value["selected"] .
427  " (" . sprintf("%.2f", 100*$value["percentage"]) . "%)</li>";
428  }
429  }
430  $values = "<ol>$values</ol>";
431  $template->setVariable("TEXT_OPTION_VALUE", $values);
432  $template->parseCurrentBlock();
433 
434 
435  // chart
436  $template->setCurrentBlock("detail_row");
437  $template->setVariable("TEXT_OPTION", $this->lng->txt("chart"));
438  $template->setVariable("TEXT_OPTION_VALUE", $this->renderChart("svy_ch_".$this->object->getId(), $this->cumulated["values"]));
439  $template->parseCurrentBlock();
440 
441 
442  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
443  return $template->get();
444  }
445 
446  protected function renderChart($a_id, $a_values)
447  {
448  include_once "Services/Chart/classes/class.ilChart.php";
449  $chart = new ilChart($a_id, 700, 400);
450 
451  $legend = new ilChartLegend();
452  $chart->setLegend($legend);
453 
454  $data = new ilChartData("bars");
455  $data->setLabel($this->lng->txt("users_answered"));
456  $data->setBarOptions(0.1, "center");
457 
458  if($a_values)
459  {
460  $labels = array();
461  foreach($a_values as $idx => $answer)
462  {
463  $data->addPoint($answer["value"], $answer["selected"]);
464  $labels[$answer["value"]] = $answer["value"];
465  }
466  $chart->addData($data);
467 
468  $chart->setTicks($labels, false, true);
469  }
470 
471  return "<div style=\"margin:10px\">".$chart->getHTML()."</div>";
472  }
473 }
474 ?>