ILIAS  Release_4_4_x_branch Revision 61816
 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 
38 {
39  protected function initObject()
40  {
41  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyMetricQuestion.php";
42  $this->object = new SurveyMetricQuestion();
43  }
44 
45 
46  //
47  // EDITOR
48  //
49 
50  public function setQuestionTabs()
51  {
52  $this->setQuestionTabsForClass("surveymetricquestiongui");
53  }
54 
55  protected function addFieldsToEditForm(ilPropertyFormGUI $a_form)
56  {
57  // subtype
58  $subtype = new ilRadioGroupInputGUI($this->lng->txt("subtype"), "type");
59  $subtype->setRequired(true);
60  $a_form->addItem($subtype);
61 
62  // #10652
63  $opt = new ilRadioOption($this->lng->txt('non_ratio'), SurveyMetricQuestion::SUBTYPE_NON_RATIO, $this->lng->txt("metric_subtype_description_interval"));
64  $subtype->addOption($opt);
65 
66  // minimum value
67  $minimum1 = new ilNumberInputGUI($this->lng->txt("minimum"), "minimum3");
68  $minimum1->setRequired(false);
69  $minimum1->setSize(6);
70  $opt->addSubItem($minimum1);
71 
72  // maximum value
73  $maximum1 = new ilNumberInputGUI($this->lng->txt("maximum"), "maximum3");
74  $maximum1->setRequired(false);
75  $maximum1->setSize(6);
76  $opt->addSubItem($maximum1);
77 
78  $opt = new ilRadioOption($this->lng->txt('ratio_non_absolute'), SurveyMetricQuestion::SUBTYPE_RATIO_NON_ABSOLUTE, $this->lng->txt("metric_subtype_description_rationonabsolute"));
79  $subtype->addOption($opt);
80 
81  // minimum value
82  $minimum2 = new ilNumberInputGUI($this->lng->txt("minimum"), "minimum4");
83  $minimum2->setRequired(false);
84  $minimum2->setSize(6);
85  $minimum2->setMinValue(0);
86  $opt->addSubItem($minimum2);
87 
88  // maximum value
89  $maximum2 = new ilNumberInputGUI($this->lng->txt("maximum"), "maximum4");
90  $maximum2->setRequired(false);
91  $maximum2->setSize(6);
92  $opt->addSubItem($maximum2);
93 
94  $opt = new ilRadioOption($this->lng->txt('ratio_absolute'), SurveyMetricQuestion::SUBTYPE_RATIO_ABSOLUTE, $this->lng->txt("metric_subtype_description_ratioabsolute"));
95  $subtype->addOption($opt);
96 
97  // minimum value
98  $minimum3 = new ilNumberInputGUI($this->lng->txt("minimum"), "minimum5");
99  $minimum3->setRequired(false);
100  $minimum3->setSize(6);
101  $minimum3->setMinValue(0);
102  $minimum3->setDecimals(0);
103  $opt->addSubItem($minimum3);
104 
105  // maximum value
106  $maximum3 = new ilNumberInputGUI($this->lng->txt("maximum"), "maximum5");
107  $maximum3->setDecimals(0);
108  $maximum3->setRequired(false);
109  $maximum3->setSize(6);
110  $opt->addSubItem($maximum3);
111 
112 
113  // values
114  $subtype->setValue($this->object->getSubtype());
115 
116  switch($this->object->getSubtype())
117  {
119  $minimum1->setValue($this->object->getMinimum());
120  $maximum1->setValue($this->object->getMaximum());
121  break;
122 
124  $minimum2->setValue($this->object->getMinimum());
125  $maximum2->setValue($this->object->getMaximum());
126  break;
127 
129  $minimum3->setValue($this->object->getMinimum());
130  $maximum3->setValue($this->object->getMaximum());
131  break;
132  }
133  }
134 
135  protected function importEditFormValues(ilPropertyFormGUI $a_form)
136  {
137  $type = (int)$a_form->getInput("type");
138  $this->object->setOrientation($a_form->getInput("orientation"));
139  $this->object->setSubtype($type);
140  $this->object->setMinimum($a_form->getInput("minimum".$type));
141  $this->object->setMaximum($a_form->getInput("maximum".$type));
142  }
143 
151  function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
152  {
153  $template = new ilTemplate("tpl.il_svy_qpl_metric_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
154  $template->setVariable("MIN_MAX", $this->object->getMinMaxText());
155 
156  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
157  if ($show_questiontext)
158  {
159  $this->outQuestionText($template);
160  }
161  if ($question_title)
162  {
163  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
164  }
165  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
166  $template->setVariable("QUESTION_ID", $this->object->getId());
167 
168  $solution_text = "";
169  $len = 10;
170  for ($i = 0; $i < 10; $i++) $solution_text .= "&#160;";
171  $template->setVariable("TEXT_SOLUTION", $solution_text);
172 
173  $template->parseCurrentBlock();
174  return $template->get();
175  }
176 
177 
178  //
179  // EXECUTION
180  //
181 
189  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
190  {
191  $template = new ilTemplate("tpl.il_svy_out_metric.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
192  $template->setCurrentBlock("material_metric");
193  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
194  $template->parseCurrentBlock();
195  $template->setVariable("MIN_MAX", $this->object->getMinMaxText());
196  /*if (strlen($this->object->getMinimum()))
197  {
198  $template->setCurrentBlock("minimum");
199  $template->setVariable("TEXT_MINIMUM", $this->lng->txt("minimum"));
200  $template->setVariable("VALUE_MINIMUM", $this->object->getMinimum());
201  $template->parseCurrentBlock();
202  }
203  if (strlen($this->object->getMaximum()))
204  {
205  $template->setCurrentBlock("maximum");
206  $template->setVariable("TEXT_MAXIMUM", $this->lng->txt("maximum"));
207  $template->setVariable("VALUE_MAXIMUM", $this->object->getMaximum());
208  $template->parseCurrentBlock();
209  }*/
210 
211  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
212  if ($show_questiontext)
213  {
214  $this->outQuestionText($template);
215  }
216  if ($question_title)
217  {
218  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
219  }
220  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
221  $template->setVariable("QUESTION_ID", $this->object->getId());
222  if (is_array($working_data))
223  {
224  $template->setVariable("VALUE_METRIC", $working_data[0]["value"]);
225  }
226 
227  $template->setVariable("INPUT_SIZE", 10);
228 
229  if (strcmp($error_message, "") != 0)
230  {
231  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
232  }
233  $template->parseCurrentBlock();
234  return $template->get();
235  }
236 
237 
238  //
239  // EVALUATION
240  //
241 
250  function getCumulatedResultsDetails($survey_id, $counter, $finished_ids)
251  {
252  if (count($this->cumulated) == 0)
253  {
254  if(!$finished_ids)
255  {
256  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
257  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
258  }
259  else
260  {
261  $nr_of_users = sizeof($finished_ids);
262  }
263  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users, $finished_ids);
264  }
265 
266  $output = "";
267  include_once "./Services/UICore/classes/class.ilTemplate.php";
268  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
269 
270  $template->setCurrentBlock("detail_row");
271  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
272  $questiontext = $this->object->getQuestiontext();
273  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
274  $template->parseCurrentBlock();
275  $template->setCurrentBlock("detail_row");
276  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
277  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
278  $template->parseCurrentBlock();
279  $template->setCurrentBlock("detail_row");
280  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
281  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
282  $template->parseCurrentBlock();
283  $template->setCurrentBlock("detail_row");
284  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
285  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
286  $template->parseCurrentBlock();
287  $template->setCurrentBlock("detail_row");
288  $template->setVariable("TEXT_OPTION", $this->lng->txt("subtype"));
289  switch ($this->object->getSubType())
290  {
292  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("non_ratio"));
293  break;
295  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("ratio_non_absolute"));
296  break;
298  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("ratio_absolute"));
299  break;
300  }
301  $template->parseCurrentBlock();
302 
303  /*
304  $template->setCurrentBlock("detail_row");
305  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
306  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE"]);
307  $template->parseCurrentBlock();
308  $template->setCurrentBlock("detail_row");
309  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
310  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
311  $template->parseCurrentBlock();
312  */
313  $template->setCurrentBlock("detail_row");
314  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
315  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MEDIAN"]);
316  $template->parseCurrentBlock();
317  $template->setCurrentBlock("detail_row");
318  $template->setVariable("TEXT_OPTION", $this->lng->txt("arithmetic_mean"));
319  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["ARITHMETIC_MEAN"]);
320  $template->parseCurrentBlock();
321 
322  $template->setCurrentBlock("detail_row");
323  $template->setVariable("TEXT_OPTION", $this->lng->txt("values"));
324  $values = "";
325  if (is_array($this->cumulated["values"]))
326  {
327  foreach ($this->cumulated["values"] as $key => $value)
328  {
329  $values .= "<li>" . $value["value"] . ": n=" . $value["selected"] .
330  " (" . sprintf("%.2f", 100*$value["percentage"]) . "%)</li>";
331  }
332  }
333  $values = "<ol>$values</ol>";
334  $template->setVariable("TEXT_OPTION_VALUE", $values);
335  $template->parseCurrentBlock();
336 
337 
338  // chart
339  $template->setCurrentBlock("detail_row");
340  $template->setVariable("TEXT_OPTION", $this->lng->txt("chart"));
341  $template->setVariable("TEXT_OPTION_VALUE", $this->renderChart("svy_ch_".$this->object->getId(), $this->cumulated["values"]));
342  $template->parseCurrentBlock();
343 
344 
345  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
346  return $template->get();
347  }
348 
349  protected function renderChart($a_id, $a_values)
350  {
351  include_once "Services/Chart/classes/class.ilChart.php";
352  $chart = new ilChart($a_id, 700, 400);
353 
354  $legend = new ilChartLegend();
355  $chart->setLegend($legend);
356 
357  $data = new ilChartData("bars");
358  $data->setLabel($this->lng->txt("users_answered"));
359  $data->setBarOptions(0.1, "center");
360 
361  if($a_values)
362  {
363  $labels = array();
364  foreach($a_values as $idx => $answer)
365  {
366  $data->addPoint($answer["value"], $answer["selected"]);
367  $labels[$answer["value"]] = $answer["value"];
368  }
369  $chart->addData($data);
370 
371  $chart->setTicks($labels, false, true);
372  }
373 
374  return "<div style=\"margin:10px\">".$chart->getHTML()."</div>";
375  }
376 }
377 
378 ?>