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