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