ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyMatrixQuestionGUI.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 $show_layout_row;
40 
41  protected function initObject()
42  {
43  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyMatrixQuestion.php";
44  $this->object = new SurveyMatrixQuestion();
45  }
46 
47 
48  //
49  // EDITOR
50  //
51 
52  public function setQuestionTabs()
53  {
54  $this->setQuestionTabsForClass("surveymatrixquestiongui");
55  }
56 
57  protected function addFieldsToEditForm(ilPropertyFormGUI $a_form)
58  {
59  // subtype
60  $subtype = new ilRadioGroupInputGUI($this->lng->txt("subtype"), "type");
61  $subtype->setRequired(false);
62  $subtypes = array(
63  "0" => "matrix_subtype_sr",
64  "1" => "matrix_subtype_mr",
65  //"2" => "matrix_subtype_text",
66  //"3" => "matrix_subtype_integer",
67  //"4" => "matrix_subtype_double",
68  //"5" => "matrix_subtype_date",
69  //"6" => "matrix_subtype_time"
70  );
71  foreach ($subtypes as $idx => $st)
72  {
73  $subtype->addOption(new ilRadioOption($this->lng->txt($st), $idx));
74  }
75  $a_form->addItem($subtype);
76 
77 
78  $header = new ilFormSectionHeaderGUI();
79  $header->setTitle($this->lng->txt("matrix_appearance"));
80  $a_form->addItem($header);
81 
82  // column separators
83  $column_separators = new ilCheckboxInputGUI($this->lng->txt("matrix_column_separators"), "column_separators");
84  $column_separators->setValue(1);
85  $column_separators->setInfo($this->lng->txt("matrix_column_separators_description"));
86  $column_separators->setRequired(false);
87  $a_form->addItem($column_separators);
88 
89  // row separators
90  $row_separators = new ilCheckboxInputGUI($this->lng->txt("matrix_row_separators"), "row_separators");
91  $row_separators->setValue(1);
92  $row_separators->setInfo($this->lng->txt("matrix_row_separators_description"));
93  $row_separators->setRequired(false);
94  $a_form->addItem($row_separators);
95 
96  // neutral column separators
97  $neutral_column_separator = new ilCheckboxInputGUI($this->lng->txt("matrix_neutral_column_separator"), "neutral_column_separator");
98  $neutral_column_separator->setValue(1);
99  $neutral_column_separator->setInfo($this->lng->txt("matrix_neutral_column_separator_description"));
100  $neutral_column_separator->setRequired(false);
101  $a_form->addItem($neutral_column_separator);
102 
103 
104  $header = new ilFormSectionHeaderGUI();
105  $header->setTitle($this->lng->txt("matrix_columns"));
106  $a_form->addItem($header);
107 
108  // Answers
109  include_once "./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
110  $columns = new ilCategoryWizardInputGUI("", "columns");
111  $columns->setRequired(false);
112  $columns->setAllowMove(true);
113  $columns->setShowWizard(true);
114  $columns->setShowNeutralCategory(true);
115  $columns->setDisabledScale(false);
116  $columns->setNeutralCategoryTitle($this->lng->txt('matrix_neutral_answer'));
117  $columns->setCategoryText($this->lng->txt('matrix_standard_answers'));
118  $columns->setShowSavePhrase(true);
119  $a_form->addItem($columns);
120 
121 
122  $header = new ilFormSectionHeaderGUI();
123  $header->setTitle($this->lng->txt("matrix_column_settings"));
124  $a_form->addItem($header);
125 
126  // bipolar adjectives
127  $bipolar = new ilCustomInputGUI($this->lng->txt("matrix_bipolar_adjectives"));
128  $bipolar->setInfo($this->lng->txt("matrix_bipolar_adjectives_description"));
129 
130  // left pole
131  $bipolar1 = new ilTextInputGUI($this->lng->txt("matrix_left_pole"), "bipolar1");
132  $bipolar1->setRequired(false);
133  $bipolar->addSubItem($bipolar1);
134 
135  // right pole
136  $bipolar2 = new ilTextInputGUI($this->lng->txt("matrix_right_pole"), "bipolar2");
137  $bipolar2->setRequired(false);
138  $bipolar->addSubItem($bipolar2);
139 
140  $a_form->addItem($bipolar);
141 
142 
143  $header = new ilFormSectionHeaderGUI();
144  $header->setTitle($this->lng->txt("matrix_rows"));
145  $a_form->addItem($header);
146 
147  // matrix rows
148  include_once "./Modules/SurveyQuestionPool/classes/class.ilMatrixRowWizardInputGUI.php";
149  $rows = new ilMatrixRowWizardInputGUI("", "rows");
150  $rows->setRequired(false);
151  $rows->setAllowMove(true);
152  $rows->setLabelText($this->lng->txt('label'));
153  $rows->setUseOtherAnswer(true);
154  $a_form->addItem($rows);
155 
156 
157  // values
158  $subtype->setValue($this->object->getSubtype());
159  $column_separators->setChecked($this->object->getColumnSeparators());
160  $row_separators->setChecked($this->object->getRowSeparators());
161  $neutral_column_separator->setChecked($this->object->getNeutralColumnSeparator());
162 
163  if (!$this->object->getColumnCount())
164  {
165  $this->object->columns->addCategory("");
166  }
167  $columns->setValues($this->object->getColumns());
168 
169  $bipolar1->setValue($this->object->getBipolarAdjective(0));
170  $bipolar2->setValue($this->object->getBipolarAdjective(1));
171 
172  if ($this->object->getRowCount() == 0)
173  {
174  $this->object->getRows()->addCategory("");
175  }
176  $rows->setValues($this->object->getRows());
177  }
178 
179  protected function importEditFormValues(ilPropertyFormGUI $a_form)
180  {
181  $this->object->setSubtype($a_form->getInput("type"));
182  $this->object->setRowSeparators($a_form->getInput("row_separators") ? 1 : 0);
183  $this->object->setColumnSeparators($a_form->getInput("column_separators") ? 1 : 0);
184  $this->object->setNeutralColumnSeparator($a_form->getInput("neutral_column_separator") ? 1 : 0);
185 
186  // Set bipolar adjectives
187  $this->object->setBipolarAdjective(0, $a_form->getInput("bipolar1"));
188  $this->object->setBipolarAdjective(1, $a_form->getInput("bipolar2"));
189 
190  // set columns
191  $this->object->flushColumns();
192 
193  foreach ($_POST['columns']['answer'] as $key => $value)
194  {
195  if (strlen($value)) $this->object->getColumns()->addCategory($value, $_POST['columns']['other'][$key], 0, null, $_POST['columns']['scale'][$key]);
196  }
197  if (strlen($_POST["columns"]["neutral"]))
198  {
199  $this->object->getColumns()->addCategory($_POST['columns']['neutral'], 0, 1, null, $_POST['columns_neutral_scale']);
200  }
201 
202  // set rows
203  $this->object->flushRows();
204  foreach ($_POST['rows']['answer'] as $key => $value)
205  {
206  if (strlen($value)) $this->object->getRows()->addCategory($value, $_POST['rows']['other'][$key], 0, $_POST['rows']['label'][$key]);
207  }
208  }
209 
215  function getPrintView($question_title = 1, $show_questiontext = 1)
216  {
217  $layout = $this->object->getLayout();
218  $neutralstyle = "3px solid #808080";
219  $bordercolor = "#808080";
220  $template = new ilTemplate("tpl.il_svy_qpl_matrix_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
221 
222  if ($this->show_layout_row)
223  {
224  $layout_row = $this->getLayoutRow();
225  $template->setCurrentBlock("matrix_row");
226  $template->setVariable("ROW", $layout_row);
227  $template->parseCurrentBlock();
228  }
229 
230  $tplheaders = new ilTemplate("tpl.il_svy_out_matrix_columnheaders.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
231  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
232  {
233  $tplheaders->setCurrentBlock("bipolar_start");
234  $style = array();
235  array_push($style, sprintf("width: %.2F%s!important", $layout["percent_bipolar_adjective1"], "%"));
236  if (count($style) > 0)
237  {
238  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
239  }
240  $tplheaders->parseCurrentBlock();
241  }
242  // column headers
243  for ($i = 0; $i < $this->object->getColumnCount(); $i++)
244  {
245  $cat = $this->object->getColumn($i);
246  if ($cat->neutral)
247  {
248  $tplheaders->setCurrentBlock("neutral_column_header");
249  $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($cat->title));
250  $tplheaders->setVariable("CLASS", "rsep");
251  $style = array();
252  array_push($style, sprintf("width: %.2F%s!important", $layout["percent_neutral"], "%"));
253  if ($this->object->getNeutralColumnSeparator())
254  {
255  array_push($style, "border-left: $neutralstyle!important;");
256  }
257  if (count($style) > 0)
258  {
259  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
260  }
261  $tplheaders->parseCurrentBlock();
262  }
263  else
264  {
265  $style = array();
266  if ($this->object->getColumnSeparators() == 1)
267  {
268  if (($i < $this->object->getColumnCount() - 1))
269  {
270  array_push($style, "border-right: 1px solid $bordercolor!important");
271  }
272  }
273  array_push($style, sprintf("width: %.2F%s!important", $layout["percent_columns"] / $this->object->getColumnCount(), "%"));
274  $tplheaders->setCurrentBlock("column_header");
275  $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($cat->title));
276  $tplheaders->setVariable("CLASS", "center");
277  if (count($style) > 0)
278  {
279  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
280  }
281  $tplheaders->parseCurrentBlock();
282  }
283  }
284 
285  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
286  {
287  $tplheaders->setCurrentBlock("bipolar_end");
288  $style = array();
289  array_push($style, sprintf("width: %.2F%s!important", $layout["percent_bipolar_adjective2"], "%"));
290  if (count($style) > 0)
291  {
292  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
293  }
294  $tplheaders->parseCurrentBlock();
295  }
296 
297  $style = array();
298  array_push($style, sprintf("width: %.2F%s!important", $layout["percent_row"], "%"));
299  if (count($style) > 0)
300  {
301  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
302  }
303 
304  $template->setCurrentBlock("matrix_row");
305  $template->setVariable("ROW", $tplheaders->get());
306  $template->parseCurrentBlock();
307 
308  $rowclass = array("tblrow1", "tblrow2");
309 
310  for ($i = 0; $i < $this->object->getRowCount(); $i++)
311  {
312  $rowobj = $this->object->getRow($i);
313  $tplrow = new ilTemplate("tpl.il_svy_qpl_matrix_printview_row.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
314  for ($j = 0; $j < $this->object->getColumnCount(); $j++)
315  {
316  $cat = $this->object->getColumn($j);
317  if (($i == 0) && ($j == 0))
318  {
319  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
320  {
321  $tplrow->setCurrentBlock("bipolar_start");
322  $tplrow->setVariable("TEXT_BIPOLAR_START", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(0)));
323  $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
324  $tplrow->parseCurrentBlock();
325  }
326  }
327  if (($i == 0) && ($j == $this->object->getColumnCount()-1))
328  {
329  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
330  {
331  $tplrow->setCurrentBlock("bipolar_end");
332  $tplrow->setVariable("TEXT_BIPOLAR_END", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(1)));
333  $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
334  $tplrow->parseCurrentBlock();
335  }
336  }
337  switch ($this->object->getSubtype())
338  {
339  case 0:
340  if ($cat->neutral)
341  {
342  $tplrow->setCurrentBlock("neutral_radiobutton");
343  $tplrow->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
344  $tplrow->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
345  $tplrow->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
346  $tplrow->parseCurrentBlock();
347  }
348  else
349  {
350  $tplrow->setCurrentBlock("radiobutton");
351  $tplrow->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
352  $tplrow->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
353  $tplrow->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
354  $tplrow->parseCurrentBlock();
355  }
356  break;
357  case 1:
358  if ($cat->neutral)
359  {
360  $tplrow->setCurrentBlock("neutral_checkbox");
361  $tplrow->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.png")));
362  $tplrow->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
363  $tplrow->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
364  $tplrow->parseCurrentBlock();
365  }
366  else
367  {
368  $tplrow->setCurrentBlock("checkbox");
369  $tplrow->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.png")));
370  $tplrow->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
371  $tplrow->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
372  $tplrow->parseCurrentBlock();
373  }
374  break;
375  }
376  if ($cat->neutral)
377  {
378  $tplrow->setCurrentBlock("neutral_answer");
379  $style = array();
380  if ($this->object->getNeutralColumnSeparator())
381  {
382  array_push($style, "border-left: $neutralstyle!important");
383  }
384  if ($this->object->getColumnSeparators() == 1)
385  {
386  if ($j < $this->object->getColumnCount() - 1)
387  {
388  array_push($style, "border-right: 1px solid $bordercolor!important");
389  }
390  }
391 
392  if ($this->object->getRowSeparators() == 1)
393  {
394  if ($i < $this->object->getRowCount() - 1)
395  {
396  array_push($style, "border-bottom: 1px solid $bordercolor!important");
397  }
398  }
399  if (count($style))
400  {
401  $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
402  }
403  $tplrow->parseCurrentBlock();
404  }
405  else
406  {
407  $tplrow->setCurrentBlock("answer");
408  $style = array();
409 
410  if ($this->object->getColumnSeparators() == 1)
411  {
412  if ($j < $this->object->getColumnCount() - 1)
413  {
414  array_push($style, "border-right: 1px solid $bordercolor!important");
415  }
416  }
417 
418  if ($this->object->getRowSeparators() == 1)
419  {
420  if ($i < $this->object->getRowCount() - 1)
421  {
422  array_push($style, "border-bottom: 1px solid $bordercolor!important");
423  }
424  }
425  if (count($style))
426  {
427  $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
428  }
429  $tplrow->parseCurrentBlock();
430  }
431  }
432 
433  if ($rowobj->other)
434  {
435  $tplrow->setCurrentBlock("text_other");
436  $tplrow->setVariable("TEXT_OTHER", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
437  $tplrow->parseCurrentBlock();
438  }
439 
440  $tplrow->setVariable("TEXT_ROW", ilUtil::prepareFormOutput($rowobj->title));
441  $tplrow->setVariable("ROWCLASS", $rowclass[$i % 2]);
442  if ($this->object->getRowSeparators() == 1)
443  {
444  if ($i < $this->object->getRowCount() - 1)
445  {
446  $tplrow->setVariable("STYLE", " style=\"border-bottom: 1px solid $bordercolor!important\"");
447  }
448  }
449  $template->setCurrentBlock("matrix_row");
450  $template->setVariable("ROW", $tplrow->get());
451  $template->parseCurrentBlock();
452  }
453 
454  if ($question_title)
455  {
456  $template->setVariable("QUESTION_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
457  }
458  $template->setCurrentBlock();
459  if ($show_questiontext)
460  {
461  $this->outQuestionText($template);
462  }
463  $template->parseCurrentBlock();
464  return $template->get();
465  }
466 
467 
468  //
469  // LAYOUT
470  //
471 
477  function layout()
478  {
479  global $ilTabs;
480 
481  $ilTabs->activateTab("layout");
482 
483  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_layout.html", "Modules/SurveyQuestionPool");
484  $this->show_layout_row = TRUE;
485  $question_output = $this->getWorkingForm();
486  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
487  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "saveLayout"));
488  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
489  }
490 
496  function saveLayout()
497  {
498  $percent_values = array(
499  "percent_row" => (int)$_POST["percent_row"],
500  "percent_columns" => (int)$_POST["percent_columns"],
501  "percent_bipolar_adjective1" => (int)$_POST['percent_bipolar_adjective1'],
502  "percent_bipolar_adjective2" => (int)$_POST['percent_bipolar_adjective2'],
503  "percent_neutral" => (int)$_POST["percent_neutral"]
504  );
505  $this->object->setLayout($percent_values);
506 
507  // #9364
508  if(array_sum($percent_values) == 100)
509  {
510  $this->object->saveLayout($percent_values["percent_row"],
511  $percent_values['percent_columns'],
512  $percent_values['percent_bipolar_adjective1'],
513  $percent_values['percent_bipolar_adjective2'],
514  $percent_values["percent_neutral"]);
515  ilUtil::sendSuccess($this->lng->txt("settings_saved"));
516  }
517  else
518  {
519  ilUtil::sendFailure($this->lng->txt("svy_matrix_layout_percentages_sum_invalid"));
520  }
521  $this->layout();
522  }
523 
529  function getLayoutRow()
530  {
531  $percent_values = $this->object->getLayout();
532  $template = new ilTemplate("tpl.il_svy_out_matrix_layout.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
533  if (strlen($this->object->getBipolarAdjective(0)) && strlen($this->object->getBipolarAdjective(1)))
534  {
535  $template->setCurrentBlock("bipolar_start");
536  $template->setVariable("VALUE_PERCENT_BIPOLAR_ADJECTIVE1", " value=\"" . $percent_values["percent_bipolar_adjective1"] . "\"");
537  $template->setVariable("STYLE", " style=\"width:" . $percent_values["percent_bipolar_adjective1"] . "%\"");
538  $template->parseCurrentBlock();
539  $template->setCurrentBlock("bipolar_end");
540  $template->setVariable("VALUE_PERCENT_BIPOLAR_ADJECTIVE2", " value=\"" . $percent_values["percent_bipolar_adjective2"] . "\"");
541  $template->setVariable("STYLE", " style=\"width:" . $percent_values["percent_bipolar_adjective2"] . "%\"");
542  $template->parseCurrentBlock();
543  }
544  $counter = $this->object->getColumnCount();
545  if (strlen($this->object->hasNeutralColumn()))
546  {
547  $template->setCurrentBlock("neutral_start");
548  $template->setVariable("VALUE_PERCENT_NEUTRAL", " value=\"" . $percent_values["percent_neutral"] . "\"");
549  $template->setVariable("STYLE_NEUTRAL", " style=\"width:" . $percent_values["percent_neutral"] . "%\"");
550  $template->parseCurrentBlock();
551  $counter--;
552  }
553  $template->setVariable("VALUE_PERCENT_ROW", " value=\"" . $percent_values["percent_row"] . "\"");
554  $template->setVariable("STYLE_ROW", " style=\"width:" . $percent_values["percent_row"] . "%\"");
555  $template->setVariable("COLSPAN_COLUMNS", $counter);
556  $template->setVariable("VALUE_PERCENT_COLUMNS", " value=\"" . $percent_values["percent_columns"] . "\"");
557  $template->setVariable("STYLE_COLUMNS", " style=\"width:" . $percent_values["percent_columns"] . "%\"");
558  return $template->get();
559  }
560 
561 
562  //
563  // EXECUTION
564  //
565 
571  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
572  {
573  $layout = $this->object->getLayout();
574  $neutralstyle = "3px solid #808080";
575  $bordercolor = "#808080";
576  $template = new ilTemplate("tpl.il_svy_out_matrix.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
577  $template->setCurrentBlock("material_matrix");
578  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
579  $template->parseCurrentBlock();
580 
581  if ($this->show_layout_row)
582  {
583  $layout_row = $this->getLayoutRow();
584  $template->setCurrentBlock("matrix_row");
585  $template->setVariable("ROW", $layout_row);
586  $template->parseCurrentBlock();
587  }
588 
589  $tplheaders = new ilTemplate("tpl.il_svy_out_matrix_columnheaders.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
590  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
591  {
592  $tplheaders->setCurrentBlock("bipolar_start");
593  $style = array();
594  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective1"], "%"));
595  if (count($style) > 0)
596  {
597  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
598  }
599  $tplheaders->parseCurrentBlock();
600  }
601  // column headers
602  for ($i = 0; $i < $this->object->getColumnCount(); $i++)
603  {
604  $style = array();
605  $col = $this->object->getColumn($i);
606  if ($col->neutral)
607  {
608  $tplheaders->setCurrentBlock("neutral_column_header");
609  $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($col->title));
610  $tplheaders->setVariable("CLASS", "rsep");
611  $style = array();
612  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_neutral"], "%"));
613  if ($this->object->getNeutralColumnSeparator())
614  {
615  array_push($style, "border-left: $neutralstyle!important;");
616  }
617  if (count($style) > 0)
618  {
619  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
620  }
621  $tplheaders->parseCurrentBlock();
622  }
623  else
624  {
625  if ($this->object->getColumnSeparators() == 1)
626  {
627  if (($i < $this->object->getColumnCount() - 1))
628  {
629  array_push($style, "border-right: 1px solid $bordercolor!important");
630  }
631  }
632  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_columns"] / $this->object->getColumnCount(), "%"));
633  $tplheaders->setCurrentBlock("column_header");
634  $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($col->title));
635  $tplheaders->setVariable("CLASS", "center");
636  if (count($style) > 0)
637  {
638  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
639  }
640  $tplheaders->parseCurrentBlock();
641  }
642  }
643  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
644  {
645  $tplheaders->setCurrentBlock("bipolar_end");
646  $style = array();
647  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective2"], "%"));
648  if (count($style) > 0)
649  {
650  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
651  }
652  $tplheaders->parseCurrentBlock();
653  }
654 
655  $style = array();
656  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_row"], "%"));
657  if (count($style) > 0)
658  {
659  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
660  }
661 
662  $template->setCurrentBlock("matrix_row");
663  $template->setVariable("ROW", $tplheaders->get());
664  $template->parseCurrentBlock();
665 
666  $rowclass = array("tblrow1", "tblrow2");
667  for ($i = 0; $i < $this->object->getRowCount(); $i++)
668  {
669  $rowobj = $this->object->getRow($i);
670  $tplrow = new ilTemplate("tpl.il_svy_out_matrix_row.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
671  for ($j = 0; $j < $this->object->getColumnCount(); $j++)
672  {
673  $cat = $this->object->getColumn($j);
674  if (($i == 0) && ($j == 0))
675  {
676  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
677  {
678  $tplrow->setCurrentBlock("bipolar_start");
679  $tplrow->setVariable("TEXT_BIPOLAR_START", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(0)));
680  $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
681  $tplrow->parseCurrentBlock();
682  }
683  }
684  if (($i == 0) && ($j == $this->object->getColumnCount()-1))
685  {
686  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
687  {
688  $tplrow->setCurrentBlock("bipolar_end");
689  $tplrow->setVariable("TEXT_BIPOLAR_END", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(1)));
690  $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
691  $tplrow->parseCurrentBlock();
692  }
693  }
694  switch ($this->object->getSubtype())
695  {
696  case 0:
697  if ($cat->neutral)
698  {
699  $tplrow->setCurrentBlock("neutral_radiobutton");
700  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
701  $tplrow->setVariable("ROW", $i);
702  $tplrow->setVariable("VALUE", ($cat->scale) ? ($cat->scale - 1) : $j);
703  if (is_array($working_data))
704  {
705  foreach ($working_data as $data)
706  {
707  if (($data["value"] == $cat->scale-1) && ($data["rowvalue"] == $i))
708  {
709  $tplrow->setVariable("CHECKED_RADIOBUTTON", " checked=\"checked\"");
710  }
711  }
712  }
713  $tplrow->parseCurrentBlock();
714  }
715  else
716  {
717  $tplrow->setCurrentBlock("radiobutton");
718  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
719  $tplrow->setVariable("ROW", $i);
720  $tplrow->setVariable("VALUE", ($cat->scale) ? ($cat->scale - 1) : $j);
721  if (is_array($working_data))
722  {
723  foreach ($working_data as $data)
724  {
725  if (($data["value"] == $cat->scale-1) && ($data["rowvalue"] == $i))
726  {
727  $tplrow->setVariable("CHECKED_RADIOBUTTON", " checked=\"checked\"");
728  }
729  }
730  }
731  $tplrow->parseCurrentBlock();
732  }
733  break;
734  case 1:
735  if ($cat->neutral)
736  {
737  $tplrow->setCurrentBlock("neutral_checkbox");
738  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
739  $tplrow->setVariable("ROW", $i);
740  $tplrow->setVariable("VALUE", ($cat->scale) ? ($cat->scale - 1) : $j);
741  if (is_array($working_data))
742  {
743  foreach ($working_data as $data)
744  {
745  if (($data["value"] == $cat->scale-1) && ($data["rowvalue"] == $i))
746  {
747  $tplrow->setVariable("CHECKED_CHECKBOX", " checked=\"checked\"");
748  }
749  }
750  }
751  $tplrow->parseCurrentBlock();
752  }
753  else
754  {
755  $tplrow->setCurrentBlock("checkbox");
756  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
757  $tplrow->setVariable("ROW", $i);
758  $tplrow->setVariable("VALUE", ($cat->scale) ? ($cat->scale - 1) : $j);
759  if (is_array($working_data))
760  {
761  foreach ($working_data as $data)
762  {
763  if (($data["value"] == $cat->scale-1) && ($data["rowvalue"] == $i))
764  {
765  $tplrow->setVariable("CHECKED_CHECKBOX", " checked=\"checked\"");
766  }
767  }
768  }
769  $tplrow->parseCurrentBlock();
770  }
771  break;
772  }
773  if ($cat->neutral)
774  {
775  $tplrow->setCurrentBlock("neutral_answer");
776  $style = array();
777  if ($this->object->getNeutralColumnSeparator())
778  {
779  array_push($style, "border-left: $neutralstyle!important");
780  }
781  if ($this->object->getColumnSeparators() == 1)
782  {
783  if ($j < $this->object->getColumnCount() - 1)
784  {
785  array_push($style, "border-right: 1px solid $bordercolor!important");
786  }
787  }
788  }
789  else
790  {
791  $tplrow->setCurrentBlock("answer");
792  $style = array();
793 
794  if ($this->object->getColumnSeparators() == 1)
795  {
796  if ($j < $this->object->getColumnCount() - 1)
797  {
798  array_push($style, "border-right: 1px solid $bordercolor!important");
799  }
800  }
801  }
802  if ($this->object->getRowSeparators() == 1)
803  {
804  if ($i < $this->object->getRowCount() - 1)
805  {
806  array_push($style, "border-bottom: 1px solid $bordercolor!important");
807  }
808  }
809  if (count($style))
810  {
811  $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
812  }
813  $tplrow->parseCurrentBlock();
814  }
815 
816  if ($rowobj->other)
817  {
818  $tplrow->setCurrentBlock("row_other");
819  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
820  $tplrow->setVariable("ROW", $i);
821  if (is_array($working_data))
822  {
823  foreach ($working_data as $data)
824  {
825  if ($data["rowvalue"] == $i)
826  {
827  $tplrow->setVariable("VALUE_OTHER", ilUtil::prepareFormOutput($data['textanswer']));
828  }
829  }
830  }
831  $tplrow->parseCurrentBlock();
832  }
833  $tplrow->setVariable("TEXT_ROW", ilUtil::prepareFormOutput($rowobj->title));
834  $tplrow->setVariable("ROWCLASS", $rowclass[$i % 2]);
835  if ($this->object->getRowSeparators() == 1)
836  {
837  if ($i < $this->object->getRowCount() - 1)
838  {
839  $tplrow->setVariable("STYLE", " style=\"border-bottom: 1px solid $bordercolor!important\"");
840  }
841  }
842  $template->setCurrentBlock("matrix_row");
843  $template->setVariable("ROW", $tplrow->get());
844  $template->parseCurrentBlock();
845  }
846 
847  if ($question_title)
848  {
849  $template->setVariable("QUESTION_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
850  }
851  $template->setCurrentBlock("question_data_matrix");
852  if (strcmp($error_message, "") != 0)
853  {
854  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
855  }
856  if ($show_questiontext)
857  {
858  $this->outQuestionText($template);
859  }
860  $template->parseCurrentBlock();
861  return $template->get();
862  }
863 
864 
865  //
866  // EVALUATION
867  //
868 
877  function getCumulatedResultsDetails($survey_id, $counter, $finished_ids)
878  {
879  if (count($this->cumulated) == 0)
880  {
881  if(!$finished_ids)
882  {
883  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
884  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
885  }
886  else
887  {
888  $nr_of_users = sizeof($finished_ids);
889  }
890  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users, $finished_ids);
891  }
892 
893  $cumulated_count = 0;
894  foreach ($this->cumulated as $key => $value)
895  {
896  if (is_numeric($key))
897  {
898  $cumulated_count++;
899  }
900  }
901 
902  $output = "";
903 
904  include_once "./Services/UICore/classes/class.ilTemplate.php";
905  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
906 
907  $template->setCurrentBlock("detail_row");
908  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
909  $questiontext = $this->object->getQuestiontext();
910  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
911  $template->parseCurrentBlock();
912  $template->setCurrentBlock("detail_row");
913  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
914  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()).
915  " (".$cumulated_count." ".$this->lng->txt("rows").")");
916  $template->parseCurrentBlock();
917  $template->setCurrentBlock("detail_row");
918  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
919  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["USERS_ANSWERED"]);
920  $template->parseCurrentBlock();
921  $template->setCurrentBlock("detail_row");
922  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
923  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["USERS_SKIPPED"]);
924  $template->parseCurrentBlock();
925  /*
926  $template->setCurrentBlock("detail_row");
927  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
928  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["MODE"]);
929  $template->parseCurrentBlock();
930  $template->setCurrentBlock("detail_row");
931  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
932  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["MODE_NR_OF_SELECTIONS"]);
933  $template->parseCurrentBlock();
934  */
935  $template->setCurrentBlock("detail_row");
936  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
937  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["MEDIAN"]);
938  $template->parseCurrentBlock();
939 
940  $template->setCurrentBlock("detail_row");
941  $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
942  $columns = "";
943  foreach ($this->cumulated["TOTAL"]["variables"] as $key => $value)
944  {
945  $columns .= "<li>" . $value["title"] . ": n=" . $value["selected"] .
946  " (" . sprintf("%.2f", 100*$value["percentage"]) . "%)</li>";
947  }
948  $columns = "<ol>$columns</ol>";
949  $template->setVariable("TEXT_OPTION_VALUE", $columns);
950  $template->parseCurrentBlock();
951 
952  // total chart
953  $template->setCurrentBlock("detail_row");
954  $template->setVariable("TEXT_OPTION", $this->lng->txt("chart"));
955  $template->setVariable("TEXT_OPTION_VALUE", $this->renderChart("svy_ch_".$this->object->getId()."_total", $this->cumulated["TOTAL"]["variables"]));
956  $template->parseCurrentBlock();
957 
958  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
959 
960  $output .= $template->get();
961 
962  foreach ($this->cumulated as $key => $value)
963  {
964  if (is_numeric($key))
965  {
966  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
967 
968  $template->setCurrentBlock("detail_row");
969  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
970  $template->setVariable("TEXT_OPTION_VALUE", $value["USERS_ANSWERED"]);
971  $template->parseCurrentBlock();
972  $template->setCurrentBlock("detail_row");
973  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
974  $template->setVariable("TEXT_OPTION_VALUE", $value["USERS_SKIPPED"]);
975  $template->parseCurrentBlock();
976  /*
977  $template->setCurrentBlock("detail_row");
978  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
979  $template->setVariable("TEXT_OPTION_VALUE", $value["MODE"]);
980  $template->parseCurrentBlock();
981  $template->setCurrentBlock("detail_row");
982  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
983  $template->setVariable("TEXT_OPTION_VALUE", $value["MODE_NR_OF_SELECTIONS"]);
984  $template->parseCurrentBlock();
985  */
986  $template->setCurrentBlock("detail_row");
987  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
988  $template->setVariable("TEXT_OPTION_VALUE", $value["MEDIAN"]);
989  $template->parseCurrentBlock();
990 
991  $template->setCurrentBlock("detail_row");
992  $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
993  $columns = "";
994  foreach ($value["variables"] as $cvalue)
995  {
996  $columns .= "<li>" . $cvalue["title"] . ": n=". $cvalue["selected"] .
997  " (".sprintf("%.2f", 100*$cvalue["percentage"]) . "%)</li>";
998  }
999  $columns = "<ol>".$columns."</ol>";
1000  $template->setVariable("TEXT_OPTION_VALUE", $columns);
1001  $template->parseCurrentBlock();
1002 
1003  // add text answers to detailed results
1004  if (is_array($value["textanswers"]))
1005  {
1006  $template->setCurrentBlock("detail_row");
1007  $template->setVariable("TEXT_OPTION", $this->lng->txt("freetext_answers"));
1008  $html = "";
1009  foreach ($value["textanswers"] as $tkey => $answers)
1010  {
1011  $html .= $value["variables"][$tkey]["title"] ."\n";
1012  $html .= "<ul>\n";
1013  foreach ($answers as $answer)
1014  {
1015  $html .= "<li>" . preg_replace("/\n/", "<br>\n", $answer) . "</li>\n";
1016  }
1017  $html .= "</ul>\n";
1018  }
1019  $template->setVariable("TEXT_OPTION_VALUE", $html);
1020  $template->parseCurrentBlock();
1021  }
1022 
1023  // chart
1024  $template->setCurrentBlock("detail_row");
1025  $template->setVariable("TEXT_OPTION", $this->lng->txt("chart"));
1026  $template->setVariable("TEXT_OPTION_VALUE", $this->renderChart("svy_ch_".$this->object->getId()."_".$key, $value["variables"]));
1027  $template->parseCurrentBlock();
1028 
1029  $template->setVariable("QUESTION_SUBTITLE", $counter.".".($key+1)." ".
1030  $this->object->prepareTextareaOutput($value["ROW"], TRUE));
1031 
1032  $output .= $template->get();
1033  }
1034  }
1035 
1036  return $output;
1037  }
1038 }
1039 
1040 ?>