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