ILIAS  release_7 Revision v7.30-3-g800a261c036
class.SurveyMatrixQuestionGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
14{
16
17 protected function initObject()
18 {
19 $this->object = new SurveyMatrixQuestion();
20 }
21
22
23 //
24 // EDITOR
25 //
26
27 public function setQuestionTabs()
28 {
29 $this->setQuestionTabsForClass("surveymatrixquestiongui");
30 }
31
32 protected function addFieldsToEditForm(ilPropertyFormGUI $a_form)
33 {
34 // subtype
35 $subtype = new ilRadioGroupInputGUI($this->lng->txt("subtype"), "type");
36 $subtype->setRequired(false);
37 $subtypes = array(
38 "0" => "matrix_subtype_sr",
39 "1" => "matrix_subtype_mr",
40 //"2" => "matrix_subtype_text",
41 //"3" => "matrix_subtype_integer",
42 //"4" => "matrix_subtype_double",
43 //"5" => "matrix_subtype_date",
44 //"6" => "matrix_subtype_time"
45 );
46 foreach ($subtypes as $idx => $st) {
47 $subtype->addOption(new ilRadioOption($this->lng->txt($st), $idx));
48 }
49 $a_form->addItem($subtype);
50
51
52 $header = new ilFormSectionHeaderGUI();
53 $header->setTitle($this->lng->txt("matrix_appearance"));
54 $a_form->addItem($header);
55
56 // column separators
57 $column_separators = new ilCheckboxInputGUI($this->lng->txt("matrix_column_separators"), "column_separators");
58 $column_separators->setValue(1);
59 $column_separators->setInfo($this->lng->txt("matrix_column_separators_description"));
60 $column_separators->setRequired(false);
61 $a_form->addItem($column_separators);
62
63 // row separators
64 $row_separators = new ilCheckboxInputGUI($this->lng->txt("matrix_row_separators"), "row_separators");
65 $row_separators->setValue(1);
66 $row_separators->setInfo($this->lng->txt("matrix_row_separators_description"));
67 $row_separators->setRequired(false);
68 $a_form->addItem($row_separators);
69
70 // neutral column separators
71 $neutral_column_separator = new ilCheckboxInputGUI($this->lng->txt("matrix_neutral_column_separator"), "neutral_column_separator");
72 $neutral_column_separator->setValue(1);
73 $neutral_column_separator->setInfo($this->lng->txt("matrix_neutral_column_separator_description"));
74 $neutral_column_separator->setRequired(false);
75 $a_form->addItem($neutral_column_separator);
76
77
78 $header = new ilFormSectionHeaderGUI();
79 $header->setTitle($this->lng->txt("matrix_columns"));
80 $a_form->addItem($header);
81
82 // Answers
83 $columns = new ilCategoryWizardInputGUI("", "columns");
84 $columns->setRequired(false);
85 $columns->setAllowMove(true);
86 $columns->setShowWizard(true);
87 $columns->setShowNeutralCategory(true);
88 $columns->setDisabledScale(false);
89 $columns->setNeutralCategoryTitle($this->lng->txt('matrix_neutral_answer'));
90 $columns->setCategoryText($this->lng->txt('matrix_standard_answers'));
91 $columns->setShowSavePhrase(true);
92 $a_form->addItem($columns);
93
94
95 $header = new ilFormSectionHeaderGUI();
96 $header->setTitle($this->lng->txt("matrix_column_settings"));
97 $a_form->addItem($header);
98
99 // bipolar adjectives
100 $bipolar = new ilCustomInputGUI($this->lng->txt("matrix_bipolar_adjectives"));
101 $bipolar->setInfo($this->lng->txt("matrix_bipolar_adjectives_description"));
102
103 // left pole
104 $bipolar1 = new ilTextInputGUI($this->lng->txt("matrix_left_pole"), "bipolar1");
105 $bipolar1->setRequired(false);
106 $bipolar->addSubItem($bipolar1);
107
108 // right pole
109 $bipolar2 = new ilTextInputGUI($this->lng->txt("matrix_right_pole"), "bipolar2");
110 $bipolar2->setRequired(false);
111 $bipolar->addSubItem($bipolar2);
112
113 $a_form->addItem($bipolar);
114
115
116 $header = new ilFormSectionHeaderGUI();
117 $header->setTitle($this->lng->txt("matrix_rows"));
118 $a_form->addItem($header);
119
120 // matrix rows
121 $rows = new ilMatrixRowWizardInputGUI("", "rows");
122 $rows->setRequired(false);
123 $rows->setAllowMove(true);
124 $rows->setLabelText($this->lng->txt('label'));
125 $rows->setUseOtherAnswer(true);
126 $a_form->addItem($rows);
127
128
129 // values
130 $subtype->setValue($this->object->getSubtype());
131 $column_separators->setChecked($this->object->getColumnSeparators());
132 $row_separators->setChecked($this->object->getRowSeparators());
133 $neutral_column_separator->setChecked($this->object->getNeutralColumnSeparator());
134
135 if (!$this->object->getColumnCount()) {
136 $this->object->columns->addCategory("");
137 }
138 $columns->setValues($this->object->getColumns());
139
140 $bipolar1->setValue($this->object->getBipolarAdjective(0));
141 $bipolar2->setValue($this->object->getBipolarAdjective(1));
142
143 if ($this->object->getRowCount() == 0) {
144 $this->object->getRows()->addCategory("");
145 }
146 $rows->setValues($this->object->getRows());
147 }
148
149 protected function importEditFormValues(ilPropertyFormGUI $a_form)
150 {
151 $this->object->setSubtype($a_form->getInput("type"));
152 $this->object->setRowSeparators($a_form->getInput("row_separators") ? 1 : 0);
153 $this->object->setColumnSeparators($a_form->getInput("column_separators") ? 1 : 0);
154 $this->object->setNeutralColumnSeparator($a_form->getInput("neutral_column_separator") ? 1 : 0);
155
156 // Set bipolar adjectives
157 $this->object->setBipolarAdjective(0, $a_form->getInput("bipolar1"));
158 $this->object->setBipolarAdjective(1, $a_form->getInput("bipolar2"));
159
160 // set columns
161 $this->object->flushColumns();
162
163 foreach ($_POST['columns']['answer'] as $key => $value) {
164 if (strlen($value)) {
165 $this->object->getColumns()->addCategory($value, $_POST['columns']['other'][$key], 0, null, $_POST['columns']['scale'][$key]);
166 }
167 }
168 if (strlen($_POST["columns"]["neutral"])) {
169 $this->object->getColumns()->addCategory($_POST['columns']['neutral'], 0, 1, null, $_POST['columns_neutral_scale']);
170 }
171
172 // set rows
173 $this->object->flushRows();
174 foreach ($_POST['rows']['answer'] as $key => $value) {
175 if (strlen($value)) {
176 $this->object->getRows()->addCategory($value, $_POST['rows']['other'][$key], 0, $_POST['rows']['label'][$key]);
177 }
178 }
179 }
180
181 public function getParsedAnswers(array $a_working_data = null, $a_only_user_anwers = false)
182 {
183 if (is_array($a_working_data)) {
184 $user_answers = $a_working_data;
185 }
186
187 $options = array();
188 for ($i = 0; $i < $this->object->getRowCount(); $i++) {
189 $rowobj = $this->object->getRow($i);
190
191 $text = null;
192
193 $cols = array();
194 for ($j = 0; $j < $this->object->getColumnCount(); $j++) {
195 $cat = $this->object->getColumn($j);
196 $value = ($cat->scale) ? ($cat->scale - 1) : $j;
197
198 $checked = "unchecked";
199 if (is_array($a_working_data)) {
200 foreach ($user_answers as $user_answer) {
201 if ($user_answer["rowvalue"] == $i &&
202 $user_answer["value"] == $value) {
203 $checked = "checked";
204 if ($user_answer["textanswer"]) {
205 $text = $user_answer["textanswer"];
206 }
207 }
208 }
209 }
210
211 if (!$a_only_user_anwers || $checked == "checked") {
212 $cols[$value] = array(
213 "title" => trim($cat->title)
214 ,"neutral" => (bool) $cat->neutral
215 ,"checked" => $checked
216 );
217 }
218 }
219
220 if ($a_only_user_anwers || sizeof($cols) || $text) {
221 $row_idx = $i;
222 $options[$row_idx] = array(
223 "title" => trim($rowobj->title)
224 ,"other" => (bool) $rowobj->other
225 ,"textanswer" => $text
226 ,"cols" => $cols
227 );
228 }
229 }
230
231 return $options;
232 }
233
239 public function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null, array $a_working_data = null)
240 {
241 $options = $this->getParsedAnswers($a_working_data);
242
243 $layout = $this->object->getLayout();
244 $neutralstyle = "3px solid #808080";
245 $bordercolor = "#808080";
246 $template = new ilTemplate("tpl.il_svy_qpl_matrix_printview.html", true, true, "Modules/SurveyQuestionPool");
247
248 if ($this->show_layout_row) {
249 $layout_row = $this->getLayoutRow();
250 $template->setCurrentBlock("matrix_row");
251 $template->setVariable("ROW", $layout_row);
252 $template->parseCurrentBlock();
253 }
254
255 $tplheaders = new ilTemplate("tpl.il_svy_out_matrix_columnheaders.html", true, true, "Modules/SurveyQuestionPool");
256 if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1)))) {
257 $tplheaders->setCurrentBlock("bipolar_start");
258 $style = array();
259 array_push($style, sprintf("width: %.2F%s!important", $layout["percent_bipolar_adjective1"], "%"));
260 if (count($style) > 0) {
261 $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
262 }
263 $tplheaders->parseCurrentBlock();
264 }
265 // column headers
266 for ($i = 0; $i < $this->object->getColumnCount(); $i++) {
267 $cat = $this->object->getColumn($i);
268 if ($cat->neutral) {
269 $tplheaders->setCurrentBlock("neutral_column_header");
270 $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($cat->title));
271 $tplheaders->setVariable("CLASS", "rsep");
272 $style = array();
273 array_push($style, sprintf("width: %.2F%s!important", $layout["percent_neutral"], "%"));
274 if ($this->object->getNeutralColumnSeparator()) {
275 array_push($style, "border-left: $neutralstyle!important;");
276 }
277 if (count($style) > 0) {
278 $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
279 }
280 $tplheaders->parseCurrentBlock();
281 } else {
282 $style = array();
283 if ($this->object->getColumnSeparators() == 1) {
284 if (($i < $this->object->getColumnCount() - 1)) {
285 array_push($style, "border-right: 1px solid $bordercolor!important");
286 }
287 }
288 array_push($style, sprintf("width: %.2F%s!important", $layout["percent_columns"] / $this->object->getColumnCount(), "%"));
289 $tplheaders->setCurrentBlock("column_header");
290 $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($cat->title));
291 $tplheaders->setVariable("CLASS", "center");
292 if (count($style) > 0) {
293 $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
294 }
295 $tplheaders->parseCurrentBlock();
296 }
297 }
298
299 if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1)))) {
300 $tplheaders->setCurrentBlock("bipolar_end");
301 $style = array();
302 array_push($style, sprintf("width: %.2F%s!important", $layout["percent_bipolar_adjective2"], "%"));
303 if (count($style) > 0) {
304 $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
305 }
306 $tplheaders->parseCurrentBlock();
307 }
308
309 $style = array();
310 array_push($style, sprintf("width: %.2F%s!important", $layout["percent_row"], "%"));
311 if (count($style) > 0) {
312 $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
313 }
314
315 $template->setCurrentBlock("matrix_row");
316 $template->setVariable("ROW", $tplheaders->get());
317 $template->parseCurrentBlock();
318
319 $rowclass = array("tblrow1", "tblrow2");
320
321 for ($i = 0; $i < $this->object->getRowCount(); $i++) {
322 $rowobj = $this->object->getRow($i);
323 $tplrow = new ilTemplate("tpl.il_svy_qpl_matrix_printview_row.html", true, true, "Modules/SurveyQuestionPool");
324 for ($j = 0; $j < $this->object->getColumnCount(); $j++) {
325 $cat = $this->object->getColumn($j);
326 if (($i == 0) && ($j == 0)) {
327 if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1)))) {
328 $tplrow->setCurrentBlock("bipolar_start");
329 $tplrow->setVariable("TEXT_BIPOLAR_START", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(0)));
330 $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
331 $tplrow->parseCurrentBlock();
332 }
333 }
334 if (($i == 0) && ($j == $this->object->getColumnCount() - 1)) {
335 if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1)))) {
336 $tplrow->setCurrentBlock("bipolar_end");
337 $tplrow->setVariable("TEXT_BIPOLAR_END", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(1)));
338 $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
339 $tplrow->parseCurrentBlock();
340 }
341 }
342
343 $value = ($cat->scale) ? ($cat->scale - 1) : $j;
344 $col = $options[$i]["cols"][$value];
345
346 switch ($this->object->getSubtype()) {
347 case 0:
348 if ($cat->neutral) {
349 $tplrow->setCurrentBlock("neutral_radiobutton");
350 $tplrow->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_" . $col["checked"] . ".png")));
351 $tplrow->setVariable("ALT_RADIO", $this->lng->txt($col["checked"]));
352 $tplrow->setVariable("TITLE_RADIO", $this->lng->txt($col["checked"]));
353 $tplrow->parseCurrentBlock();
354 } else {
355 $tplrow->setCurrentBlock("radiobutton");
356 $tplrow->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_" . $col["checked"] . ".png")));
357 $tplrow->setVariable("ALT_RADIO", $this->lng->txt($col["checked"]));
358 $tplrow->setVariable("TITLE_RADIO", $this->lng->txt($col["checked"]));
359 $tplrow->parseCurrentBlock();
360 }
361 break;
362 case 1:
363 if ($cat->neutral) {
364 $tplrow->setCurrentBlock("neutral_checkbox");
365 $tplrow->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_" . $col["checked"] . ".png")));
366 $tplrow->setVariable("ALT_CHECKBOX", $this->lng->txt($col["checked"]));
367 $tplrow->setVariable("TITLE_CHECKBOX", $this->lng->txt($col["checked"]));
368 $tplrow->parseCurrentBlock();
369 } else {
370 $tplrow->setCurrentBlock("checkbox");
371 $tplrow->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_" . $col["checked"] . ".png")));
372 $tplrow->setVariable("ALT_CHECKBOX", $this->lng->txt($col["checked"]));
373 $tplrow->setVariable("TITLE_CHECKBOX", $this->lng->txt($col["checked"]));
374 $tplrow->parseCurrentBlock();
375 }
376 break;
377 }
378 if ($cat->neutral) {
379 $tplrow->setCurrentBlock("neutral_answer");
380 $style = array();
381 if ($this->object->getNeutralColumnSeparator()) {
382 array_push($style, "border-left: $neutralstyle!important");
383 }
384 if ($this->object->getColumnSeparators() == 1) {
385 if ($j < $this->object->getColumnCount() - 1) {
386 array_push($style, "border-right: 1px solid $bordercolor!important");
387 }
388 }
389
390 if ($this->object->getRowSeparators() == 1) {
391 if ($i < $this->object->getRowCount() - 1) {
392 array_push($style, "border-bottom: 1px solid $bordercolor!important");
393 }
394 }
395 if (count($style)) {
396 $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
397 }
398 $tplrow->parseCurrentBlock();
399 } else {
400 $tplrow->setCurrentBlock("answer");
401 $style = array();
402
403 if ($this->object->getColumnSeparators() == 1) {
404 if ($j < $this->object->getColumnCount() - 1) {
405 array_push($style, "border-right: 1px solid $bordercolor!important");
406 }
407 }
408
409 if ($this->object->getRowSeparators() == 1) {
410 if ($i < $this->object->getRowCount() - 1) {
411 array_push($style, "border-bottom: 1px solid $bordercolor!important");
412 }
413 }
414 if (count($style)) {
415 $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
416 }
417 $tplrow->parseCurrentBlock();
418 }
419 }
420
421 if ($rowobj->other) {
422 $text = $options[$i]["textanswer"];
423 $tplrow->setCurrentBlock("text_other");
424 $tplrow->setVariable("TEXT_OTHER", $text
425 ? $text
426 : "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
427 $tplrow->parseCurrentBlock();
428 }
429
430 #force to have always the title
431 #22526
432 $row_title = ilUtil::prepareFormOutput($rowobj->title);
433 if ($question_title == 3) {
434 if (trim($rowobj->label)) {
435 $row_title .= ' <span class="questionLabel">(' . ilUtil::prepareFormOutput($rowobj->label) . ')</span>';
436 }
437 }
438
439 $tplrow->setVariable("TEXT_ROW", $row_title);
440 $tplrow->setVariable("ROWCLASS", $rowclass[$i % 2]);
441 if ($this->object->getRowSeparators() == 1) {
442 if ($i < $this->object->getRowCount() - 1) {
443 $tplrow->setVariable("STYLE", " style=\"border-bottom: 1px solid $bordercolor!important\"");
444 }
445 }
446 $template->setCurrentBlock("matrix_row");
447 $template->setVariable("ROW", $tplrow->get());
448 $template->parseCurrentBlock();
449 }
450
451 if ($question_title) {
452 $template->setVariable("QUESTION_TITLE", $this->getPrintViewQuestionTitle($question_title));
453 }
454 $template->setCurrentBlock();
455 if ($show_questiontext) {
456 $this->outQuestionText($template);
457 }
458 $template->parseCurrentBlock();
459 return $template->get();
460 }
461
462
463 //
464 // LAYOUT
465 //
466
472 public function layout()
473 {
474 $ilTabs = $this->tabs;
475
476 $ilTabs->activateTab("layout");
477
478 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_layout.html", "Modules/SurveyQuestionPool");
479 $this->show_layout_row = true;
480 $question_output = $this->getWorkingForm();
481 $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
482 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "saveLayout"));
483 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
484 }
485
491 public function saveLayout()
492 {
493 $percent_values = array(
494 "percent_row" => (int) $_POST["percent_row"],
495 "percent_columns" => (int) $_POST["percent_columns"],
496 "percent_bipolar_adjective1" => (int) $_POST['percent_bipolar_adjective1'],
497 "percent_bipolar_adjective2" => (int) $_POST['percent_bipolar_adjective2'],
498 "percent_neutral" => (int) $_POST["percent_neutral"]
499 );
500 $this->object->setLayout($percent_values);
501
502 // #9364
503 if (array_sum($percent_values) == 100) {
504 $this->object->saveLayout(
505 $percent_values["percent_row"],
506 $percent_values['percent_columns'],
507 $percent_values['percent_bipolar_adjective1'],
508 $percent_values['percent_bipolar_adjective2'],
509 $percent_values["percent_neutral"]
510 );
511 ilUtil::sendSuccess($this->lng->txt("settings_saved"));
512 } else {
513 ilUtil::sendFailure($this->lng->txt("svy_matrix_layout_percentages_sum_invalid"));
514 }
515 $this->layout();
516 }
517
523 public function getLayoutRow()
524 {
525 $percent_values = $this->object->getLayout();
526 $template = new ilTemplate("tpl.il_svy_out_matrix_layout.html", true, true, "Modules/SurveyQuestionPool");
527 if (strlen($this->object->getBipolarAdjective(0)) && strlen($this->object->getBipolarAdjective(1))) {
528 $template->setCurrentBlock("bipolar_start");
529 $template->setVariable("VALUE_PERCENT_BIPOLAR_ADJECTIVE1", " value=\"" . $percent_values["percent_bipolar_adjective1"] . "\"");
530 $template->setVariable("STYLE", " style=\"width:" . $percent_values["percent_bipolar_adjective1"] . "%\"");
531 $template->parseCurrentBlock();
532 $template->setCurrentBlock("bipolar_end");
533 $template->setVariable("VALUE_PERCENT_BIPOLAR_ADJECTIVE2", " value=\"" . $percent_values["percent_bipolar_adjective2"] . "\"");
534 $template->setVariable("STYLE", " style=\"width:" . $percent_values["percent_bipolar_adjective2"] . "%\"");
535 $template->parseCurrentBlock();
536 }
537 $counter = $this->object->getColumnCount();
538 if (strlen($this->object->hasNeutralColumn())) {
539 $template->setCurrentBlock("neutral_start");
540 $template->setVariable("VALUE_PERCENT_NEUTRAL", " value=\"" . $percent_values["percent_neutral"] . "\"");
541 $template->setVariable("STYLE_NEUTRAL", " style=\"width:" . $percent_values["percent_neutral"] . "%\"");
542 $template->parseCurrentBlock();
543 $counter--;
544 }
545 $template->setVariable("VALUE_PERCENT_ROW", " value=\"" . $percent_values["percent_row"] . "\"");
546 $template->setVariable("STYLE_ROW", " style=\"width:" . $percent_values["percent_row"] . "%\"");
547 $template->setVariable("COLSPAN_COLUMNS", $counter);
548 $template->setVariable("VALUE_PERCENT_COLUMNS", " value=\"" . $percent_values["percent_columns"] . "\"");
549 $template->setVariable("STYLE_COLUMNS", " style=\"width:" . $percent_values["percent_columns"] . "%\"");
550 return $template->get();
551 }
552
553
554 //
555 // EXECUTION
556 //
557
563 public function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null, $compress_view = false)
564 {
565 $layout = $this->object->getLayout();
566 $neutralstyle = "3px solid #808080";
567 $bordercolor = "#808080";
568 $template = new ilTemplate("tpl.il_svy_out_matrix.html", true, true, "Modules/SurveyQuestionPool");
569 $template->setCurrentBlock("material_matrix");
570 $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
571 $template->parseCurrentBlock();
572
573 if ($this->show_layout_row) {
574 $layout_row = $this->getLayoutRow();
575 $template->setCurrentBlock("matrix_row");
576 $template->setVariable("ROW", $layout_row);
577 $template->parseCurrentBlock();
578 }
579
580 $tplheaders = new ilTemplate("tpl.il_svy_out_matrix_columnheaders.html", true, true, "Modules/SurveyQuestionPool");
581 if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1)))) {
582 $tplheaders->setCurrentBlock("bipolar_start");
583 $style = array();
584 array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective1"], "%"));
585 if (count($style) > 0) {
586 $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
587 }
588 $tplheaders->parseCurrentBlock();
589 }
590 // column headers
591 for ($i = 0; $i < $this->object->getColumnCount(); $i++) {
592 $style = array();
593 $col = $this->object->getColumn($i);
594 if ($col->neutral) {
595 $tplheaders->setCurrentBlock("neutral_column_header");
596 $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($col->title));
597 $tplheaders->setVariable("CLASS", "rsep");
598 $style = array();
599 array_push($style, sprintf("width: %.2f%s!important", $layout["percent_neutral"], "%"));
600 if ($this->object->getNeutralColumnSeparator()) {
601 array_push($style, "border-left: $neutralstyle!important;");
602 }
603 if (count($style) > 0) {
604 $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
605 }
606 $tplheaders->parseCurrentBlock();
607 } else {
608 if ($this->object->getColumnSeparators() == 1) {
609 if (($i < $this->object->getColumnCount() - 1)) {
610 array_push($style, "border-right: 1px solid $bordercolor!important");
611 }
612 }
613 array_push($style, sprintf("width: %.2f%s!important", $layout["percent_columns"] / $this->object->getColumnCount(), "%"));
614 $tplheaders->setCurrentBlock("column_header");
615 $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($col->title));
616 $tplheaders->setVariable("CLASS", "center");
617 if (count($style) > 0) {
618 $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
619 }
620 $tplheaders->parseCurrentBlock();
621 }
622 }
623 if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1)))) {
624 $tplheaders->setCurrentBlock("bipolar_end");
625 $style = array();
626 array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective2"], "%"));
627 if (count($style) > 0) {
628 $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
629 }
630 $tplheaders->parseCurrentBlock();
631 }
632
633 $style = array();
634 array_push($style, sprintf("width: %.2f%s!important", $layout["percent_row"], "%"));
635 if (count($style) > 0) {
636 $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
637 }
638
639 $template->setCurrentBlock("matrix_row");
640 $template->setVariable("ROW", $tplheaders->get());
641 $template->parseCurrentBlock();
642
643 $rowclass = array("tblrow1", "tblrow2");
644 for ($i = 0; $i < $this->object->getRowCount(); $i++) {
645 $rowobj = $this->object->getRow($i);
646 $tplrow = new ilTemplate("tpl.il_svy_out_matrix_row.html", true, true, "Modules/SurveyQuestionPool");
647 for ($j = 0; $j < $this->object->getColumnCount(); $j++) {
648 $cat = $this->object->getColumn($j);
649 if (($i == 0) && ($j == 0)) {
650 if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1)))) {
651 $tplrow->setCurrentBlock("bipolar_start");
652 $tplrow->setVariable("TEXT_BIPOLAR_START", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(0)));
653 $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
654 $tplrow->parseCurrentBlock();
655 }
656 }
657 if (($i == 0) && ($j == $this->object->getColumnCount() - 1)) {
658 if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1)))) {
659 $tplrow->setCurrentBlock("bipolar_end");
660 $tplrow->setVariable("TEXT_BIPOLAR_END", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(1)));
661 $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
662 $tplrow->parseCurrentBlock();
663 }
664 }
665 switch ($this->object->getSubtype()) {
666 case 0:
667 if ($cat->neutral) {
668 $tplrow->setCurrentBlock("neutral_radiobutton");
669 $tplrow->setVariable("QUESTION_ID", $this->object->getId());
670 $tplrow->setVariable("ROW", $i);
671 $tplrow->setVariable("VALUE", ($cat->scale) ? ($cat->scale - 1) : $j);
672 if (is_array($working_data)) {
673 foreach ($working_data as $data) {
674 if (($data["value"] == $cat->scale - 1) && ($data["rowvalue"] == $i)) {
675 $tplrow->setVariable("CHECKED_RADIOBUTTON", " checked=\"checked\"");
676 }
677 }
678 }
679 $tplrow->parseCurrentBlock();
680 } else {
681 $tplrow->setCurrentBlock("radiobutton");
682 $tplrow->setVariable("QUESTION_ID", $this->object->getId());
683 $tplrow->setVariable("ROW", $i);
684 $tplrow->setVariable("VALUE", ($cat->scale) ? ($cat->scale - 1) : $j);
685 if (is_array($working_data)) {
686 foreach ($working_data as $data) {
687 if (($data["value"] == $cat->scale - 1) && ($data["rowvalue"] == $i)) {
688 $tplrow->setVariable("CHECKED_RADIOBUTTON", " checked=\"checked\"");
689 }
690 }
691 }
692 $tplrow->parseCurrentBlock();
693 }
694 break;
695 case 1:
696 if ($cat->neutral) {
697 $tplrow->setCurrentBlock("neutral_checkbox");
698 $tplrow->setVariable("QUESTION_ID", $this->object->getId());
699 $tplrow->setVariable("ROW", $i);
700 $tplrow->setVariable("VALUE", ($cat->scale) ? ($cat->scale - 1) : $j);
701 if (is_array($working_data)) {
702 foreach ($working_data as $data) {
703 if (($data["value"] == $cat->scale - 1) && ($data["rowvalue"] == $i)) {
704 $tplrow->setVariable("CHECKED_CHECKBOX", " checked=\"checked\"");
705 }
706 }
707 }
708 $tplrow->parseCurrentBlock();
709 } else {
710 $tplrow->setCurrentBlock("checkbox");
711 $tplrow->setVariable("QUESTION_ID", $this->object->getId());
712 $tplrow->setVariable("ROW", $i);
713 $tplrow->setVariable("VALUE", ($cat->scale) ? ($cat->scale - 1) : $j);
714 if (is_array($working_data)) {
715 foreach ($working_data as $data) {
716 if (($data["value"] == $cat->scale - 1) && ($data["rowvalue"] == $i)) {
717 $tplrow->setVariable("CHECKED_CHECKBOX", " checked=\"checked\"");
718 }
719 }
720 }
721 $tplrow->parseCurrentBlock();
722 }
723 break;
724 }
725 if ($cat->neutral) {
726 $tplrow->setCurrentBlock("neutral_answer");
727 $style = array();
728 if ($this->object->getNeutralColumnSeparator()) {
729 array_push($style, "border-left: $neutralstyle!important");
730 }
731 if ($this->object->getColumnSeparators() == 1) {
732 if ($j < $this->object->getColumnCount() - 1) {
733 array_push($style, "border-right: 1px solid $bordercolor!important");
734 }
735 }
736 } else {
737 $tplrow->setCurrentBlock("answer");
738 $style = array();
739
740 if ($this->object->getColumnSeparators() == 1) {
741 if ($j < $this->object->getColumnCount() - 1) {
742 array_push($style, "border-right: 1px solid $bordercolor!important");
743 }
744 }
745 }
746 if ($this->object->getRowSeparators() == 1) {
747 if ($i < $this->object->getRowCount() - 1) {
748 array_push($style, "border-bottom: 1px solid $bordercolor!important");
749 }
750 }
751 if (count($style)) {
752 $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
753 }
754 $tplrow->parseCurrentBlock();
755 }
756
757 if ($rowobj->other) {
758 $tplrow->setCurrentBlock("row_other");
759 $tplrow->setVariable("QUESTION_ID", $this->object->getId());
760 $tplrow->setVariable("ROW", $i);
761 if (is_array($working_data)) {
762 foreach ($working_data as $data) {
763 if ($data["rowvalue"] == $i) {
764 $tplrow->setVariable("VALUE_OTHER", ilUtil::prepareFormOutput($data['textanswer']));
765 }
766 }
767 }
768 $tplrow->parseCurrentBlock();
769 }
770 $tplrow->setVariable("TEXT_ROW", ilUtil::prepareFormOutput($rowobj->title));
771 $tplrow->setVariable("ROWCLASS", $rowclass[$i % 2]);
772 if ($this->object->getRowSeparators() == 1) {
773 if ($i < $this->object->getRowCount() - 1) {
774 $tplrow->setVariable("STYLE", " style=\"border-bottom: 1px solid $bordercolor!important\"");
775 }
776 }
777 $template->setCurrentBlock("matrix_row");
778 $template->setVariable("ROW", $tplrow->get());
779 $template->parseCurrentBlock();
780 }
781
782 if ($question_title) {
783 $template->setVariable("QUESTION_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
784 }
785 $template->setCurrentBlock("question_data_matrix");
786 if (strcmp($error_message, "") != 0) {
787 $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
788 }
789 if ($show_questiontext) {
790 $this->outQuestionText($template);
791 }
792 $template->parseCurrentBlock();
793 return $template->get();
794 }
795}
if(! $in) $columns
Definition: Utf8Test.php:45
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
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.
getWorkingForm($working_data="", $question_title=1, $show_questiontext=1, $error_message="", $survey_id=null, $compress_view=false)
Creates the question output form for the learner.
getParsedAnswers(array $a_working_data=null, $a_only_user_anwers=false)
The SurveyMatrixQuestion class defines and encapsulates basic methods and attributes for matrix quest...
Basic class for all survey question types.
getPrintViewQuestionTitle($question_title=1)
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.
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 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
$i
Definition: metadata.php:24
$data
Definition: storeScorm.php:23
$cols
Definition: xhr_table.php:11
$rows
Definition: xhr_table.php:10