ILIAS  eassessment Revision 61809
 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  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
101 
102  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
103  $form = new ilPropertyFormGUI();
104  $form->setFormAction($this->ctrl->getFormAction($this));
105  $form->setTitle($this->lng->txt($this->getQuestionType()));
106  $form->setMultipart(FALSE);
107  $form->setTableWidth("100%");
108  $form->setId("multiplechoice");
109 
110  // title
111  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
112  $title->setValue($this->object->getTitle());
113  $title->setRequired(TRUE);
114  $form->addItem($title);
115 
116  // label
117  $label = new ilTextInputGUI($this->lng->txt("label"), "label");
118  $label->setValue($this->object->label);
119  $label->setInfo($this->lng->txt("label_info"));
120  $label->setRequired(false);
121  $form->addItem($label);
122 
123  // author
124  $author = new ilTextInputGUI($this->lng->txt("author"), "author");
125  $author->setValue($this->object->getAuthor());
126  $author->setRequired(TRUE);
127  $form->addItem($author);
128 
129  // description
130  $description = new ilTextInputGUI($this->lng->txt("description"), "description");
131  $description->setValue($this->object->getDescription());
132  $description->setRequired(FALSE);
133  $form->addItem($description);
134 
135  // questiontext
136  $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
137  $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestiontext()));
138  $question->setRequired(TRUE);
139  $question->setRows(10);
140  $question->setCols(80);
141  $question->setUseRte(TRUE);
142  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
143  $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
144  $question->addPlugin("latex");
145  $question->addButton("latex");
146  $question->addButton("pastelatex");
147  $question->removePlugin("ibrowser");
148  $question->setRTESupport($this->object->getId(), "spl", "survey");
149  $form->addItem($question);
150 
151  // subtype
152  $subtype = new ilRadioGroupInputGUI($this->lng->txt("subtype"), "type");
153  $subtype->setRequired(true);
154  $subtype->setValue($this->object->getSubtype());
155  $subtype->addOption(new ilRadioOption($this->lng->txt('non_ratio'), 3, $this->lng->txt("metric_subtype_description_interval")));
156  $subtype->addOption(new ilRadioOption($this->lng->txt('ratio_non_absolute'), 4, $this->lng->txt("metric_subtype_description_rationonabsolute")));
157  $subtype->addOption(new ilRadioOption($this->lng->txt('ratio_absolute'), 5, $this->lng->txt("metric_subtype_description_ratioabsolute")));
158  $form->addItem($subtype);
159 
160  // minimum value
161  $minimum = new ilNumberInputGUI($this->lng->txt("minimum"), "minimum");
162  $minimum->setValue($this->object->getMinimum());
163  $minimum->setRequired(false);
164  $minimum->setSize(6);
165  if ($this->object->getSubtype() > 3)
166  {
167  $minimum->setMinValue(0);
168  }
169  if ($this->object->getSubtype() == 5)
170  {
171  $minimum->setDecimals(0);
172  }
173  $form->addItem($minimum);
174 
175  // maximum value
176  $maximum = new ilNumberInputGUI($this->lng->txt("maximum"), "maximum");
177  if ($this->object->getSubtype() == 5)
178  {
179  $maximum->setDecimals(0);
180  }
181  $maximum->setValue($this->object->getMaximum());
182  $maximum->setRequired(false);
183  $maximum->setSize(6);
184  $form->addItem($maximum);
185 
186  // obligatory
187  $shuffle = new ilCheckboxInputGUI($this->lng->txt("obligatory"), "obligatory");
188  $shuffle->setValue(1);
189  $shuffle->setChecked($this->object->getObligatory());
190  $shuffle->setRequired(FALSE);
191  $form->addItem($shuffle);
192 
193  $form->addCommandButton("save", $this->lng->txt("save"));
194 
195  $errors = false;
196 
197  if ($save)
198  {
199  $form->setValuesByPost();
200  $errors = !$form->checkInput();
201  $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
202  if ($errors) $checkonly = false;
203  }
204 
205  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
206  return $errors;
207  }
208 
216  function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
217  {
218  $template = new ilTemplate("tpl.il_svy_qpl_metric_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
219  $template->setVariable("MIN_MAX", $this->object->getMinMaxText());
220 
221  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
222  if ($show_questiontext)
223  {
224  $this->outQuestionText($template);
225  }
226  if ($question_title)
227  {
228  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
229  }
230  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
231  $template->setVariable("QUESTION_ID", $this->object->getId());
232 
233  $solution_text = "";
234  $len = 10;
235  for ($i = 0; $i < 10; $i++) $solution_text .= "&#160;";
236  $template->setVariable("TEXT_SOLUTION", $solution_text);
237 
238  $template->parseCurrentBlock();
239  return $template->get();
240  }
241 
249  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
250  {
251  $template = new ilTemplate("tpl.il_svy_out_metric.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
252  $template->setCurrentBlock("material_metric");
253  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
254  $template->parseCurrentBlock();
255  $template->setVariable("MIN_MAX", $this->object->getMinMaxText());
256  /*if (strlen($this->object->getMinimum()))
257  {
258  $template->setCurrentBlock("minimum");
259  $template->setVariable("TEXT_MINIMUM", $this->lng->txt("minimum"));
260  $template->setVariable("VALUE_MINIMUM", $this->object->getMinimum());
261  $template->parseCurrentBlock();
262  }
263  if (strlen($this->object->getMaximum()))
264  {
265  $template->setCurrentBlock("maximum");
266  $template->setVariable("TEXT_MAXIMUM", $this->lng->txt("maximum"));
267  $template->setVariable("VALUE_MAXIMUM", $this->object->getMaximum());
268  $template->parseCurrentBlock();
269  }*/
270 
271  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
272  if ($show_questiontext)
273  {
274  $this->outQuestionText($template);
275  }
276  if ($question_title)
277  {
278  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
279  }
280  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
281  $template->setVariable("QUESTION_ID", $this->object->getId());
282  if (is_array($working_data))
283  {
284  $template->setVariable("VALUE_METRIC", $working_data[0]["value"]);
285  }
286 
287  $template->setVariable("INPUT_SIZE", 10);
288 
289  if (strcmp($error_message, "") != 0)
290  {
291  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
292  }
293  $template->parseCurrentBlock();
294  return $template->get();
295  }
296 
304  function preview()
305  {
306  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", "Modules/SurveyQuestionPool");
307  $question_output = $this->getWorkingForm();
308  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
309  }
310 
311  function setQuestionTabs()
312  {
313  $this->setQuestionTabsForClass("surveymetricquestiongui");
314  }
315 
324  function getCumulatedResultsDetails($survey_id, $counter)
325  {
326  if (count($this->cumulated) == 0)
327  {
328  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
329  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
330  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
331  }
332 
333  $output = "";
334  include_once "./classes/class.ilTemplate.php";
335  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
336 
337  $template->setCurrentBlock("detail_row");
338  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
339  $questiontext = $this->object->getQuestiontext();
340  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
341  $template->parseCurrentBlock();
342  $template->setCurrentBlock("detail_row");
343  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
344  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
345  $template->parseCurrentBlock();
346  $template->setCurrentBlock("detail_row");
347  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
348  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
349  $template->parseCurrentBlock();
350  $template->setCurrentBlock("detail_row");
351  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
352  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
353  $template->parseCurrentBlock();
354  $template->setCurrentBlock("detail_row");
355  $template->setVariable("TEXT_OPTION", $this->lng->txt("subtype"));
356  switch ($this->object->getSubType())
357  {
358  case SUBTYPE_NON_RATIO:
359  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("non_ratio"));
360  break;
362  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("ratio_non_absolute"));
363  break;
365  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("ratio_absolute"));
366  break;
367  }
368  $template->parseCurrentBlock();
369 
370 
371  $template->setCurrentBlock("detail_row");
372  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
373  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE"]);
374  $template->parseCurrentBlock();
375  $template->setCurrentBlock("detail_row");
376  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
377  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
378  $template->parseCurrentBlock();
379  $template->setCurrentBlock("detail_row");
380  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
381  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MEDIAN"]);
382  $template->parseCurrentBlock();
383  $template->setCurrentBlock("detail_row");
384  $template->setVariable("TEXT_OPTION", $this->lng->txt("arithmetic_mean"));
385  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["ARITHMETIC_MEAN"]);
386  $template->parseCurrentBlock();
387 
388  $template->setCurrentBlock("detail_row");
389  $template->setVariable("TEXT_OPTION", $this->lng->txt("values"));
390  $values = "";
391  if (is_array($this->cumulated["values"]))
392  {
393  foreach ($this->cumulated["values"] as $key => $value)
394  {
395  $values .= "<li>" . $this->lng->txt("value") . ": " . "<span class=\"bold\">" . $value["value"] . "</span><br />" .
396  $this->lng->txt("value_nr_entered") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
397  $this->lng->txt("percentage_of_entered_values") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
398  }
399  }
400  $values = "<ol>$values</ol>";
401  $template->setVariable("TEXT_OPTION_VALUE", $values);
402  $template->parseCurrentBlock();
403  // display chart for metric question for array $eval["values"]
404  $template->setCurrentBlock("chart");
405  $charturl = "";
406  include_once "./Services/Administration/classes/class.ilSetting.php";
407  $surveySetting = new ilSetting("survey");
408  if ($surveySetting->get("googlechart") == 1)
409  {
410  $selections = array();
411  $values = array();
412  $maxselection = 0;
413  if (is_array($this->cumulated["values"]))
414  {
415  foreach ($this->cumulated["values"] as $val)
416  {
417  if ($val["selected"] > $maxselection) $maxselection = $val["selected"];
418  array_push($selections, $val["selected"]);
419  array_push($values, $val["value"]);
420  }
421  }
422  $selectionlabels = "";
423  if ($maxselection % 2 == 0)
424  {
425  $selectionlabels = "0|" . ($maxselection / 2) . "|$maxselection";
426  }
427  else
428  {
429  $selectionlabels = "0|$maxselection";
430  }
431  $chartwidth = 800;
432  $charturl = "http://chart.apis.google.com/chart?chco=76A4FB&cht=bvs&chs=$chartwidth" . "x250&chd=t:" . implode(",", $selections) . "&chds=0,$maxselection&chxt=x,y,x,y&chxl=0:|" . implode("|", $values) . "|1:|$selectionlabels|2:||" . $this->lng->txt("values")."||3:||".$this->lng->txt("mode_nr_of_selections")."|" . "&chxr=1,0,$maxselection&chtt=" . str_replace(" ", "+", $this->object->getTitle());
433  }
434  else
435  {
436  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "survey", $survey_id);
437  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "question", $this->object->getId());
438  $charturl = $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "outChart");
439  }
440  $template->setVariable("CHART", $charturl);
441 
442  $template->setVariable("TEXT_CHART", $this->lng->txt("chart"));
443  $template->setVariable("ALT_CHART", $data["title"] . "( " . $this->lng->txt("chart") . ")");
444  $template->parseCurrentBlock();
445 
446  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
447  return $template->get();
448  }
449 
450 }
451 ?>