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