ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveySingleChoiceQuestionGUI.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.SurveySingleChoiceQuestion.php";
42  $this->object = new SurveySingleChoiceQuestion();
43  }
44 
45 
46  //
47  // EDITOR
48  //
49 
50  public function setQuestionTabs()
51  {
52  $this->setQuestionTabsForClass("surveysinglechoicequestiongui");
53  }
54 
55  protected function addFieldsToEditForm(ilPropertyFormGUI $a_form)
56  {
57  // orientation
58  $orientation = new ilRadioGroupInputGUI($this->lng->txt("orientation"), "orientation");
59  $orientation->setRequired(false);
60  $orientation->addOption(new ilRadioOption($this->lng->txt('vertical'), 0));
61  $orientation->addOption(new ilRadioOption($this->lng->txt('horizontal'), 1));
62  $orientation->addOption(new ilRadioOption($this->lng->txt('combobox'), 2));
63  $a_form->addItem($orientation);
64 
65  // Answers
66  include_once "./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
67  $answers = new ilCategoryWizardInputGUI($this->lng->txt("answers"), "answers");
68  $answers->setRequired(false);
69  $answers->setAllowMove(true);
70  $answers->setShowWizard(true);
71  $answers->setShowSavePhrase(true);
72  $answers->setUseOtherAnswer(true);
73  $answers->setShowNeutralCategory(true);
74  $answers->setNeutralCategoryTitle($this->lng->txt('svy_neutral_answer'));
75  $answers->setDisabledScale(false);
76  $a_form->addItem($answers);
77 
78  // values
79  $orientation->setValue($this->object->getOrientation());
80  if (!$this->object->getCategories()->getCategoryCount())
81  {
82  $this->object->getCategories()->addCategory("");
83  }
84  $answers->setValues($this->object->getCategories());
85  }
86 
87  protected function importEditFormValues(ilPropertyFormGUI $a_form)
88  {
89  $this->object->setOrientation($a_form->getInput("orientation"));
90 
91  $this->object->categories->flushCategories();
92 
93  foreach ($_POST['answers']['answer'] as $key => $value)
94  {
95  if (strlen($value)) $this->object->getCategories()->addCategory($value, $_POST['answers']['other'][$key], 0, null, $_POST['answers']['scale'][$key]);
96  }
97  if (strlen($_POST['answers']['neutral']))
98  {
99  $this->object->getCategories()->addCategory($_POST['answers']['neutral'], 0, 1, null, $_POST['answers_neutral_scale']);
100  }
101  }
102 
108  function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
109  {
110  $template = new ilTemplate("tpl.il_svy_qpl_sc_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
111  switch ($this->object->orientation)
112  {
113  case 0:
114  // vertical orientation
115  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
116  {
117  $cat = $this->object->categories->getCategory($i);
118  if ($cat->other)
119  {
120  $template->setCurrentBlock("other_row");
121  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
122  $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
123  $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
124  $template->setVariable("OTHER_LABEL", ilUtil::prepareFormOutput($cat->title));
125  $template->setVariable("OTHER_ANSWER", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
126  $template->parseCurrentBlock();
127  }
128  else
129  {
130  $template->setCurrentBlock("row");
131  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
132  $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
133  $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
134  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
135  $template->parseCurrentBlock();
136  }
137  }
138  break;
139  case 1:
140  // horizontal orientation
141  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
142  {
143  $template->setCurrentBlock("radio_col");
144  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
145  $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
146  $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
147  $template->parseCurrentBlock();
148  }
149  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
150  {
151  $cat = $this->object->categories->getCategory($i);
152  if ($cat->other)
153  {
154  $template->setCurrentBlock("other_text_col");
155  $template->setVariable("OTHER_LABEL", ilUtil::prepareFormOutput($cat->title));
156  $template->setVariable("OTHER_ANSWER", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
157  $template->parseCurrentBlock();
158  }
159  else
160  {
161  $template->setCurrentBlock("text_col");
162  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
163  $template->parseCurrentBlock();
164  }
165  }
166  break;
167  case 2:
168  // combobox output
169  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
170  {
171  $cat = $this->object->categories->getCategory($i);
172  $template->setCurrentBlock("comborow");
173  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
174  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
175  if (is_array($working_data))
176  {
177  if (strcmp($working_data[0]["value"], "") != 0)
178  {
179  if ($working_data[0]["value"] == $i)
180  {
181  $template->setVariable("SELECTED_SC", " selected=\"selected\"");
182  }
183  }
184  }
185  $template->parseCurrentBlock();
186  }
187  $template->setCurrentBlock("combooutput");
188  $template->setVariable("QUESTION_ID", $this->object->getId());
189  $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
190  $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
191  $template->parseCurrentBlock();
192  break;
193  }
194  if ($question_title)
195  {
196  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
197  }
198  if ($show_questiontext)
199  {
200  $this->outQuestionText($template);
201  }
202  $template->parseCurrentBlock();
203  return $template->get();
204  }
205 
206 
207  //
208  // EXECUTION
209  //
210 
216  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
217  {
218  $template = new ilTemplate("tpl.il_svy_out_sc.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
219  $template->setCurrentBlock("material");
220  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
221  $template->parseCurrentBlock();
222  switch ($this->object->orientation)
223  {
224  case 0:
225  // vertical orientation
226  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
227  {
228  $cat = $this->object->categories->getCategory($i);
229  if ($cat->other)
230  {
231  $template->setCurrentBlock("other_row");
232  if (strlen($cat->title))
233  {
234  $template->setVariable("OTHER_LABEL", $cat->title);
235  }
236  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
237  $template->setVariable("QUESTION_ID", $this->object->getId());
238  if (is_array($working_data))
239  {
240  foreach ($working_data as $value)
241  {
242  if (strlen($value["value"]))
243  {
244  if ($value["value"] == $cat->scale-1)
245  {
246  if (strlen($value['textanswer'])) $template->setVariable("OTHER_VALUE", ' value="' . ilUtil::prepareFormOutput($value['textanswer']) . '"');
247  if (!$value['uncheck'])
248  {
249  $template->setVariable("CHECKED_SC", " checked=\"checked\"");
250  }
251  }
252  }
253  }
254  }
255  $template->parseCurrentBlock();
256  }
257  else
258  {
259  $template->setCurrentBlock("row");
260  if ($cat->neutral) $template->setVariable('ROWCLASS', ' class="neutral"');
261  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
262  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
263  $template->setVariable("QUESTION_ID", $this->object->getId());
264  if (is_array($working_data))
265  {
266  foreach ($working_data as $value)
267  {
268  if (strcmp($value["value"], "") != 0)
269  {
270  if ($value["value"] == $cat->scale-1)
271  {
272  if (!$value['uncheck'])
273  {
274  $template->setVariable("CHECKED_SC", " checked=\"checked\"");
275  }
276  }
277  }
278  }
279  }
280  $template->parseCurrentBlock();
281  }
282  $template->touchBlock('outer_row');
283  }
284  break;
285  case 1:
286  // horizontal orientation
287  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
288  {
289  $cat = $this->object->categories->getCategory($i);
290  $template->setCurrentBlock("radio_col");
291  if ($cat->neutral) $template->setVariable('COLCLASS', ' neutral');
292  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
293  $template->setVariable("QUESTION_ID", $this->object->getId());
294  if (is_array($working_data))
295  {
296  foreach ($working_data as $value)
297  {
298  if (strcmp($value["value"], "") != 0)
299  {
300  if ($value["value"] == $cat->scale-1)
301  {
302  if (!$value['uncheck'])
303  {
304  $template->setVariable("CHECKED_SC", " checked=\"checked\"");
305  }
306  }
307  }
308  }
309  }
310  $template->parseCurrentBlock();
311  }
312  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
313  {
314  $cat = $this->object->categories->getCategory($i);
315  if ($cat->other)
316  {
317  $template->setCurrentBlock("text_other_col");
318  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
319  $template->setVariable("QUESTION_ID", $this->object->getId());
320  if (strlen($cat->title))
321  {
322  $template->setVariable("OTHER_LABEL", $cat->title);
323  }
324  if (is_array($working_data))
325  {
326  foreach ($working_data as $value)
327  {
328  if (strlen($value["value"]))
329  {
330  if ($value["value"] == $cat->scale-1 && strlen($value['textanswer']))
331  {
332  $template->setVariable("OTHER_VALUE", ' value="' . ilUtil::prepareFormOutput($value['textanswer']) . '"');
333  }
334  }
335  }
336  }
337  $template->parseCurrentBlock();
338  }
339  else
340  {
341  $template->setCurrentBlock("text_col");
342  if ($cat->neutral) $template->setVariable('COLCLASS', ' neutral');
343  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
344  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
345  $template->setVariable("QUESTION_ID", $this->object->getId());
346  $template->parseCurrentBlock();
347  }
348  $template->touchBlock('text_outer_col');
349  }
350  break;
351  case 2:
352  // combobox output
353  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
354  {
355  $cat = $this->object->categories->getCategory($i);
356  $template->setCurrentBlock("comborow");
357  $template->setVariable("TEXT_SC", $cat->title);
358  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
359  if (is_array($working_data))
360  {
361  if (strcmp($working_data[0]["value"], "") != 0)
362  {
363  if ($working_data[0]["value"] == $cat->scale-1)
364  {
365  $template->setVariable("SELECTED_SC", " selected=\"selected\"");
366  }
367  }
368  }
369  $template->parseCurrentBlock();
370  }
371  $template->setCurrentBlock("combooutput");
372  $template->setVariable("QUESTION_ID", $this->object->getId());
373  $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
374  $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
375  $template->parseCurrentBlock();
376  break;
377  }
378  if ($question_title)
379  {
380  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
381  }
382  $template->setCurrentBlock("question_data");
383  if (strcmp($error_message, "") != 0)
384  {
385  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
386  }
387  if ($show_questiontext)
388  {
389  $this->outQuestionText($template);
390  }
391  $template->parseCurrentBlock();
392  return $template->get();
393  }
394 
395 
396  //
397  // EVALUTION
398  //
399 
408  function getCumulatedResultsDetails($survey_id, $counter, $finished_ids)
409  {
410  if (count($this->cumulated) == 0)
411  {
412  if(!$finished_ids)
413  {
414  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
415  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
416  }
417  else
418  {
419  $nr_of_users = sizeof($finished_ids);
420  }
421  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users, $finished_ids);
422  }
423  $output = "";
424  include_once "./Services/UICore/classes/class.ilTemplate.php";
425  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
426 
427  $template->setCurrentBlock("detail_row");
428  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
429  $questiontext = $this->object->getQuestiontext();
430  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
431  $template->parseCurrentBlock();
432  $template->setCurrentBlock("detail_row");
433  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
434  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
435  $template->parseCurrentBlock();
436  $template->setCurrentBlock("detail_row");
437  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
438  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
439  $template->parseCurrentBlock();
440  $template->setCurrentBlock("detail_row");
441  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
442  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
443  $template->parseCurrentBlock();
444  /*
445  $template->setCurrentBlock("detail_row");
446  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
447  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE"]);
448  $template->parseCurrentBlock();
449  $template->setCurrentBlock("detail_row");
450  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
451  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
452  $template->parseCurrentBlock();
453  */
454  $template->setCurrentBlock("detail_row");
455  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
456  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MEDIAN"]);
457  $template->parseCurrentBlock();
458 
459  $template->setCurrentBlock("detail_row");
460  $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
461  $categories = "";
462  foreach ($this->cumulated["variables"] as $key => $value)
463  {
464  $categories .= "<li>" . $value["title"] . ": n=" . $value["selected"] .
465  " (" . sprintf("%.2f", 100*$value["percentage"]) . "%)</li>";
466  }
467  $categories = "<ol>$categories</ol>";
468  $template->setVariable("TEXT_OPTION_VALUE", $categories);
469  $template->parseCurrentBlock();
470 
471  // add text answers to detailed results
472  if (is_array($this->cumulated["textanswers"]))
473  {
474  $template->setCurrentBlock("detail_row");
475  $template->setVariable("TEXT_OPTION", $this->lng->txt("freetext_answers"));
476  $html = "";
477  foreach ($this->cumulated["textanswers"] as $key => $answers)
478  {
479  $html .= $this->cumulated["variables"][$key]["title"] ."\n";
480  $html .= "<ul>\n";
481  foreach ($answers as $answer)
482  {
483  $html .= "<li>" . preg_replace("/\n/", "<br>\n", $answer) . "</li>\n";
484  }
485  $html .= "</ul>\n";
486  }
487  $template->setVariable("TEXT_OPTION_VALUE", $html);
488  $template->parseCurrentBlock();
489  }
490 
491  // chart
492  $template->setCurrentBlock("detail_row");
493  $template->setVariable("TEXT_OPTION", $this->lng->txt("chart"));
494  $template->setVariable("TEXT_OPTION_VALUE", $this->renderChart("svy_ch_".$this->object->getId(), $this->cumulated["variables"]));
495  $template->parseCurrentBlock();
496 
497  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
498  return $template->get();
499  }
500 }
501 
502 ?>