ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
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
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
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
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 switch ($question_title)
512 {
513 case 1:
514 $row_title = ilUtil::prepareFormOutput($rowobj->title);
515 break;
516 #19448 matrix rows should contain always the title because labels are optional.
517 /*case 2:
518 $row_title = ilUtil::prepareFormOutput($rowobj->label);
519 break;
520
521 case 3:*/
522 default:
523 $row_title = ilUtil::prepareFormOutput($rowobj->title);
524 if(trim($rowobj->label))
525 {
526 $row_title .= ' <span class="questionLabel">('.ilUtil::prepareFormOutput($rowobj->label).')</span>';
527 }
528 break;
529 }
530 $tplrow->setVariable("TEXT_ROW", $row_title);
531 $tplrow->setVariable("ROWCLASS", $rowclass[$i % 2]);
532 if ($this->object->getRowSeparators() == 1)
533 {
534 if ($i < $this->object->getRowCount() - 1)
535 {
536 $tplrow->setVariable("STYLE", " style=\"border-bottom: 1px solid $bordercolor!important\"");
537 }
538 }
539 $template->setCurrentBlock("matrix_row");
540 $template->setVariable("ROW", $tplrow->get());
541 $template->parseCurrentBlock();
542 }
543
544 if ($question_title)
545 {
546 $template->setVariable("QUESTION_TITLE", $this->getPrintViewQuestionTitle($question_title));
547 }
548 $template->setCurrentBlock();
549 if ($show_questiontext)
550 {
551 $this->outQuestionText($template);
552 }
553 $template->parseCurrentBlock();
554 return $template->get();
555 }
556
557
558 //
559 // LAYOUT
560 //
561
567 function layout()
568 {
569 global $ilTabs;
570
571 $ilTabs->activateTab("layout");
572
573 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_layout.html", "Modules/SurveyQuestionPool");
574 $this->show_layout_row = TRUE;
575 $question_output = $this->getWorkingForm();
576 $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
577 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "saveLayout"));
578 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
579 }
580
586 function saveLayout()
587 {
588 $percent_values = array(
589 "percent_row" => (int)$_POST["percent_row"],
590 "percent_columns" => (int)$_POST["percent_columns"],
591 "percent_bipolar_adjective1" => (int)$_POST['percent_bipolar_adjective1'],
592 "percent_bipolar_adjective2" => (int)$_POST['percent_bipolar_adjective2'],
593 "percent_neutral" => (int)$_POST["percent_neutral"]
594 );
595 $this->object->setLayout($percent_values);
596
597 // #9364
598 if(array_sum($percent_values) == 100)
599 {
600 $this->object->saveLayout($percent_values["percent_row"],
601 $percent_values['percent_columns'],
602 $percent_values['percent_bipolar_adjective1'],
603 $percent_values['percent_bipolar_adjective2'],
604 $percent_values["percent_neutral"]);
605 ilUtil::sendSuccess($this->lng->txt("settings_saved"));
606 }
607 else
608 {
609 ilUtil::sendFailure($this->lng->txt("svy_matrix_layout_percentages_sum_invalid"));
610 }
611 $this->layout();
612 }
613
619 function getLayoutRow()
620 {
621 $percent_values = $this->object->getLayout();
622 $template = new ilTemplate("tpl.il_svy_out_matrix_layout.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
623 if (strlen($this->object->getBipolarAdjective(0)) && strlen($this->object->getBipolarAdjective(1)))
624 {
625 $template->setCurrentBlock("bipolar_start");
626 $template->setVariable("VALUE_PERCENT_BIPOLAR_ADJECTIVE1", " value=\"" . $percent_values["percent_bipolar_adjective1"] . "\"");
627 $template->setVariable("STYLE", " style=\"width:" . $percent_values["percent_bipolar_adjective1"] . "%\"");
628 $template->parseCurrentBlock();
629 $template->setCurrentBlock("bipolar_end");
630 $template->setVariable("VALUE_PERCENT_BIPOLAR_ADJECTIVE2", " value=\"" . $percent_values["percent_bipolar_adjective2"] . "\"");
631 $template->setVariable("STYLE", " style=\"width:" . $percent_values["percent_bipolar_adjective2"] . "%\"");
632 $template->parseCurrentBlock();
633 }
634 $counter = $this->object->getColumnCount();
635 if (strlen($this->object->hasNeutralColumn()))
636 {
637 $template->setCurrentBlock("neutral_start");
638 $template->setVariable("VALUE_PERCENT_NEUTRAL", " value=\"" . $percent_values["percent_neutral"] . "\"");
639 $template->setVariable("STYLE_NEUTRAL", " style=\"width:" . $percent_values["percent_neutral"] . "%\"");
640 $template->parseCurrentBlock();
641 $counter--;
642 }
643 $template->setVariable("VALUE_PERCENT_ROW", " value=\"" . $percent_values["percent_row"] . "\"");
644 $template->setVariable("STYLE_ROW", " style=\"width:" . $percent_values["percent_row"] . "%\"");
645 $template->setVariable("COLSPAN_COLUMNS", $counter);
646 $template->setVariable("VALUE_PERCENT_COLUMNS", " value=\"" . $percent_values["percent_columns"] . "\"");
647 $template->setVariable("STYLE_COLUMNS", " style=\"width:" . $percent_values["percent_columns"] . "%\"");
648 return $template->get();
649 }
650
651
652 //
653 // EXECUTION
654 //
655
661 function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
662 {
663 $layout = $this->object->getLayout();
664 $neutralstyle = "3px solid #808080";
665 $bordercolor = "#808080";
666 $template = new ilTemplate("tpl.il_svy_out_matrix.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
667 $template->setCurrentBlock("material_matrix");
668 $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
669 $template->parseCurrentBlock();
670
671 if ($this->show_layout_row)
672 {
673 $layout_row = $this->getLayoutRow();
674 $template->setCurrentBlock("matrix_row");
675 $template->setVariable("ROW", $layout_row);
676 $template->parseCurrentBlock();
677 }
678
679 $tplheaders = new ilTemplate("tpl.il_svy_out_matrix_columnheaders.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
680 if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
681 {
682 $tplheaders->setCurrentBlock("bipolar_start");
683 $style = array();
684 array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective1"], "%"));
685 if (count($style) > 0)
686 {
687 $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
688 }
689 $tplheaders->parseCurrentBlock();
690 }
691 // column headers
692 for ($i = 0; $i < $this->object->getColumnCount(); $i++)
693 {
694 $style = array();
695 $col = $this->object->getColumn($i);
696 if ($col->neutral)
697 {
698 $tplheaders->setCurrentBlock("neutral_column_header");
699 $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($col->title));
700 $tplheaders->setVariable("CLASS", "rsep");
701 $style = array();
702 array_push($style, sprintf("width: %.2f%s!important", $layout["percent_neutral"], "%"));
703 if ($this->object->getNeutralColumnSeparator())
704 {
705 array_push($style, "border-left: $neutralstyle!important;");
706 }
707 if (count($style) > 0)
708 {
709 $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
710 }
711 $tplheaders->parseCurrentBlock();
712 }
713 else
714 {
715 if ($this->object->getColumnSeparators() == 1)
716 {
717 if (($i < $this->object->getColumnCount() - 1))
718 {
719 array_push($style, "border-right: 1px solid $bordercolor!important");
720 }
721 }
722 array_push($style, sprintf("width: %.2f%s!important", $layout["percent_columns"] / $this->object->getColumnCount(), "%"));
723 $tplheaders->setCurrentBlock("column_header");
724 $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($col->title));
725 $tplheaders->setVariable("CLASS", "center");
726 if (count($style) > 0)
727 {
728 $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
729 }
730 $tplheaders->parseCurrentBlock();
731 }
732 }
733 if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
734 {
735 $tplheaders->setCurrentBlock("bipolar_end");
736 $style = array();
737 array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective2"], "%"));
738 if (count($style) > 0)
739 {
740 $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
741 }
742 $tplheaders->parseCurrentBlock();
743 }
744
745 $style = array();
746 array_push($style, sprintf("width: %.2f%s!important", $layout["percent_row"], "%"));
747 if (count($style) > 0)
748 {
749 $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
750 }
751
752 $template->setCurrentBlock("matrix_row");
753 $template->setVariable("ROW", $tplheaders->get());
754 $template->parseCurrentBlock();
755
756 $rowclass = array("tblrow1", "tblrow2");
757 for ($i = 0; $i < $this->object->getRowCount(); $i++)
758 {
759 $rowobj = $this->object->getRow($i);
760 $tplrow = new ilTemplate("tpl.il_svy_out_matrix_row.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
761 for ($j = 0; $j < $this->object->getColumnCount(); $j++)
762 {
763 $cat = $this->object->getColumn($j);
764 if (($i == 0) && ($j == 0))
765 {
766 if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
767 {
768 $tplrow->setCurrentBlock("bipolar_start");
769 $tplrow->setVariable("TEXT_BIPOLAR_START", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(0)));
770 $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
771 $tplrow->parseCurrentBlock();
772 }
773 }
774 if (($i == 0) && ($j == $this->object->getColumnCount()-1))
775 {
776 if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
777 {
778 $tplrow->setCurrentBlock("bipolar_end");
779 $tplrow->setVariable("TEXT_BIPOLAR_END", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(1)));
780 $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
781 $tplrow->parseCurrentBlock();
782 }
783 }
784 switch ($this->object->getSubtype())
785 {
786 case 0:
787 if ($cat->neutral)
788 {
789 $tplrow->setCurrentBlock("neutral_radiobutton");
790 $tplrow->setVariable("QUESTION_ID", $this->object->getId());
791 $tplrow->setVariable("ROW", $i);
792 $tplrow->setVariable("VALUE", ($cat->scale) ? ($cat->scale - 1) : $j);
793 if (is_array($working_data))
794 {
795 foreach ($working_data as $data)
796 {
797 if (($data["value"] == $cat->scale-1) && ($data["rowvalue"] == $i))
798 {
799 $tplrow->setVariable("CHECKED_RADIOBUTTON", " checked=\"checked\"");
800 }
801 }
802 }
803 $tplrow->parseCurrentBlock();
804 }
805 else
806 {
807 $tplrow->setCurrentBlock("radiobutton");
808 $tplrow->setVariable("QUESTION_ID", $this->object->getId());
809 $tplrow->setVariable("ROW", $i);
810 $tplrow->setVariable("VALUE", ($cat->scale) ? ($cat->scale - 1) : $j);
811 if (is_array($working_data))
812 {
813 foreach ($working_data as $data)
814 {
815 if (($data["value"] == $cat->scale-1) && ($data["rowvalue"] == $i))
816 {
817 $tplrow->setVariable("CHECKED_RADIOBUTTON", " checked=\"checked\"");
818 }
819 }
820 }
821 $tplrow->parseCurrentBlock();
822 }
823 break;
824 case 1:
825 if ($cat->neutral)
826 {
827 $tplrow->setCurrentBlock("neutral_checkbox");
828 $tplrow->setVariable("QUESTION_ID", $this->object->getId());
829 $tplrow->setVariable("ROW", $i);
830 $tplrow->setVariable("VALUE", ($cat->scale) ? ($cat->scale - 1) : $j);
831 if (is_array($working_data))
832 {
833 foreach ($working_data as $data)
834 {
835 if (($data["value"] == $cat->scale-1) && ($data["rowvalue"] == $i))
836 {
837 $tplrow->setVariable("CHECKED_CHECKBOX", " checked=\"checked\"");
838 }
839 }
840 }
841 $tplrow->parseCurrentBlock();
842 }
843 else
844 {
845 $tplrow->setCurrentBlock("checkbox");
846 $tplrow->setVariable("QUESTION_ID", $this->object->getId());
847 $tplrow->setVariable("ROW", $i);
848 $tplrow->setVariable("VALUE", ($cat->scale) ? ($cat->scale - 1) : $j);
849 if (is_array($working_data))
850 {
851 foreach ($working_data as $data)
852 {
853 if (($data["value"] == $cat->scale-1) && ($data["rowvalue"] == $i))
854 {
855 $tplrow->setVariable("CHECKED_CHECKBOX", " checked=\"checked\"");
856 }
857 }
858 }
859 $tplrow->parseCurrentBlock();
860 }
861 break;
862 }
863 if ($cat->neutral)
864 {
865 $tplrow->setCurrentBlock("neutral_answer");
866 $style = array();
867 if ($this->object->getNeutralColumnSeparator())
868 {
869 array_push($style, "border-left: $neutralstyle!important");
870 }
871 if ($this->object->getColumnSeparators() == 1)
872 {
873 if ($j < $this->object->getColumnCount() - 1)
874 {
875 array_push($style, "border-right: 1px solid $bordercolor!important");
876 }
877 }
878 }
879 else
880 {
881 $tplrow->setCurrentBlock("answer");
882 $style = array();
883
884 if ($this->object->getColumnSeparators() == 1)
885 {
886 if ($j < $this->object->getColumnCount() - 1)
887 {
888 array_push($style, "border-right: 1px solid $bordercolor!important");
889 }
890 }
891 }
892 if ($this->object->getRowSeparators() == 1)
893 {
894 if ($i < $this->object->getRowCount() - 1)
895 {
896 array_push($style, "border-bottom: 1px solid $bordercolor!important");
897 }
898 }
899 if (count($style))
900 {
901 $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
902 }
903 $tplrow->parseCurrentBlock();
904 }
905
906 if ($rowobj->other)
907 {
908 $tplrow->setCurrentBlock("row_other");
909 $tplrow->setVariable("QUESTION_ID", $this->object->getId());
910 $tplrow->setVariable("ROW", $i);
911 if (is_array($working_data))
912 {
913 foreach ($working_data as $data)
914 {
915 if ($data["rowvalue"] == $i)
916 {
917 $tplrow->setVariable("VALUE_OTHER", ilUtil::prepareFormOutput($data['textanswer']));
918 }
919 }
920 }
921 $tplrow->parseCurrentBlock();
922 }
923 $tplrow->setVariable("TEXT_ROW", ilUtil::prepareFormOutput($rowobj->title));
924 $tplrow->setVariable("ROWCLASS", $rowclass[$i % 2]);
925 if ($this->object->getRowSeparators() == 1)
926 {
927 if ($i < $this->object->getRowCount() - 1)
928 {
929 $tplrow->setVariable("STYLE", " style=\"border-bottom: 1px solid $bordercolor!important\"");
930 }
931 }
932 $template->setCurrentBlock("matrix_row");
933 $template->setVariable("ROW", $tplrow->get());
934 $template->parseCurrentBlock();
935 }
936
937 if ($question_title)
938 {
939 $template->setVariable("QUESTION_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
940 }
941 $template->setCurrentBlock("question_data_matrix");
942 if (strcmp($error_message, "") != 0)
943 {
944 $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
945 }
946 if ($show_questiontext)
947 {
948 $this->outQuestionText($template);
949 }
950 $template->parseCurrentBlock();
951 return $template->get();
952 }
953
954
955 //
956 // EVALUATION
957 //
958
967 function getCumulatedResultsDetails($survey_id, $counter, $finished_ids)
968 {
969 if (count($this->cumulated) == 0)
970 {
971 if(!$finished_ids)
972 {
973 include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
974 $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
975 }
976 else
977 {
978 $nr_of_users = sizeof($finished_ids);
979 }
980 $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users, $finished_ids);
981 }
982
983 $cumulated_count = 0;
984 foreach ($this->cumulated as $key => $value)
985 {
986 if (is_numeric($key))
987 {
988 $cumulated_count++;
989 }
990 }
991
992 $output = "";
993
994 include_once "./Services/UICore/classes/class.ilTemplate.php";
995 $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
996
997 $template->setCurrentBlock("detail_row");
998 $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
999 $questiontext = $this->object->getQuestiontext();
1000 $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
1001 $template->parseCurrentBlock();
1002 $template->setCurrentBlock("detail_row");
1003 $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
1004 $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()).
1005 " (".$cumulated_count." ".$this->lng->txt("rows").")");
1006 $template->parseCurrentBlock();
1007 $template->setCurrentBlock("detail_row");
1008 $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
1009 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["USERS_ANSWERED"]);
1010 $template->parseCurrentBlock();
1011 $template->setCurrentBlock("detail_row");
1012 $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
1013 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["USERS_SKIPPED"]);
1014 $template->parseCurrentBlock();
1015 /*
1016 $template->setCurrentBlock("detail_row");
1017 $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
1018 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["MODE"]);
1019 $template->parseCurrentBlock();
1020 $template->setCurrentBlock("detail_row");
1021 $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
1022 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["MODE_NR_OF_SELECTIONS"]);
1023 $template->parseCurrentBlock();
1024 */
1025 $template->setCurrentBlock("detail_row");
1026 $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
1027 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["MEDIAN"]);
1028 $template->parseCurrentBlock();
1029
1030 $template->setCurrentBlock("detail_row");
1031 $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
1032 $table = array();
1033 $idx = $selsum = 0;
1034 foreach ($this->cumulated["TOTAL"]["variables"] as $key => $value)
1035 {
1036 $table[] = array(
1037 (++$idx).".",
1038 $value["title"],
1039 $value["selected"],
1040 sprintf("%.2f", 100*$value["percentage"])."%"
1041 );
1042 $selsum += (int)$value["selected"];
1043 }
1044 $head = array(
1045 "",
1046 $this->lng->txt("title"),
1047 $this->lng->txt("category_nr_selected"),
1048 $this->lng->txt("percentage_of_selections")
1049 );
1050 $foot = array(null, null, $selsum, null);
1051 $template->setVariable("TEXT_OPTION_VALUE",
1052 $this->renderStatisticsDetailsTable($head, $table, $foot));
1053 $template->parseCurrentBlock();
1054
1055 // total chart
1056 $template->setCurrentBlock("detail_row");
1057 $template->setVariable("TEXT_OPTION", $this->lng->txt("chart"));
1058 $template->setVariable("TEXT_OPTION_VALUE", $this->renderChart("svy_ch_".$this->object->getId()."_total", $this->cumulated["TOTAL"]["variables"]));
1059 $template->parseCurrentBlock();
1060
1061 $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
1062
1063 $output .= $template->get();
1064
1065 foreach ($this->cumulated as $key => $value)
1066 {
1067 if (is_numeric($key))
1068 {
1069 $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
1070
1071 $template->setCurrentBlock("detail_row");
1072 $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
1073 $template->setVariable("TEXT_OPTION_VALUE", $value["USERS_ANSWERED"]);
1074 $template->parseCurrentBlock();
1075 $template->setCurrentBlock("detail_row");
1076 $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
1077 $template->setVariable("TEXT_OPTION_VALUE", $value["USERS_SKIPPED"]);
1078 $template->parseCurrentBlock();
1079 /*
1080 $template->setCurrentBlock("detail_row");
1081 $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
1082 $template->setVariable("TEXT_OPTION_VALUE", $value["MODE"]);
1083 $template->parseCurrentBlock();
1084 $template->setCurrentBlock("detail_row");
1085 $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
1086 $template->setVariable("TEXT_OPTION_VALUE", $value["MODE_NR_OF_SELECTIONS"]);
1087 $template->parseCurrentBlock();
1088 */
1089 $template->setCurrentBlock("detail_row");
1090 $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
1091 $template->setVariable("TEXT_OPTION_VALUE", $value["MEDIAN"]);
1092 $template->parseCurrentBlock();
1093
1094 $template->setCurrentBlock("detail_row");
1095 $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
1096 $table = array();
1097 $idx = $selsum = 0;
1098 foreach ($value["variables"] as $cvalue)
1099 {
1100 $table[] = array(
1101 (++$idx).".",
1102 $cvalue["title"],
1103 $cvalue["selected"],
1104 sprintf("%.2f", 100*$cvalue["percentage"])."%"
1105 );
1106 $selsum += (int)$cvalue["selected"];
1107 }
1108 $head = array(
1109 "",
1110 $this->lng->txt("title"),
1111 $this->lng->txt("category_nr_selected"),
1112 $this->lng->txt("percentage_of_selections")
1113 );
1114 $foot = array(null, null, $selsum, null);
1115 $template->setVariable("TEXT_OPTION_VALUE",
1116 $this->renderStatisticsDetailsTable($head, $table, $foot));
1117 $template->parseCurrentBlock();
1118
1119 // add text answers to detailed results
1120 if (is_array($value["textanswers"]))
1121 {
1122 $template->setCurrentBlock("detail_row");
1123 $template->setVariable("TEXT_OPTION", $this->lng->txt("freetext_answers"));
1124 $html = "";
1125 foreach ($value["textanswers"] as $tkey => $answers)
1126 {
1127 $html .= $value["variables"][$tkey]["title"] ."\n";
1128 $html .= "<ul>\n";
1129 foreach ($answers as $answer)
1130 {
1131 $html .= "<li>" . preg_replace("/\n/", "<br>\n", $answer) . "</li>\n";
1132 }
1133 $html .= "</ul>\n";
1134 }
1135 $template->setVariable("TEXT_OPTION_VALUE", $html);
1136 $template->parseCurrentBlock();
1137 }
1138
1139 // chart
1140 $template->setCurrentBlock("detail_row");
1141 $template->setVariable("TEXT_OPTION", $this->lng->txt("chart"));
1142 $template->setVariable("TEXT_OPTION_VALUE", $this->renderChart("svy_ch_".$this->object->getId()."_".$key, $value["variables"]));
1143 $template->parseCurrentBlock();
1144
1145 $template->setVariable("QUESTION_SUBTITLE", $counter.".".($key+1)." ".
1146 $this->object->prepareTextareaOutput($value["ROW"], TRUE));
1147
1148 $output .= $template->get();
1149 }
1150 }
1151
1152 return $output;
1153 }
1154}
1155
1156?>
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.
getPrintViewQuestionTitle($question_title=1)
renderChart($a_id, $a_variables)
getMaterialOutput()
Creates the HTML output of the question material(s)
renderStatisticsDetailsTable(array $a_head, array $a_rows, array $a_foot=null)
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
$html
Definition: example_001.php:87
$header
$data
$style
Definition: example_012.php:70
$text
if(!is_array($argv)) $options