ILIAS  release_4-3 Revision
 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 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
26 
39 {
41 
51  $id = -1
52  )
53 
54  {
55  $this->SurveyQuestionGUI();
56  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyMatrixQuestion.php";
57  $this->object = new SurveyMatrixQuestion();
58  $this->show_layout_row = FALSE;
59  if ($id >= 0)
60  {
61  $this->object->loadFromDb($id);
62  }
63  }
64 
68  function &executeCommand()
69  {
70  $cmd = $this->ctrl->getCmd();
71  $next_class = $this->ctrl->getNextClass($this);
72 
73  $cmd = $this->getCommand($cmd);
74  switch($next_class)
75  {
76  default:
77  $ret =& $this->$cmd();
78  break;
79  }
80  return $ret;
81  }
82 
89  function writePostData($always = false)
90  {
91  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
92  if (!$hasErrors)
93  {
94  $this->object->setTitle($_POST["title"]);
95  $this->object->label = $_POST['label'];
96  $this->object->setAuthor($_POST["author"]);
97  $this->object->setDescription($_POST["description"]);
98  $questiontext = $_POST["question"];
99  $this->object->setQuestiontext($questiontext);
100  $this->object->setObligatory(($_POST["obligatory"]) ? 1 : 0);
101  $this->object->setSubtype($_POST["type"]);
102  $this->object->setRowSeparators(($_POST["row_separators"]) ? 1 : 0);
103  $this->object->setColumnSeparators(($_POST["column_separators"]) ? 1 : 0);
104  $this->object->setNeutralColumnSeparator(($_POST["neutral_column_separator"]) ? 1 : 0);
105  // Set bipolar adjectives
106  $this->object->setBipolarAdjective(0, $_POST["bipolar1"]);
107  $this->object->setBipolarAdjective(1, $_POST["bipolar2"]);
108  // set columns
109  $this->object->flushColumns();
110  foreach ($_POST['columns']['answer'] as $key => $value)
111  {
112  if (strlen($value)) $this->object->getColumns()->addCategory($value, $_POST['columns']['other'][$key], 0, null, $_POST['columns']['scale'][$key]);
113  }
114  if (strlen($_POST["columns"]["neutral"]))
115  {
116  $this->object->getColumns()->addCategory($_POST['columns']['neutral'], 0, 1, null, $_POST['columns_neutral_scale']);
117  }
118  // set rows
119  $this->object->flushRows();
120  foreach ($_POST['rows']['answer'] as $key => $value)
121  {
122  if (strlen($value)) $this->object->getRows()->addCategory($value, $_POST['rows']['other'][$key], 0, $_POST['rows']['label'][$key]);
123  }
124  return 0;
125  }
126  else
127  {
128  return 1;
129  }
130  }
131 
137  public function editQuestion($checkonly = FALSE)
138  {
139  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
140  $form = new ilPropertyFormGUI();
141  $form->setFormAction($this->ctrl->getFormAction($this));
142  $form->setTitle($this->lng->txt($this->getQuestionType()));
143  $form->setMultipart(FALSE);
144  $form->setTableWidth("100%");
145  $form->setId("multiplechoice");
146 
147  // title
148  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
149  $title->setValue($this->object->getTitle());
150  $title->setRequired(TRUE);
151  $form->addItem($title);
152 
153  // label
154  $label = new ilTextInputGUI($this->lng->txt("label"), "label");
155  $label->setValue($this->object->label);
156  $label->setInfo($this->lng->txt("label_info"));
157  $label->setRequired(false);
158  $form->addItem($label);
159 
160  // author
161  $author = new ilTextInputGUI($this->lng->txt("author"), "author");
162  $author->setValue($this->object->getAuthor());
163  $author->setRequired(TRUE);
164  $form->addItem($author);
165 
166  // description
167  $description = new ilTextInputGUI($this->lng->txt("description"), "description");
168  $description->setValue($this->object->getDescription());
169  $description->setRequired(FALSE);
170  $form->addItem($description);
171 
172  // questiontext
173  $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
174  $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestiontext()));
175  $question->setRequired(TRUE);
176  $question->setRows(10);
177  $question->setCols(80);
178  $question->setUseRte(TRUE);
179  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
180  $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
181  $question->addPlugin("latex");
182  $question->addButton("latex");
183  $question->addButton("pastelatex");
184  $question->setRTESupport($this->object->getId(), "spl", "survey", null, false, "3.4.7");
185  $form->addItem($question);
186 
187  // subtype
188  $subtype = new ilRadioGroupInputGUI($this->lng->txt("subtype"), "type");
189  $subtype->setRequired(false);
190  $subtype->setValue($this->object->getSubtype());
191  $subtypes = array(
192  "0" => "matrix_subtype_sr",
193  "1" => "matrix_subtype_mr",
194  //"2" => "matrix_subtype_text",
195  //"3" => "matrix_subtype_integer",
196  //"4" => "matrix_subtype_double",
197  //"5" => "matrix_subtype_date",
198  //"6" => "matrix_subtype_time"
199  );
200  foreach ($subtypes as $idx => $st)
201  {
202  $subtype->addOption(new ilRadioOption($this->lng->txt($st), $idx));
203  }
204  $form->addItem($subtype);
205 
206  // obligatory
207  $shuffle = new ilCheckboxInputGUI($this->lng->txt("obligatory"), "obligatory");
208  $shuffle->setValue(1);
209  $shuffle->setChecked($this->object->getObligatory());
210  $shuffle->setRequired(FALSE);
211  $form->addItem($shuffle);
212 
213  $header = new ilFormSectionHeaderGUI();
214  $header->setTitle($this->lng->txt("matrix_appearance"));
215  $form->addItem($header);
216 
217  // column separators
218  $column_separators = new ilCheckboxInputGUI($this->lng->txt("matrix_column_separators"), "column_separators");
219  $column_separators->setValue(1);
220  $column_separators->setInfo($this->lng->txt("matrix_column_separators_description"));
221  $column_separators->setChecked($this->object->getColumnSeparators());
222  $column_separators->setRequired(false);
223  $form->addItem($column_separators);
224 
225  // row separators
226  $row_separators = new ilCheckboxInputGUI($this->lng->txt("matrix_row_separators"), "row_separators");
227  $row_separators->setValue(1);
228  $row_separators->setInfo($this->lng->txt("matrix_row_separators_description"));
229  $row_separators->setChecked($this->object->getRowSeparators());
230  $row_separators->setRequired(false);
231  $form->addItem($row_separators);
232 
233  // neutral column separators
234  $neutral_column_separator = new ilCheckboxInputGUI($this->lng->txt("matrix_neutral_column_separator"), "neutral_column_separator");
235  $neutral_column_separator->setValue(1);
236  $neutral_column_separator->setInfo($this->lng->txt("matrix_neutral_column_separator_description"));
237  $neutral_column_separator->setChecked($this->object->getNeutralColumnSeparator());
238  $neutral_column_separator->setRequired(false);
239  $form->addItem($neutral_column_separator);
240 
241  $header = new ilFormSectionHeaderGUI();
242  $header->setTitle($this->lng->txt("matrix_columns"));
243  $form->addItem($header);
244 
245  // Answers
246  include_once "./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
247  $columns = new ilCategoryWizardInputGUI("", "columns");
248  $columns->setRequired(false);
249  $columns->setAllowMove(true);
250  $columns->setShowWizard(true);
251  $columns->setShowNeutralCategory(true);
252  $columns->setDisabledScale(false);
253  $columns->setNeutralCategoryTitle($this->lng->txt('matrix_neutral_answer'));
254  $columns->setCategoryText($this->lng->txt('matrix_standard_answers'));
255  $columns->setShowSavePhrase(true);
256  if (!$this->object->getColumnCount())
257  {
258  $this->object->columns->addCategory("");
259  }
260  $columns->setValues($this->object->getColumns());
261  $form->addItem($columns);
262 
263  $header = new ilFormSectionHeaderGUI();
264  $header->setTitle($this->lng->txt("matrix_column_settings"));
265  $form->addItem($header);
266 
267  // bipolar adjectives
268  $bipolar = new ilCustomInputGUI($this->lng->txt("matrix_bipolar_adjectives"));
269  $bipolar->setInfo($this->lng->txt("matrix_bipolar_adjectives_description"));
270 
271  // left pole
272  $bipolar1 = new ilTextInputGUI($this->lng->txt("matrix_left_pole"), "bipolar1");
273  $bipolar1->setValue($this->object->getBipolarAdjective(0));
274  $bipolar1->setRequired(false);
275  $bipolar->addSubItem($bipolar1);
276 
277  // right pole
278  $bipolar2 = new ilTextInputGUI($this->lng->txt("matrix_right_pole"), "bipolar2");
279  $bipolar2->setValue($this->object->getBipolarAdjective(1));
280  $bipolar2->setRequired(false);
281  $bipolar->addSubItem($bipolar2);
282 
283  $form->addItem($bipolar);
284 
285  $header = new ilFormSectionHeaderGUI();
286  $header->setTitle($this->lng->txt("matrix_rows"));
287  $form->addItem($header);
288 
289  // matrix rows
290  include_once "./Modules/SurveyQuestionPool/classes/class.ilMatrixRowWizardInputGUI.php";
291  $rows = new ilMatrixRowWizardInputGUI("", "rows");
292  $rows->setRequired(false);
293  $rows->setAllowMove(true);
294  $rows->setLabelText($this->lng->txt('label'));
295  $rows->setUseOtherAnswer(true);
296  if ($this->object->getRowCount() == 0)
297  {
298  $this->object->getRows()->addCategory("");
299  }
300  $rows->setValues($this->object->getRows());
301  $form->addItem($rows);
302 
303  $this->addCommandButtons($form);
304 
305  $errors = false;
306 
307  if ($this->isSaveCommand(array("wizardcolumns", "savePhrasecolumns")))
308  {
309  $form->setValuesByPost();
310  $errors = !$form->checkInput();
311  $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
312  if ($errors) $checkonly = false;
313  }
314 
315  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
316  return $errors;
317  }
318 
322  public function addrows()
323  {
324  $this->writePostData(true);
325  $position = key($_POST['cmd']['addrows']);
326  $this->object->addRowAtPosition("", false, $position+1);
327  $this->editQuestion();
328  }
329 
333  public function removerows()
334  {
335  $this->writePostData(true);
336  $position = key($_POST['cmd']['removerows']);
337  $this->object->removeRow($position);
338  $this->editQuestion();
339  }
340 
344  public function uprows()
345  {
346  $this->writePostData(true);
347  $position = key($_POST['cmd']['uprows']);
348  $this->object->moveRowUp($position);
349  $this->editQuestion();
350  }
351 
355  public function downrows()
356  {
357  $this->writePostData(true);
358  $position = key($_POST['cmd']['downrows']);
359  $this->object->moveRowDown($position);
360  $this->editQuestion();
361  }
362 
366  public function addcolumns()
367  {
368  $this->writePostData(true);
369  $position = key($_POST['cmd']['addcolumns']);
370  $this->object->getColumns()->addCategoryAtPosition("", $position+1);
371  $this->editQuestion();
372  }
373 
377  public function removecolumns()
378  {
379  $this->writePostData(true);
380  $position = key($_POST['cmd']['removecolumns']);
381  $this->object->getColumns()->removeCategory($position);
382  $this->editQuestion();
383  }
384 
388  public function upcolumns()
389  {
390  $this->writePostData(true);
391  $position = key($_POST['cmd']['upcolumns']);
392  $this->object->getColumns()->moveCategoryUp($position);
393  $this->editQuestion();
394  }
395 
399  public function downcolumns()
400  {
401  $this->writePostData(true);
402  $position = key($_POST['cmd']['downcolumns']);
403  $this->object->getColumns()->moveCategoryDown($position);
404  $this->editQuestion();
405  }
406 
412  function savePhrasecolumns($haserror = false)
413  {
414  if (!$haserror) $result = $this->writePostData();
415  if ($result == 0 || $haserror)
416  {
417  if (!$haserror) $this->object->saveToDb();
418 
419  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_savephrase.html", "Modules/SurveyQuestionPool");
420  $this->tpl->setCurrentBlock("adm_content");
421  $this->tpl->setVariable("SAVE_PHRASE_INTRODUCTION", $this->lng->txt("save_phrase_introduction"));
422  $this->tpl->setVariable("TEXT_PHRASE_TITLE", $this->lng->txt("enter_phrase_title"));
423  $this->tpl->setVariable("VALUE_PHRASE_TITLE", $_POST["phrase_title"]);
424  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
425  $this->tpl->setVariable("BTN_CONFIRM",$this->lng->txt("confirm"));
426  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
427 
428  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveySavePhraseTableGUI.php";
429  $table_gui = new ilSurveySavePhraseTableGUI($this, 'editQuestion');
430 
431  $data = array();
432  if (!$haserror)
433  {
434  foreach ($_POST['columns']['answer'] as $key => $value)
435  {
436  array_push($data, array('answer' => $value, 'other' => (($_POST['columns']['other'][$key]) ? true : false), 'scale' => $_POST['columns']['scale'][$key], 'neutral' => false));
437  }
438  if (strlen($_POST['columns']['neutral']))
439  {
440  array_push($data, array('answer' => $_POST['columns']['neutral'], 'other' => false, 'scale' => $_POST['columns_neutral_scale'], 'neutral' => true));
441  }
442  }
443  else
444  {
445  $data = $_SESSION['save_phrase_data'];
446  }
447  $table_gui->setData($data);
448  $_SESSION['save_phrase_data'] = $data;
449  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
450  $this->tpl->parseCurrentBlock();
451  }
452  }
453 
459  function cancelSavePhrase()
460  {
461  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
462  $this->ctrl->redirect($this, "editQuestion");
463  }
464 
470  function confirmSavePhrase()
471  {
472  if (!$_POST["phrase_title"])
473  {
474  ilUtil::sendInfo($this->lng->txt("qpl_savephrase_empty"));
475  $this->savePhrasecolumns(true);
476  return;
477  }
478 
479  if ($this->object->phraseExists($_POST["phrase_title"]))
480  {
481  ilUtil::sendInfo($this->lng->txt("qpl_savephrase_exists"));
482  $this->savePhrasecolumns(true);
483  return;
484  }
485 
486  $this->object->savePhrase($_POST["phrase_title"]);
487  ilUtil::sendSuccess($this->lng->txt("phrase_saved"), true);
488  $this->ctrl->redirect($this, "editQuestion");
489  }
490 
496  function wizardcolumns($save_post_data = true)
497  {
498  if ($save_post_data) $result = $this->writePostData();
499  if ($result == 0)
500  {
501  if ($save_post_data) $this->object->saveToDb();
502  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase.html", "Modules/SurveyQuestionPool");
503 
504  // set the id to return to the selected question
505  $this->tpl->setCurrentBlock("hidden");
506  $this->tpl->setVariable("HIDDEN_NAME", "id");
507  $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
508  $this->tpl->parseCurrentBlock();
509 
510  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyPhrases.php";
512  $colors = array("tblrow1", "tblrow2");
513  $counter = 0;
514  foreach ($phrases as $phrase_id => $phrase_array)
515  {
516  $this->tpl->setCurrentBlock("phraserow");
517  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter++ % 2]);
518  $this->tpl->setVariable("PHRASE_VALUE", $phrase_id);
519  $this->tpl->setVariable("PHRASE_NAME", $phrase_array["title"]);
520  $categories =& ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
521  $this->tpl->setVariable("PHRASE_CONTENT", join($categories, ","));
522  $this->tpl->parseCurrentBlock();
523  }
524 
525  $this->tpl->setCurrentBlock("adm_content");
526  $this->tpl->setVariable("TEXT_CANCEL", $this->lng->txt("cancel"));
527  $this->tpl->setVariable("TEXT_PHRASE", $this->lng->txt("phrase"));
528  $this->tpl->setVariable("TEXT_CONTENT", $this->lng->txt("categories"));
529  $this->tpl->setVariable("TEXT_ADD_PHRASE", $this->lng->txt("add_phrase"));
530  $this->tpl->setVariable("TEXT_INTRODUCTION",$this->lng->txt("add_phrase_introduction"));
531  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
532  $this->tpl->parseCurrentBlock();
533  }
534  }
535 
541  function cancelViewPhrase()
542  {
543  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
544  $this->ctrl->redirect($this, 'editQuestion');
545  }
546 
552  function addSelectedPhrase()
553  {
554  if (strcmp($_POST["phrases"], "") == 0)
555  {
556  ilUtil::sendInfo($this->lng->txt("select_phrase_to_add"));
557  $this->wizardcolumns(false);
558  }
559  else
560  {
561  if (strcmp($this->object->getPhrase($_POST["phrases"]), "dp_standard_numbers") != 0)
562  {
563  $this->object->addPhrase($_POST["phrases"]);
564  $this->object->saveToDb();
565  }
566  else
567  {
568  $this->addStandardNumbers();
569  return;
570  }
571  ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
572  $this->ctrl->redirect($this, 'editQuestion');
573  }
574  }
575 
581  function addStandardNumbers()
582  {
583  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase_standard_numbers.html", "Modules/SurveyQuestionPool");
584 
585  // set the id to return to the selected question
586  $this->tpl->setCurrentBlock("hidden");
587  $this->tpl->setVariable("HIDDEN_NAME", "id");
588  $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
589  $this->tpl->parseCurrentBlock();
590 
591  $this->tpl->setCurrentBlock("adm_content");
592  $this->tpl->setVariable("ADD_STANDARD_NUMBERS", $this->lng->txt("add_standard_numbers"));
593  $this->tpl->setVariable("TEXT_ADD_LIMITS", $this->lng->txt("add_limits_for_standard_numbers"));
594  $this->tpl->setVariable("TEXT_LOWER_LIMIT",$this->lng->txt("lower_limit"));
595  $this->tpl->setVariable("TEXT_UPPER_LIMIT",$this->lng->txt("upper_limit"));
596  $this->tpl->setVariable("VALUE_LOWER_LIMIT", $_POST["lower_limit"]);
597  $this->tpl->setVariable("VALUE_UPPER_LIMIT", $_POST["upper_limit"]);
598  $this->tpl->setVariable("BTN_ADD",$this->lng->txt("add_phrase"));
599  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
600  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
601  $this->tpl->parseCurrentBlock();
602  }
603 
610  {
611  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
612  $this->ctrl->redirect($this, "editQuestion");
613  }
614 
621  {
622  if ((strcmp($_POST["lower_limit"], "") == 0) or (strcmp($_POST["upper_limit"], "") == 0))
623  {
624  ilUtil::sendInfo($this->lng->txt("missing_upper_or_lower_limit"));
625  $this->addStandardNumbers();
626  }
627  else if ((int)$_POST["upper_limit"] <= (int)$_POST["lower_limit"])
628  {
629  ilUtil::sendInfo($this->lng->txt("upper_limit_must_be_greater"));
630  $this->addStandardNumbers();
631  }
632  else
633  {
634  $this->object->addStandardNumbers($_POST["lower_limit"], $_POST["upper_limit"]);
635  $this->object->saveToDb();
636  ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
637  $this->ctrl->redirect($this, "editQuestion");
638  }
639  }
640 
646  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "")
647  {
648  $layout = $this->object->getLayout();
649  $neutralstyle = "3px solid #808080";
650  $bordercolor = "#808080";
651  $template = new ilTemplate("tpl.il_svy_out_matrix.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
652  $template->setCurrentBlock("material_matrix");
653  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
654  $template->parseCurrentBlock();
655 
656  if ($this->show_layout_row)
657  {
658  $layout_row = $this->getLayoutRow();
659  $template->setCurrentBlock("matrix_row");
660  $template->setVariable("ROW", $layout_row);
661  $template->parseCurrentBlock();
662  }
663 
664  $tplheaders = new ilTemplate("tpl.il_svy_out_matrix_columnheaders.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
665  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
666  {
667  $tplheaders->setCurrentBlock("bipolar_start");
668  $style = array();
669  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective1"], "%"));
670  if (count($style) > 0)
671  {
672  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
673  }
674  $tplheaders->parseCurrentBlock();
675  }
676  // column headers
677  for ($i = 0; $i < $this->object->getColumnCount(); $i++)
678  {
679  $style = array();
680  $col = $this->object->getColumn($i);
681  if ($col->neutral)
682  {
683  $tplheaders->setCurrentBlock("neutral_column_header");
684  $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($col->title));
685  $tplheaders->setVariable("CLASS", "rsep");
686  $style = array();
687  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_neutral"], "%"));
688  if ($this->object->getNeutralColumnSeparator())
689  {
690  array_push($style, "border-left: $neutralstyle!important;");
691  }
692  if (count($style) > 0)
693  {
694  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
695  }
696  $tplheaders->parseCurrentBlock();
697  }
698  else
699  {
700  if ($this->object->getColumnSeparators() == 1)
701  {
702  if (($i < $this->object->getColumnCount() - 1))
703  {
704  array_push($style, "border-right: 1px solid $bordercolor!important");
705  }
706  }
707  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_columns"] / $this->object->getColumnCount(), "%"));
708  $tplheaders->setCurrentBlock("column_header");
709  $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($col->title));
710  $tplheaders->setVariable("CLASS", "center");
711  if (count($style) > 0)
712  {
713  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
714  }
715  $tplheaders->parseCurrentBlock();
716  }
717  }
718  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
719  {
720  $tplheaders->setCurrentBlock("bipolar_end");
721  $style = array();
722  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective2"], "%"));
723  if (count($style) > 0)
724  {
725  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
726  }
727  $tplheaders->parseCurrentBlock();
728  }
729 
730  $style = array();
731  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_row"], "%"));
732  if (count($style) > 0)
733  {
734  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
735  }
736 
737  $template->setCurrentBlock("matrix_row");
738  $template->setVariable("ROW", $tplheaders->get());
739  $template->parseCurrentBlock();
740 
741  $rowclass = array("tblrow1", "tblrow2");
742  for ($i = 0; $i < $this->object->getRowCount(); $i++)
743  {
744  $rowobj = $this->object->getRow($i);
745  $tplrow = new ilTemplate("tpl.il_svy_out_matrix_row.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
746  for ($j = 0; $j < $this->object->getColumnCount(); $j++)
747  {
748  $cat = $this->object->getColumn($j);
749  if (($i == 0) && ($j == 0))
750  {
751  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
752  {
753  $tplrow->setCurrentBlock("bipolar_start");
754  $tplrow->setVariable("TEXT_BIPOLAR_START", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(0)));
755  $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
756  $tplrow->parseCurrentBlock();
757  }
758  }
759  if (($i == 0) && ($j == $this->object->getColumnCount()-1))
760  {
761  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
762  {
763  $tplrow->setCurrentBlock("bipolar_end");
764  $tplrow->setVariable("TEXT_BIPOLAR_END", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(1)));
765  $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
766  $tplrow->parseCurrentBlock();
767  }
768  }
769  switch ($this->object->getSubtype())
770  {
771  case 0:
772  if ($cat->neutral)
773  {
774  $tplrow->setCurrentBlock("neutral_radiobutton");
775  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
776  $tplrow->setVariable("ROW", $i);
777  $tplrow->setVariable("VALUE", ($cat->scale) ? ($cat->scale - 1) : $j);
778  if (is_array($working_data))
779  {
780  foreach ($working_data as $data)
781  {
782  if (($data["value"] == $cat->scale-1) && ($data["rowvalue"] == $i))
783  {
784  $tplrow->setVariable("CHECKED_RADIOBUTTON", " checked=\"checked\"");
785  }
786  }
787  }
788  $tplrow->parseCurrentBlock();
789  }
790  else
791  {
792  $tplrow->setCurrentBlock("radiobutton");
793  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
794  $tplrow->setVariable("ROW", $i);
795  $tplrow->setVariable("VALUE", ($cat->scale) ? ($cat->scale - 1) : $j);
796  if (is_array($working_data))
797  {
798  foreach ($working_data as $data)
799  {
800  if (($data["value"] == $cat->scale-1) && ($data["rowvalue"] == $i))
801  {
802  $tplrow->setVariable("CHECKED_RADIOBUTTON", " checked=\"checked\"");
803  }
804  }
805  }
806  $tplrow->parseCurrentBlock();
807  }
808  break;
809  case 1:
810  if ($cat->neutral)
811  {
812  $tplrow->setCurrentBlock("neutral_checkbox");
813  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
814  $tplrow->setVariable("ROW", $i);
815  $tplrow->setVariable("VALUE", ($cat->scale) ? ($cat->scale - 1) : $j);
816  if (is_array($working_data))
817  {
818  foreach ($working_data as $data)
819  {
820  if (($data["value"] == $cat->scale-1) && ($data["rowvalue"] == $i))
821  {
822  $tplrow->setVariable("CHECKED_CHECKBOX", " checked=\"checked\"");
823  }
824  }
825  }
826  $tplrow->parseCurrentBlock();
827  }
828  else
829  {
830  $tplrow->setCurrentBlock("checkbox");
831  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
832  $tplrow->setVariable("ROW", $i);
833  $tplrow->setVariable("VALUE", ($cat->scale) ? ($cat->scale - 1) : $j);
834  if (is_array($working_data))
835  {
836  foreach ($working_data as $data)
837  {
838  if (($data["value"] == $cat->scale-1) && ($data["rowvalue"] == $i))
839  {
840  $tplrow->setVariable("CHECKED_CHECKBOX", " checked=\"checked\"");
841  }
842  }
843  }
844  $tplrow->parseCurrentBlock();
845  }
846  break;
847  }
848  if ($cat->neutral)
849  {
850  $tplrow->setCurrentBlock("neutral_answer");
851  $style = array();
852  if ($this->object->getNeutralColumnSeparator())
853  {
854  array_push($style, "border-left: $neutralstyle!important");
855  }
856  if ($this->object->getColumnSeparators() == 1)
857  {
858  if ($j < $this->object->getColumnCount() - 1)
859  {
860  array_push($style, "border-right: 1px solid $bordercolor!important");
861  }
862  }
863  }
864  else
865  {
866  $tplrow->setCurrentBlock("answer");
867  $style = array();
868 
869  if ($this->object->getColumnSeparators() == 1)
870  {
871  if ($j < $this->object->getColumnCount() - 1)
872  {
873  array_push($style, "border-right: 1px solid $bordercolor!important");
874  }
875  }
876  }
877  if ($this->object->getRowSeparators() == 1)
878  {
879  if ($i < $this->object->getRowCount() - 1)
880  {
881  array_push($style, "border-bottom: 1px solid $bordercolor!important");
882  }
883  }
884  if (count($style))
885  {
886  $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
887  }
888  $tplrow->parseCurrentBlock();
889  }
890 
891  if ($rowobj->other)
892  {
893  $tplrow->setCurrentBlock("row_other");
894  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
895  $tplrow->setVariable("ROW", $i);
896  if (is_array($working_data))
897  {
898  foreach ($working_data as $data)
899  {
900  if ($data["rowvalue"] == $i)
901  {
902  $tplrow->setVariable("VALUE_OTHER", ilUtil::prepareFormOutput($data['textanswer']));
903  }
904  }
905  }
906  $tplrow->parseCurrentBlock();
907  }
908  $tplrow->setVariable("TEXT_ROW", ilUtil::prepareFormOutput($rowobj->title));
909  $tplrow->setVariable("ROWCLASS", $rowclass[$i % 2]);
910  if ($this->object->getRowSeparators() == 1)
911  {
912  if ($i < $this->object->getRowCount() - 1)
913  {
914  $tplrow->setVariable("STYLE", " style=\"border-bottom: 1px solid $bordercolor!important\"");
915  }
916  }
917  $template->setCurrentBlock("matrix_row");
918  $template->setVariable("ROW", $tplrow->get());
919  $template->parseCurrentBlock();
920  }
921 
922  if ($question_title)
923  {
924  $template->setVariable("QUESTION_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
925  }
926  $template->setCurrentBlock("question_data_matrix");
927  if (strcmp($error_message, "") != 0)
928  {
929  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
930  }
931  if ($show_questiontext)
932  {
933  $this->outQuestionText($template);
934  }
935  $template->parseCurrentBlock();
936  return $template->get();
937  }
938 
944  function getPrintView($question_title = 1, $show_questiontext = 1)
945  {
946  $layout = $this->object->getLayout();
947  $neutralstyle = "3px solid #808080";
948  $bordercolor = "#808080";
949  $template = new ilTemplate("tpl.il_svy_qpl_matrix_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
950 
951  if ($this->show_layout_row)
952  {
953  $layout_row = $this->getLayoutRow();
954  $template->setCurrentBlock("matrix_row");
955  $template->setVariable("ROW", $layout_row);
956  $template->parseCurrentBlock();
957  }
958 
959  $tplheaders = new ilTemplate("tpl.il_svy_out_matrix_columnheaders.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
960  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
961  {
962  $tplheaders->setCurrentBlock("bipolar_start");
963  $style = array();
964  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective1"], "%"));
965  if (count($style) > 0)
966  {
967  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
968  }
969  $tplheaders->parseCurrentBlock();
970  }
971  // column headers
972  for ($i = 0; $i < $this->object->getColumnCount(); $i++)
973  {
974  $cat = $this->object->getColumn($i);
975  if ($cat->neutral)
976  {
977  $tplheaders->setCurrentBlock("neutral_column_header");
978  $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($cat->title));
979  $tplheaders->setVariable("CLASS", "rsep");
980  $style = array();
981  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_neutral"], "%"));
982  if ($this->object->getNeutralColumnSeparator())
983  {
984  array_push($style, "border-left: $neutralstyle!important;");
985  }
986  if (count($style) > 0)
987  {
988  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
989  }
990  $tplheaders->parseCurrentBlock();
991  }
992  else
993  {
994  $style = array();
995  if ($this->object->getColumnSeparators() == 1)
996  {
997  if (($i < $this->object->getColumnCount() - 1))
998  {
999  array_push($style, "border-right: 1px solid $bordercolor!important");
1000  }
1001  }
1002  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_columns"] / $this->object->getColumnCount(), "%"));
1003  $tplheaders->setCurrentBlock("column_header");
1004  $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($cat->title));
1005  $tplheaders->setVariable("CLASS", "center");
1006  if (count($style) > 0)
1007  {
1008  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
1009  }
1010  $tplheaders->parseCurrentBlock();
1011  }
1012  }
1013 
1014  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
1015  {
1016  $tplheaders->setCurrentBlock("bipolar_end");
1017  $style = array();
1018  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective2"], "%"));
1019  if (count($style) > 0)
1020  {
1021  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
1022  }
1023  $tplheaders->parseCurrentBlock();
1024  }
1025 
1026  $style = array();
1027  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_row"], "%"));
1028  if (count($style) > 0)
1029  {
1030  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
1031  }
1032 
1033  $template->setCurrentBlock("matrix_row");
1034  $template->setVariable("ROW", $tplheaders->get());
1035  $template->parseCurrentBlock();
1036 
1037  $rowclass = array("tblrow1", "tblrow2");
1038 
1039  for ($i = 0; $i < $this->object->getRowCount(); $i++)
1040  {
1041  $rowobj = $this->object->getRow($i);
1042  $tplrow = new ilTemplate("tpl.il_svy_qpl_matrix_printview_row.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
1043  for ($j = 0; $j < $this->object->getColumnCount(); $j++)
1044  {
1045  $cat = $this->object->getColumn($j);
1046  if (($i == 0) && ($j == 0))
1047  {
1048  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
1049  {
1050  $tplrow->setCurrentBlock("bipolar_start");
1051  $tplrow->setVariable("TEXT_BIPOLAR_START", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(0)));
1052  $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
1053  $tplrow->parseCurrentBlock();
1054  }
1055  }
1056  if (($i == 0) && ($j == $this->object->getColumnCount()-1))
1057  {
1058  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
1059  {
1060  $tplrow->setCurrentBlock("bipolar_end");
1061  $tplrow->setVariable("TEXT_BIPOLAR_END", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(1)));
1062  $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
1063  $tplrow->parseCurrentBlock();
1064  }
1065  }
1066  switch ($this->object->getSubtype())
1067  {
1068  case 0:
1069  if ($cat->neutral)
1070  {
1071  $tplrow->setCurrentBlock("neutral_radiobutton");
1072  $tplrow->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
1073  $tplrow->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
1074  $tplrow->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
1075  $tplrow->parseCurrentBlock();
1076  }
1077  else
1078  {
1079  $tplrow->setCurrentBlock("radiobutton");
1080  $tplrow->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
1081  $tplrow->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
1082  $tplrow->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
1083  $tplrow->parseCurrentBlock();
1084  }
1085  break;
1086  case 1:
1087  if ($cat->neutral)
1088  {
1089  $tplrow->setCurrentBlock("neutral_checkbox");
1090  $tplrow->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.png")));
1091  $tplrow->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
1092  $tplrow->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
1093  $tplrow->parseCurrentBlock();
1094  }
1095  else
1096  {
1097  $tplrow->setCurrentBlock("checkbox");
1098  $tplrow->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.png")));
1099  $tplrow->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
1100  $tplrow->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
1101  $tplrow->parseCurrentBlock();
1102  }
1103  break;
1104  }
1105  if ($cat->neutral)
1106  {
1107  $tplrow->setCurrentBlock("neutral_answer");
1108  $style = array();
1109  if ($this->object->getNeutralColumnSeparator())
1110  {
1111  array_push($style, "border-left: $neutralstyle!important");
1112  }
1113  if ($this->object->getColumnSeparators() == 1)
1114  {
1115  if ($j < $this->object->getColumnCount() - 1)
1116  {
1117  array_push($style, "border-right: 1px solid $bordercolor!important");
1118  }
1119  }
1120 
1121  if ($this->object->getRowSeparators() == 1)
1122  {
1123  if ($i < $this->object->getRowCount() - 1)
1124  {
1125  array_push($style, "border-bottom: 1px solid $bordercolor!important");
1126  }
1127  }
1128  if (count($style))
1129  {
1130  $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
1131  }
1132  $tplrow->parseCurrentBlock();
1133  }
1134  else
1135  {
1136  $tplrow->setCurrentBlock("answer");
1137  $style = array();
1138 
1139  if ($this->object->getColumnSeparators() == 1)
1140  {
1141  if ($j < $this->object->getColumnCount() - 1)
1142  {
1143  array_push($style, "border-right: 1px solid $bordercolor!important");
1144  }
1145  }
1146 
1147  if ($this->object->getRowSeparators() == 1)
1148  {
1149  if ($i < $this->object->getRowCount() - 1)
1150  {
1151  array_push($style, "border-bottom: 1px solid $bordercolor!important");
1152  }
1153  }
1154  if (count($style))
1155  {
1156  $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
1157  }
1158  $tplrow->parseCurrentBlock();
1159  }
1160  }
1161 
1162  if ($rowobj->other)
1163  {
1164  $tplrow->setCurrentBlock("text_other");
1165  $tplrow->setVariable("TEXT_OTHER", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
1166  $tplrow->parseCurrentBlock();
1167  }
1168 
1169  $tplrow->setVariable("TEXT_ROW", ilUtil::prepareFormOutput($rowobj->title));
1170  $tplrow->setVariable("ROWCLASS", $rowclass[$i % 2]);
1171  if ($this->object->getRowSeparators() == 1)
1172  {
1173  if ($i < $this->object->getRowCount() - 1)
1174  {
1175  $tplrow->setVariable("STYLE", " style=\"border-bottom: 1px solid $bordercolor!important\"");
1176  }
1177  }
1178  $template->setCurrentBlock("matrix_row");
1179  $template->setVariable("ROW", $tplrow->get());
1180  $template->parseCurrentBlock();
1181  }
1182 
1183  if ($question_title)
1184  {
1185  $template->setVariable("QUESTION_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
1186  }
1187  $template->setCurrentBlock();
1188  if ($show_questiontext)
1189  {
1190  $this->outQuestionText($template);
1191  }
1192  $template->parseCurrentBlock();
1193  return $template->get();
1194  }
1195 
1201  function layout()
1202  {
1203  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_layout.html", "Modules/SurveyQuestionPool");
1204  $this->show_layout_row = TRUE;
1205  $question_output = $this->getWorkingForm();
1206  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
1207  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "saveLayout"));
1208  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
1209  }
1210 
1216  function saveLayout()
1217  {
1218  $percent_values = array(
1219  "percent_row" => (int)$_POST["percent_row"],
1220  "percent_columns" => (int)$_POST["percent_columns"],
1221  "percent_bipolar_adjective1" => (int)$_POST['percent_bipolar_adjective1'],
1222  "percent_bipolar_adjective2" => (int)$_POST['percent_bipolar_adjective2'],
1223  "percent_neutral" => (int)$_POST["percent_neutral"]
1224  );
1225  $this->object->setLayout($percent_values);
1226 
1227  // #9364
1228  if(array_sum($percent_values) == 100)
1229  {
1230  $this->object->saveLayout($percent_values["percent_row"],
1231  $percent_values['percent_columns'],
1232  $percent_values['percent_bipolar_adjective1'],
1233  $percent_values['percent_bipolar_adjective2'],
1234  $percent_values["percent_neutral"]);
1235  ilUtil::sendSuccess($this->lng->txt("settings_saved"));
1236  }
1237  else
1238  {
1239  ilUtil::sendFailure($this->lng->txt("svy_matrix_layout_percentages_sum_invalid"));
1240  }
1241  $this->layout();
1242  }
1243 
1249  function getLayoutRow()
1250  {
1251  $percent_values = $this->object->getLayout();
1252  $template = new ilTemplate("tpl.il_svy_out_matrix_layout.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
1253  if (strlen($this->object->getBipolarAdjective(0)) && strlen($this->object->getBipolarAdjective(1)))
1254  {
1255  $template->setCurrentBlock("bipolar_start");
1256  $template->setVariable("VALUE_PERCENT_BIPOLAR_ADJECTIVE1", " value=\"" . $percent_values["percent_bipolar_adjective1"] . "\"");
1257  $template->setVariable("STYLE", " style=\"width:" . $percent_values["percent_bipolar_adjective1"] . "%\"");
1258  $template->parseCurrentBlock();
1259  $template->setCurrentBlock("bipolar_end");
1260  $template->setVariable("VALUE_PERCENT_BIPOLAR_ADJECTIVE2", " value=\"" . $percent_values["percent_bipolar_adjective2"] . "\"");
1261  $template->setVariable("STYLE", " style=\"width:" . $percent_values["percent_bipolar_adjective2"] . "%\"");
1262  $template->parseCurrentBlock();
1263  }
1264  $counter = $this->object->getColumnCount();
1265  if (strlen($this->object->hasNeutralColumn()))
1266  {
1267  $template->setCurrentBlock("neutral_start");
1268  $template->setVariable("VALUE_PERCENT_NEUTRAL", " value=\"" . $percent_values["percent_neutral"] . "\"");
1269  $template->setVariable("STYLE_NEUTRAL", " style=\"width:" . $percent_values["percent_neutral"] . "%\"");
1270  $template->parseCurrentBlock();
1271  $counter--;
1272  }
1273  $template->setVariable("VALUE_PERCENT_ROW", " value=\"" . $percent_values["percent_row"] . "\"");
1274  $template->setVariable("STYLE_ROW", " style=\"width:" . $percent_values["percent_row"] . "%\"");
1275  $template->setVariable("COLSPAN_COLUMNS", $counter);
1276  $template->setVariable("VALUE_PERCENT_COLUMNS", " value=\"" . $percent_values["percent_columns"] . "\"");
1277  $template->setVariable("STYLE_COLUMNS", " style=\"width:" . $percent_values["percent_columns"] . "%\"");
1278  return $template->get();
1279  }
1280 
1289  function getCumulatedResultsDetails($survey_id, $counter)
1290  {
1291  if (count($this->cumulated) == 0)
1292  {
1293  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
1294  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
1295  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
1296  }
1297 
1298  $cumulated_count = 0;
1299  foreach ($this->cumulated as $key => $value)
1300  {
1301  if (is_numeric($key))
1302  {
1303  $cumulated_count++;
1304  }
1305  }
1306 
1307  $output = "";
1308 
1309  include_once "./Services/UICore/classes/class.ilTemplate.php";
1310  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
1311 
1312  $template->setCurrentBlock("detail_row");
1313  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
1314  $questiontext = $this->object->getQuestiontext();
1315  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
1316  $template->parseCurrentBlock();
1317  $template->setCurrentBlock("detail_row");
1318  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
1319  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()).
1320  " (".$cumulated_count." ".$this->lng->txt("rows").")");
1321  $template->parseCurrentBlock();
1322  $template->setCurrentBlock("detail_row");
1323  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
1324  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["USERS_ANSWERED"]);
1325  $template->parseCurrentBlock();
1326  $template->setCurrentBlock("detail_row");
1327  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
1328  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["USERS_SKIPPED"]);
1329  $template->parseCurrentBlock();
1330  /*
1331  $template->setCurrentBlock("detail_row");
1332  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
1333  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["MODE"]);
1334  $template->parseCurrentBlock();
1335  $template->setCurrentBlock("detail_row");
1336  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
1337  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["MODE_NR_OF_SELECTIONS"]);
1338  $template->parseCurrentBlock();
1339  */
1340  $template->setCurrentBlock("detail_row");
1341  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
1342  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["MEDIAN"]);
1343  $template->parseCurrentBlock();
1344 
1345  $template->setCurrentBlock("detail_row");
1346  $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
1347  $columns = "";
1348  foreach ($this->cumulated["TOTAL"]["variables"] as $key => $value)
1349  {
1350  $columns .= "<li>" . $value["title"] . ": n=" . $value["selected"] .
1351  " (" . sprintf("%.2f", 100*$value["percentage"]) . "%)</li>";
1352  }
1353  $columns = "<ol>$columns</ol>";
1354  $template->setVariable("TEXT_OPTION_VALUE", $columns);
1355  $template->parseCurrentBlock();
1356 
1357  // total chart
1358  $template->setCurrentBlock("detail_row");
1359  $template->setVariable("TEXT_OPTION", $this->lng->txt("chart"));
1360  $template->setVariable("TEXT_OPTION_VALUE", $this->renderChart("svy_ch_".$this->object->getId()."_total", $this->cumulated["TOTAL"]["variables"]));
1361  $template->parseCurrentBlock();
1362 
1363  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
1364 
1365  $output .= $template->get();
1366 
1367  foreach ($this->cumulated as $key => $value)
1368  {
1369  if (is_numeric($key))
1370  {
1371  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
1372 
1373  $template->setCurrentBlock("detail_row");
1374  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
1375  $template->setVariable("TEXT_OPTION_VALUE", $value["USERS_ANSWERED"]);
1376  $template->parseCurrentBlock();
1377  $template->setCurrentBlock("detail_row");
1378  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
1379  $template->setVariable("TEXT_OPTION_VALUE", $value["USERS_SKIPPED"]);
1380  $template->parseCurrentBlock();
1381  /*
1382  $template->setCurrentBlock("detail_row");
1383  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
1384  $template->setVariable("TEXT_OPTION_VALUE", $value["MODE"]);
1385  $template->parseCurrentBlock();
1386  $template->setCurrentBlock("detail_row");
1387  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
1388  $template->setVariable("TEXT_OPTION_VALUE", $value["MODE_NR_OF_SELECTIONS"]);
1389  $template->parseCurrentBlock();
1390  */
1391  $template->setCurrentBlock("detail_row");
1392  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
1393  $template->setVariable("TEXT_OPTION_VALUE", $value["MEDIAN"]);
1394  $template->parseCurrentBlock();
1395 
1396  $template->setCurrentBlock("detail_row");
1397  $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
1398  $columns = "";
1399  foreach ($value["variables"] as $cvalue)
1400  {
1401  $columns .= "<li>" . $cvalue["title"] . ": n=". $cvalue["selected"] .
1402  " (".sprintf("%.2f", 100*$cvalue["percentage"]) . "%)</li>";
1403  }
1404  $columns = "<ol>".$columns."</ol>";
1405  $template->setVariable("TEXT_OPTION_VALUE", $columns);
1406  $template->parseCurrentBlock();
1407 
1408  // add text answers to detailed results
1409  if (is_array($value["textanswers"]))
1410  {
1411  $template->setCurrentBlock("detail_row");
1412  $template->setVariable("TEXT_OPTION", $this->lng->txt("freetext_answers"));
1413  $html = "";
1414  foreach ($value["textanswers"] as $tkey => $answers)
1415  {
1416  $html .= $value["variables"][$tkey]["title"] ."\n";
1417  $html .= "<ul>\n";
1418  foreach ($answers as $answer)
1419  {
1420  $html .= "<li>" . preg_replace("/\n/", "<br>\n", $answer) . "</li>\n";
1421  }
1422  $html .= "</ul>\n";
1423  }
1424  $template->setVariable("TEXT_OPTION_VALUE", $html);
1425  $template->parseCurrentBlock();
1426  }
1427 
1428  // chart
1429  $template->setCurrentBlock("detail_row");
1430  $template->setVariable("TEXT_OPTION", $this->lng->txt("chart"));
1431  $template->setVariable("TEXT_OPTION_VALUE", $this->renderChart("svy_ch_".$this->object->getId()."_".$key, $value["variables"]));
1432  $template->parseCurrentBlock();
1433 
1434  $template->setVariable("QUESTION_SUBTITLE", $counter.".".($key+1)." ".
1435  $this->object->prepareTextareaOutput($value["ROW"], TRUE));
1436 
1437  $output .= $template->get();
1438  }
1439  }
1440 
1441  return $output;
1442  }
1443 
1444  function setQuestionTabs()
1445  {
1446  global $rbacsystem,$ilTabs;
1447  $this->ctrl->setParameterByClass("$guiclass", "sel_question_types", $this->getQuestionType());
1448  $this->ctrl->setParameterByClass("$guiclass", "q_id", $_GET["q_id"]);
1449 
1450  if (($_GET["calling_survey"] > 0) || ($_GET["new_for_survey"] > 0))
1451  {
1452  $ref_id = $_GET["calling_survey"];
1453  if (!strlen($ref_id)) $ref_id = $_GET["new_for_survey"];
1454  $addurl = "";
1455  if (strlen($_GET["new_for_survey"]))
1456  {
1457  $addurl = "&new_id=" . $_GET["q_id"];
1458  }
1459  if ($_REQUEST["pgov"])
1460  {
1461  $addurl .= "&pgov=".$_REQUEST["pgov"];
1462  $addurl .= "&pgov_pos=".$_REQUEST["pgov_pos"];
1463  }
1464  $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), "ilias.php?baseClass=ilObjSurveyGUI&ref_id=$ref_id&cmd=questions" . $addurl);
1465  }
1466  else
1467  {
1468  $this->ctrl->setParameterByClass("ilObjSurveyQuestionPoolGUI", "q_id_table_nav", $_SESSION['q_id_table_nav']);
1469  $ilTabs->setBackTarget($this->lng->txt("spl"), $this->ctrl->getLinkTargetByClass("ilObjSurveyQuestionPoolGUI", "questions"));
1470  }
1471  if ($_GET["q_id"])
1472  {
1473  $ilTabs->addTarget("preview",
1474  $this->ctrl->getLinkTarget($this, "preview"),
1475  array("preview"),
1476  "",
1477  "");
1478 
1479  $ilTabs->addTarget("layout",
1480  $this->ctrl->getLinkTarget($this, "layout"),
1481  array("layout", "saveLayout"),
1482  "",
1483  "");
1484  }
1485  if ($rbacsystem->checkAccess('edit', $_GET["ref_id"]))
1486  {
1487  $ilTabs->addTarget("edit_properties",
1488  $this->ctrl->getLinkTarget($this, "editQuestion"),
1489  array("editQuestion", "cancelExplorer", "linkChilds", "addGIT", "addST",
1490  "addPG", "editQuestion", "addMaterial", "removeMaterial",
1491  "save", "cancel", "savePhrasecolumns", "confirmSavePhrase",
1492  "downcolumns", "upcolumns", "addcolumns", "removecolumns",
1493  "downrows", "uprows", "addrows", "removerows", "wizardcolumns",
1494  "addSelectedPhrase", "insertStandardNumbers"),
1495  "",
1496  "");
1497  }
1498 
1499  if ($this->object->getId() > 0)
1500  {
1501  $ilTabs->addTarget("material",
1502  $this->ctrl->getLinkTarget($this, "material"),
1503  array("material", "cancelExplorer", "linkChilds", "addGIT", "addST",
1504  "addPG", "addMaterial", "removeMaterial"),
1505  "$guiclass");
1506  }
1507 
1508  if ($this->object->getId() > 0)
1509  {
1510  $title = $this->lng->txt("edit") . " &quot;" . $this->object->getTitle() . "&quot";
1511  }
1512  else
1513  {
1514  $title = $this->lng->txt("create_new") . " " . $this->lng->txt($this->getQuestionType());
1515  }
1516 
1517  $this->tpl->setVariable("HEADER", $title);
1518  }
1519 
1520 }
1521 ?>