ILIAS  Release_3_10_x_branch Revision 61812
 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 
69  function editQuestion()
70  {
71  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_metric.html", "Modules/SurveyQuestionPool");
72  $this->tpl->addBlockFile("OTHER_QUESTION_DATA", "other_question_data", "tpl.il_svy_qpl_other_question_data.html", "Modules/SurveyQuestionPool");
73  $internallinks = array(
74  "lm" => $this->lng->txt("obj_lm"),
75  "st" => $this->lng->txt("obj_st"),
76  "pg" => $this->lng->txt("obj_pg"),
77  "glo" => $this->lng->txt("glossary_term")
78  );
79  foreach ($internallinks as $key => $value)
80  {
81  $this->tpl->setCurrentBlock("internallink");
82  $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
83  $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
84  $this->tpl->parseCurrentBlock();
85  }
86 
87  $this->tpl->setCurrentBlock("adm_content");
88  $this->tpl->setVariable("TEXT_MATERIAL", $this->lng->txt("material"));
89  if (count($this->object->material))
90  {
91  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
92  $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
93  $this->tpl->setVariable("TEXT_VALUE_MATERIAL", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("material"). "</a> ");
94  $this->tpl->setVariable("BUTTON_REMOVE_MATERIAL", $this->lng->txt("remove"));
95  $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("change"));
96  $this->tpl->setVariable("VALUE_MATERIAL", $this->object->material["internal_link"]);
97  $this->tpl->setVariable("VALUE_MATERIAL_TITLE", $this->object->material["title"]);
98  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
99  }
100  else
101  {
102  $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("add"));
103  }
104  $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
105  $this->tpl->setVariable("VALUE_TITLE", $this->object->getTitle());
106  $this->tpl->setVariable("VALUE_DESCRIPTION", $this->object->getDescription());
107  $this->tpl->setVariable("VALUE_AUTHOR", $this->object->getAuthor());
108  $questiontext = $this->object->getQuestiontext();
109  $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
110  $this->tpl->setVariable("VALUE_MINIMUM", $this->object->getMinimum());
111  $this->tpl->setVariable("VALUE_MAXIMUM", $this->object->getMaximum());
112  $this->tpl->setVariable("TEXT_MINIMUM", $this->lng->txt("minimum"));
113  $this->tpl->setVariable("TEXT_MAXIMUM", $this->lng->txt("maximum"));
114  $this->tpl->setVariable("TEXT_SUBTYPE", $this->lng->txt("subtype"));
115  $this->tpl->setVariable("DESCRIPTION_NONRATIO", $this->lng->txt("metric_subtype_description_interval"));
116  $this->tpl->setVariable("TEXT_NONRATIO", $this->lng->txt("non_ratio"));
117  $this->tpl->setVariable("DESCRIPTION_RATIONONABSOLUTE", $this->lng->txt("metric_subtype_description_rationonabsolute"));
118  $this->tpl->setVariable("TEXT_RATIONONABSOLUTE", $this->lng->txt("ratio_non_absolute"));
119  $this->tpl->setVariable("DESCRIPTION_RATIOABSOLUTE", $this->lng->txt("metric_subtype_description_ratioabsolute"));
120  $this->tpl->setVariable("TEXT_RATIOABSOLUTE", $this->lng->txt("ratio_absolute"));
121  if ($this->object->getSubtype() == SUBTYPE_NON_RATIO)
122  {
123  $this->tpl->setVariable("CHECKED_NONRATIO", " checked=\"checked\"");
124  }
125  else if ($this->object->getSubtype() == SUBTYPE_RATIO_NON_ABSOLUTE)
126  {
127  $this->tpl->setVariable("CHECKED_RATIONONABSOLUTE", " checked=\"checked\"");
128  }
129  else if ($this->object->getSubtype() == SUBTYPE_RATIO_ABSOLUTE)
130  {
131  $this->tpl->setVariable("CHECKED_RATIOABSOLUTE", " checked=\"checked\"");
132  }
133  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
134  $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
135  $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
136  $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
137  $this->tpl->setVariable("TEXT_OBLIGATORY", $this->lng->txt("obligatory"));
138  if ($this->object->getObligatory())
139  {
140  $this->tpl->setVariable("CHECKED_OBLIGATORY", " checked=\"checked\"");
141  }
142  $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("questiontype"));
143  $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
144  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
145  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
146  $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt($this->getQuestionType()));
147  $this->tpl->parseCurrentBlock();
148  include_once "./Services/RTE/classes/class.ilRTE.php";
149  $rtestring = ilRTE::_getRTEClassname();
150  include_once "./Services/RTE/classes/class.$rtestring.php";
151  $rte = new $rtestring();
152  $rte->addPlugin("latex");
153  $rte->addButton("latex"); $rte->addButton("pastelatex");
154  $rte->removePlugin("ibrowser");
155  include_once "./classes/class.ilObject.php";
156  $obj_id = $_GET["q_id"];
157  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
158  $rte->addRTESupport($obj_id, $obj_type, "survey");
159 
161  }
162 
171  function writePostData()
172  {
173  $result = 0;
174  if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"])) $result = 1;
175  if ($result == 1) $this->addErrorMessage($this->lng->txt("fill_out_all_required_fields"));
176  // Set the question id from a hidden form parameter
177  if ($_POST["id"] > 0) $this->object->setId($_POST["id"]);
178 
179  include_once "./Services/Utilities/classes/class.ilUtil.php";
180  $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
181  $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
182  $this->object->setDescription(ilUtil::stripSlashes($_POST["description"]));
183  if (strlen($_POST["material"]))
184  {
185  $this->object->setMaterial($_POST["material"], 0, ilUtil::stripSlashes($_POST["material_title"]));
186  }
187  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
188  $questiontext = ilUtil::stripSlashes($_POST["question"], true, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("survey"));
189  $this->object->setQuestiontext($questiontext);
190  if ($_POST["obligatory"])
191  {
192  $this->object->setObligatory(1);
193  }
194  else
195  {
196  $this->object->setObligatory(0);
197  }
198  $this->object->setSubtype($_POST["type"]);
199  $minimum = $_POST["minimum"];
200  if ($this->object->getSubtype() > 3)
201  {
202  if ($minimum < 0)
203  {
204  $this->addErrorMessage($this->lng->txt("ratio_scale_ge_zero"));
205  $result = 1;
206  }
207  }
208  $this->object->setMinimum($minimum);
209  $this->object->setMaximum($_POST["maximum"]);
210 
211  if ($saved) {
212  // If the question was saved automatically before an upload, we have to make
213  // sure, that the state after the upload is saved. Otherwise the user could be
214  // irritated, if he presses cancel, because he only has the question state before
215  // the upload process.
216  $this->object->saveToDb();
217  }
218  return $result;
219  }
220 
228  function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
229  {
230  $template = new ilTemplate("tpl.il_svy_qpl_metric_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
231  $template->setVariable("MIN_MAX", $this->object->getMinMaxText());
232 
233  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
234  if ($show_questiontext)
235  {
236  $questiontext = $this->object->getQuestiontext();
237  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
238  }
239  if (! $this->object->getObligatory($survey_id))
240  {
241  $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
242  }
243  if ($question_title)
244  {
245  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
246  }
247  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
248  $template->setVariable("QUESTION_ID", $this->object->getId());
249 
250  $solution_text = "";
251  $len = 10;
252  for ($i = 0; $i < 10; $i++) $solution_text .= "&#160;";
253  $template->setVariable("TEXT_SOLUTION", $solution_text);
254 
255  $template->parseCurrentBlock();
256  return $template->get();
257  }
258 
266  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
267  {
268  $template = new ilTemplate("tpl.il_svy_out_metric.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
269  if (count($this->object->material))
270  {
271  $template->setCurrentBlock("material_metric");
272  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
273  $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
274  $template->setVariable("TEXT_MATERIAL", $this->lng->txt("material") . ": <a href=\"$href\" target=\"content\">" . $this->object->material["title"]. "</a> ");
275  $template->parseCurrentBlock();
276  }
277  $template->setVariable("MIN_MAX", $this->object->getMinMaxText());
278  /*if (strlen($this->object->getMinimum()))
279  {
280  $template->setCurrentBlock("minimum");
281  $template->setVariable("TEXT_MINIMUM", $this->lng->txt("minimum"));
282  $template->setVariable("VALUE_MINIMUM", $this->object->getMinimum());
283  $template->parseCurrentBlock();
284  }
285  if (strlen($this->object->getMaximum()))
286  {
287  $template->setCurrentBlock("maximum");
288  $template->setVariable("TEXT_MAXIMUM", $this->lng->txt("maximum"));
289  $template->setVariable("VALUE_MAXIMUM", $this->object->getMaximum());
290  $template->parseCurrentBlock();
291  }*/
292 
293  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
294  if ($show_questiontext)
295  {
296  $questiontext = $this->object->getQuestiontext();
297  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
298  }
299  if (! $this->object->getObligatory($survey_id))
300  {
301  $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
302  }
303  if ($question_title)
304  {
305  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
306  }
307  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
308  $template->setVariable("QUESTION_ID", $this->object->getId());
309  if (is_array($working_data))
310  {
311  $template->setVariable("VALUE_METRIC", $working_data[0]["value"]);
312  }
313 
314  $template->setVariable("INPUT_SIZE", 10);
315 
316  if (strcmp($error_message, "") != 0)
317  {
318  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
319  }
320  $template->parseCurrentBlock();
321  return $template->get();
322  }
323 
331  function preview()
332  {
333  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", "Modules/SurveyQuestionPool");
334  $question_output = $this->getWorkingForm();
335  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
336  }
337 
338  function setQuestionTabs()
339  {
340  $this->setQuestionTabsForClass("surveymetricquestiongui");
341  }
342 
351  function getCumulatedResultRow($counter, $css_class, $survey_id)
352  {
353  include_once "./classes/class.ilTemplate.php";
354  if (count($this->cumulated) == 0)
355  {
356  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
357  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
358  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
359  }
360  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_row.html", TRUE, TRUE, "Modules/Survey");
361  $template->setVariable("QUESTION_TITLE", ($counter+1) . ". ".$this->object->getTitle());
362  $maxlen = 37;
363  $questiontext = preg_replace("/<[^>]+?>/ims", "", $this->object->getQuestiontext());
364  if (strlen($questiontext) > $maxlen + 3)
365  {
366  $questiontext = substr($questiontext, 0, $maxlen) . "...";
367  }
368  $template->setVariable("QUESTION_TEXT", $questiontext);
369  $template->setVariable("USERS_ANSWERED", $this->cumulated["USERS_ANSWERED"]);
370  $template->setVariable("USERS_SKIPPED", $this->cumulated["USERS_SKIPPED"]);
371  $template->setVariable("QUESTION_TYPE", $this->lng->txt($this->cumulated["QUESTION_TYPE"]));
372  $template->setVariable("MODE", $this->cumulated["MODE"]);
373  $template->setVariable("MODE_NR_OF_SELECTIONS", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
374  $template->setVariable("MEDIAN", $this->cumulated["MEDIAN"]);
375  $template->setVariable("ARITHMETIC_MEAN", $this->cumulated["ARITHMETIC_MEAN"]);
376  $template->setVariable("COLOR_CLASS", $css_class);
377  return $template->get();
378  }
379 
390  function getCumulatedResultsDetails($survey_id, $counter)
391  {
392  if (count($this->cumulated) == 0)
393  {
394  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
395  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
396  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
397  }
398 
399  $output = "";
400  include_once "./classes/class.ilTemplate.php";
401  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
402 
403  $template->setCurrentBlock("detail_row");
404  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
405  $questiontext = $this->object->getQuestiontext();
406  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
407  $template->parseCurrentBlock();
408  $template->setCurrentBlock("detail_row");
409  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
410  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
411  $template->parseCurrentBlock();
412  $template->setCurrentBlock("detail_row");
413  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
414  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
415  $template->parseCurrentBlock();
416  $template->setCurrentBlock("detail_row");
417  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
418  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
419  $template->parseCurrentBlock();
420  $template->setCurrentBlock("detail_row");
421  $template->setVariable("TEXT_OPTION", $this->lng->txt("subtype"));
422  switch ($this->object->getSubType())
423  {
424  case SUBTYPE_NON_RATIO:
425  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("non_ratio"));
426  break;
428  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("ratio_non_absolute"));
429  break;
431  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("ratio_absolute"));
432  break;
433  }
434  $template->parseCurrentBlock();
435 
436 
437  $template->setCurrentBlock("detail_row");
438  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
439  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE"]);
440  $template->parseCurrentBlock();
441  $template->setCurrentBlock("detail_row");
442  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
443  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
444  $template->parseCurrentBlock();
445  $template->setCurrentBlock("detail_row");
446  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
447  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MEDIAN"]);
448  $template->parseCurrentBlock();
449  $template->setCurrentBlock("detail_row");
450  $template->setVariable("TEXT_OPTION", $this->lng->txt("arithmetic_mean"));
451  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["ARITHMETIC_MEAN"]);
452  $template->parseCurrentBlock();
453 
454  $template->setCurrentBlock("detail_row");
455  $template->setVariable("TEXT_OPTION", $this->lng->txt("values"));
456  $values = "";
457  if (is_array($this->cumulated["values"]))
458  {
459  foreach ($this->cumulated["values"] as $key => $value)
460  {
461  $values .= "<li>" . $this->lng->txt("value") . ": " . "<span class=\"bold\">" . $value["value"] . "</span><br />" .
462  $this->lng->txt("value_nr_entered") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
463  $this->lng->txt("percentage_of_entered_values") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
464  }
465  }
466  $values = "<ol>$values</ol>";
467  $template->setVariable("TEXT_OPTION_VALUE", $values);
468  $template->parseCurrentBlock();
469  // display chart for metric question for array $eval["values"]
470  $template->setCurrentBlock("chart");
471  $charturl = "";
472  include_once "./Services/Administration/classes/class.ilSetting.php";
473  $surveySetting = new ilSetting("survey");
474  if ($surveySetting->get("googlechart") == 1)
475  {
476  $selections = array();
477  $values = array();
478  $maxselection = 0;
479  if (is_array($this->cumulated["values"]))
480  {
481  foreach ($this->cumulated["values"] as $val)
482  {
483  if ($val["selected"] > $maxselection) $maxselection = $val["selected"];
484  array_push($selections, $val["selected"]);
485  array_push($values, $val["value"]);
486  }
487  }
488  $selectionlabels = "";
489  if ($maxselection % 2 == 0)
490  {
491  $selectionlabels = "0|" . ($maxselection / 2) . "|$maxselection";
492  }
493  else
494  {
495  $selectionlabels = "0|$maxselection";
496  }
497  $chartwidth = 800;
498  $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());
499  }
500  else
501  {
502  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "survey", $survey_id);
503  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "question", $this->object->getId());
504  $charturl = $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "outChart");
505  }
506  $template->setVariable("CHART", $charturl);
507 
508  $template->setVariable("TEXT_CHART", $this->lng->txt("chart"));
509  $template->setVariable("ALT_CHART", $data["title"] . "( " . $this->lng->txt("chart") . ")");
510  $template->parseCurrentBlock();
511 
512  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
513  return $template->get();
514  }
515 
516 }
517 ?>