ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.SurveyMatrixQuestion.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.SurveyQuestion.php";
25
36{
43
49 var $rows;
50
57
64
72
80
88
89 /*
90 * Layout of the matrix question
91 *
92 * @var array
93 */
95
96 /*
97 * Use placeholders for the column titles
98 *
99 * @var boolean
100 */
102
103 /*
104 * Show a legend
105 *
106 * @var boolean
107 */
109
111
113
115
116 /*
117 * Use random order for rows
118 *
119 * @var boolean
120 */
122
124
126
128
130
131
147
158 function __construct($title = "", $description = "", $author = "", $questiontext = "", $owner = -1)
159 {
160 parent::__construct($title, $description, $author, $questiontext, $owner);
161
162 $this->subtype = 0;
163 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
164 $this->columns = new SurveyCategories();
165 $this->rows = new SurveyCategories();
166 $this->bipolar_adjective1 = "";
167 $this->bipolar_adjective2 = "";
168 $this->rowSeparators = 0;
169 $this->columnSeparators = 0;
170 $this->neutralColumnSeparator = 1;
171 }
172
180 function getColumnCount()
181 {
182 return $this->columns->getCategoryCount();
183 }
184
192 function removeColumn($index)
193 {
194 $this->columns->removeCategory($index);
195 }
196
204 function removeColumns($array)
205 {
206 $this->columns->removeCategories($array);
207 }
208
216 function removeColumnWithName($name)
217 {
218 $this->columns->removeCategoryWithName($name);
219 }
220
224 public function getColumns()
225 {
226 return $this->columns;
227 }
228
237 function getColumn($index)
238 {
239 return $this->columns->getCategory($index);
240 }
241
242 function getColumnForScale($scale)
243 {
244 return $this->columns->getCategoryForScale($scale);
245 }
246
254 function getColumnIndex($name)
255 {
256 return $this->columns->getCategoryIndex($name);
257 }
258
259
266 function flushColumns()
267 {
268 $this->columns->flushCategories();
269 }
270
277 function getRowCount()
278 {
279 return $this->rows->getCategoryCount();
280 }
281
287 function addRow($a_text, $a_other, $a_label)
288 {
289 $this->rows->addCategory($a_text, $a_other, 0, $a_label);
290 }
291
298 function addRowAtPosition($a_text, $a_other, $a_position)
299 {
300 $this->rows->addCategoryAtPosition($a_text, $a_position, $a_other);
301 }
302
309 function flushRows()
310 {
311 $this->rows = new SurveyCategories();
312 }
313
320 function getRow($a_index)
321 {
322 return $this->rows->getCategory($a_index);
323 }
324
325 function moveRowUp($index)
326 {
327 $this->rows->moveCategoryUp($index);
328 }
329
330 function moveRowDown($index)
331 {
332 $this->rows->moveCategoryDown($index);
333 }
334
342 function removeRows($array)
343 {
344 $this->rows->removeCategories($array);
345 }
346
352 public function removeRow($index)
353 {
354 $this->rows->removeCategory($index);
355 }
356
364 function getBipolarAdjective($a_index)
365 {
366 switch ($a_index)
367 {
368 case 1:
369 return (strlen($this->bipolar_adjective2)) ? $this->bipolar_adjective2 : NULL;
370 break;
371 case 0:
372 default:
373 return (strlen($this->bipolar_adjective1)) ? $this->bipolar_adjective1 : NULL;
374 break;
375 }
376 return NULL;
377 }
378
386 function setBipolarAdjective($a_index, $a_value)
387 {
388 switch ($a_index)
389 {
390 case 1:
391 $this->bipolar_adjective2 = $a_value;
392 break;
393 case 0:
394 default:
395 $this->bipolar_adjective1 = $a_value;
396 break;
397 }
398 }
399
406 function addPhrase($phrase_id)
407 {
408 global $ilUser;
409 global $ilDB;
410
411 $result = $ilDB->queryF("SELECT svy_category.* FROM svy_category, svy_phrase_cat WHERE svy_phrase_cat.category_fi = svy_category.category_id AND svy_phrase_cat.phrase_fi = %s AND (svy_category.owner_fi = %s OR svy_category.owner_fi = %s) ORDER BY svy_phrase_cat.sequence",
412 array('integer', 'integer', 'integer'),
413 array($phrase_id, 0, $ilUser->getId())
414 );
415 while ($row = $ilDB->fetchAssoc($result))
416 {
417 $neutral = $row["neutral"];
418 if (($row["defaultvalue"] == 1) && ($row["owner_fi"] == 0))
419 {
420 $this->columns->addCategory($this->lng->txt($row["title"]), 0, $neutral);
421 }
422 else
423 {
424 $this->columns->addCategory($row["title"], 0, $neutral);
425 }
426 }
427 }
428
437 {
438 global $ilDB;
439
440 $result = $ilDB->queryF("SELECT svy_question.*, " . $this->getAdditionalTableName() . ".* FROM svy_question, " . $this->getAdditionalTableName() . " WHERE svy_question.question_id = %s AND svy_question.question_id = " . $this->getAdditionalTableName() . ".question_fi",
441 array('integer'),
442 array($id)
443 );
444 if ($result->numRows() == 1)
445 {
446 return $ilDB->fetchAssoc($result);
447 }
448 else
449 {
450 return array();
451 }
452 }
453
460 function loadFromDb($id)
461 {
462 global $ilDB;
463 $result = $ilDB->queryF("SELECT svy_question.*, " . $this->getAdditionalTableName() . ".* FROM svy_question LEFT JOIN " . $this->getAdditionalTableName() . " ON " . $this->getAdditionalTableName() . ".question_fi = svy_question.question_id WHERE svy_question.question_id = %s",
464 array('integer'),
465 array($id)
466 );
467 if ($result->numRows() == 1)
468 {
469 $data = $ilDB->fetchAssoc($result);
470 $this->setId($data["question_id"]);
471 $this->setTitle($data["title"]);
472 $this->label = $data['label'];
473 $this->setDescription($data["description"]);
474 $this->setObjId($data["obj_fi"]);
475 $this->setAuthor($data["author"]);
476 $this->setOwner($data["owner_fi"]);
477 include_once("./Services/RTE/classes/class.ilRTE.php");
478 $this->setQuestiontext(ilRTE::_replaceMediaObjectImageSrc($data["questiontext"], 1));
479 $this->setObligatory($data["obligatory"]);
480 $this->setComplete($data["complete"]);
481 $this->setOriginalId($data["original_id"]);
482 $this->setSubtype($data["subtype"]);
483 $this->setRowSeparators($data["row_separators"]);
484 $this->setNeutralColumnSeparator($data["neutral_column_separator"]);
485 $this->setColumnSeparators($data["column_separators"]);
486 $this->setColumnPlaceholders($data["column_placeholders"]);
487 $this->setLegend($data["legend"]);
488 $this->setSingleLineRowCaption($data["singleline_row_caption"]);
489 $this->setRepeatColumnHeader($data["repeat_column_header"]);
490 $this->setColumnHeaderPosition($data["column_header_position"]);
491 $this->setRandomRows($data["random_rows"]);
492 $this->setColumnOrder($data["column_order"]);
493 $this->setColumnImages($data["column_images"]);
494 $this->setRowImages($data["row_images"]);
495 $this->setBipolarAdjective(0, $data["bipolar_adjective1"]);
496 $this->setBipolarAdjective(1, $data["bipolar_adjective2"]);
497 $this->setLayout($data["layout"]);
498 $this->flushColumns();
499
500 $result = $ilDB->queryF("SELECT svy_variable.*, svy_category.title, svy_category.neutral FROM svy_variable, svy_category WHERE svy_variable.question_fi = %s AND svy_variable.category_fi = svy_category.category_id ORDER BY sequence ASC",
501 array('integer'),
502 array($id)
503 );
504 if ($result->numRows() > 0)
505 {
506 while ($data = $ilDB->fetchAssoc($result))
507 {
508 $this->columns->addCategory($data["title"], $data["other"], $data["neutral"], null, ($data['scale']) ? $data['scale'] : ($data['sequence'] + 1));
509 }
510 }
511
512 $result = $ilDB->queryF("SELECT * FROM svy_qst_matrixrows WHERE question_fi = %s ORDER BY sequence",
513 array('integer'),
514 array($id)
515 );
516 while ($row = $ilDB->fetchAssoc($result))
517 {
518 $this->addRow($row["title"], $row['other'], $row['label']);
519 }
520 }
521 parent::loadFromDb($id);
522 }
523
530 function isComplete()
531 {
532 if (
533 strlen($this->getTitle()) &&
534 strlen($this->getAuthor()) &&
535 strlen($this->getQuestiontext()) &&
536 $this->getColumnCount() &&
537 $this->getRowCount()
538 )
539 {
540 return 1;
541 }
542 else
543 {
544 return 0;
545 }
546 }
547
553 function saveToDb($original_id = NULL, $withanswers = true)
554 {
555 global $ilDB;
556
557 $affectedRows = parent::saveToDb($original_id);
558
559 if ($affectedRows == 1)
560 {
561 $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
562 array('integer'),
563 array($this->getId())
564 );
565 $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (
566 question_fi, subtype, column_separators, row_separators, neutral_column_separator,column_placeholders,
567 legend, singleline_row_caption, repeat_column_header, column_header_position, random_rows,
568 column_order, column_images, row_images, bipolar_adjective1, bipolar_adjective2, layout, tstamp)
569 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
570 array(
571 'integer', 'integer', 'text', 'text', 'text', 'integer', 'text', 'text', 'text',
572 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer'
573 ),
574 array(
575 $this->getId(),
576 $this->getSubtype(),
577 $this->getColumnSeparators(),
578 $this->getRowSeparators(),
580 $this->getColumnPlaceholders(),
581 $this->getLegend(),
583 $this->getRepeatColumnHeader(),
585 $this->getRandomRows(),
586 $this->getColumnOrder(),
587 $this->getColumnImages(),
588 $this->getRowImages(),
589 $this->getBipolarAdjective(0),
590 $this->getBipolarAdjective(1),
591 serialize($this->getLayout()),
592 time()
593 )
594 );
595
596 // saving material uris in the database
597 $this->saveMaterial();
598
599 $this->saveColumnsToDb();
600 $this->saveRowsToDb();
601 }
602 }
603
604 function saveBipolarAdjectives($adjective1, $adjective2)
605 {
606 global $ilDB;
607
608 $affectedRows = $ilDB->manipulateF("UPDATE " . $this->getAdditionalTableName() . " SET bipolar_adjective1 = %s, bipolar_adjective2 = %s WHERE question_fi = %s",
609 array('text', 'text', 'integer'),
610 array((strlen($adjective1)) ? $adjective1 : NULL, (strlen($adjective2)) ? $adjective2 : NULL, $this->getId())
611 );
612 }
613
622 function saveColumnToDb($columntext, $neutral = 0)
623 {
624 global $ilUser, $ilDB;
625
626 $result = $ilDB->queryF("SELECT title, category_id FROM svy_category WHERE title = %s AND neutral = %s AND owner_fi = %s",
627 array('text', 'text', 'integer'),
628 array($columntext, $neutral, $ilUser->getId())
629 );
630 $insert = FALSE;
631 $returnvalue = "";
632 if ($result->numRows())
633 {
634 $insert = TRUE;
635 while ($row = $ilDB->fetchAssoc($result))
636 {
637 if (strcmp($row["title"], $columntext) == 0)
638 {
639 $returnvalue = $row["category_id"];
640 $insert = FALSE;
641 }
642 }
643 }
644 else
645 {
646 $insert = TRUE;
647 }
648 if ($insert)
649 {
650 $next_id = $ilDB->nextId('svy_category');
651 $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, neutral, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
652 array('integer', 'text', 'text', 'integer', 'text', 'integer'),
653 array($next_id, $columntext, 0, $ilUser->getId(), $neutral, time())
654 );
655 $returnvalue = $next_id;
656 }
657 return $returnvalue;
658 }
659
660 function saveColumnsToDb($original_id = "")
661 {
662 global $ilDB;
663
664 // save columns
665 $question_id = $this->getId();
666 if (strlen($original_id))
667 {
668 $question_id = $original_id;
669 }
670
671 // delete existing column relations
672 $affectedRows = $ilDB->manipulateF("DELETE FROM svy_variable WHERE question_fi = %s",
673 array('integer'),
674 array($question_id)
675 );
676 // create new column relations
677 for ($i = 0; $i < $this->getColumnCount(); $i++)
678 {
679 $cat = $this->getColumn($i);
680 $column_id = $this->saveColumnToDb($cat->title, $cat->neutral);
681 $next_id = $ilDB->nextId('svy_variable');
682 $affectedRows = $ilDB->manipulateF("INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, other, sequence, scale, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
683 array('integer','integer','integer','float','integer','integer', 'integer','integer'),
684 array($next_id, $column_id, $question_id, ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
685 );
686 }
687 $this->saveCompletionStatus($original_id);
688 }
689
690 function saveRowsToDb($original_id = "")
691 {
692 global $ilDB;
693
694 // save rows
695 $question_id = $this->getId();
696 if (strlen($original_id))
697 {
698 $question_id = $original_id;
699 }
700
701 // delete existing rows
702 $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qst_matrixrows WHERE question_fi = %s",
703 array('integer'),
704 array($question_id)
705 );
706 // create new rows
707 for ($i = 0; $i < $this->getRowCount(); $i++)
708 {
709 $row = $this->getRow($i);
710 $next_id = $ilDB->nextId('svy_qst_matrixrows');
711 $affectedRows = $ilDB->manipulateF("INSERT INTO svy_qst_matrixrows (id_svy_qst_matrixrows, title, label, other, sequence, question_fi) VALUES (%s, %s, %s, %s, %s, %s)",
712 array('integer','text','text','integer','integer','integer'),
713 array($next_id, $row->title, $row->label, ($row->other) ? 1 : 0, $i, $question_id)
714 );
715 }
716 $this->saveCompletionStatus($original_id);
717 }
718
725 function toXML($a_include_header = TRUE, $obligatory_state = "")
726 {
727 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
728 $a_xml_writer = new ilXmlWriter;
729 $a_xml_writer->xmlHeader();
730 $this->insertXML($a_xml_writer, $a_include_header, $obligatory_state);
731 $xml = $a_xml_writer->xmlDumpMem(FALSE);
732 if (!$a_include_header)
733 {
734 $pos = strpos($xml, "?>");
735 $xml = substr($xml, $pos + 2);
736 }
737 return $xml;
738 }
739
747 function insertXML(&$a_xml_writer, $a_include_header = TRUE)
748 {
749 $attrs = array(
750 "id" => $this->getId(),
751 "title" => $this->getTitle(),
752 "type" => $this->getQuestiontype(),
753 "subtype" => $this->getSubtype(),
754 "obligatory" => $this->getObligatory()
755 );
756 $a_xml_writer->xmlStartTag("question", $attrs);
757
758 $a_xml_writer->xmlElement("description", NULL, $this->getDescription());
759 $a_xml_writer->xmlElement("author", NULL, $this->getAuthor());
760 $a_xml_writer->xmlStartTag("questiontext");
761 $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
762 $a_xml_writer->xmlEndTag("questiontext");
763
764 $a_xml_writer->xmlStartTag("matrix");
765 $a_xml_writer->xmlStartTag("matrixrows");
766 for ($i = 0; $i < $this->getRowCount(); $i++)
767 {
768 $attrs = array(
769 "id" => $i
770 );
771 if (strlen($this->getRow($i)->label))
772 {
773 $attrs['label'] = $this->getRow($i)->label;
774 }
775 if ($this->getRow($i)->other)
776 {
777 $attrs['other'] = 1;
778 }
779 $a_xml_writer->xmlStartTag("matrixrow", $attrs);
780 $this->addMaterialTag($a_xml_writer, $this->getRow($i)->title);
781 $a_xml_writer->xmlEndTag("matrixrow");
782 }
783 $a_xml_writer->xmlEndTag("matrixrows");
784
785 $a_xml_writer->xmlStartTag("responses");
786 if (strlen($this->getBipolarAdjective(0)) && (strlen($this->getBipolarAdjective(1))))
787 {
788 $a_xml_writer->xmlStartTag("bipolar_adjectives");
789 $attribs = array(
790 "label" => "0"
791 );
792 $a_xml_writer->xmlElement("adjective", $attribs, $this->getBipolarAdjective(0));
793 $attribs = array(
794 "label" => "1"
795 );
796 $a_xml_writer->xmlElement("adjective", $attribs, $this->getBipolarAdjective(1));
797 $a_xml_writer->xmlEndTag("bipolar_adjectives");
798 }
799 for ($i = 0; $i < $this->getColumnCount(); $i++)
800 {
801 $attrs = array(
802 "id" => $i
803 );
804 if ($this->getColumn($i)->neutral)
805 {
806 $attrs['label'] = 'neutral';
807 }
808 switch ($this->getSubtype())
809 {
810 case 0:
811 $a_xml_writer->xmlStartTag("response_single", $attrs);
812 break;
813 case 1:
814 $a_xml_writer->xmlStartTag("response_multiple", $attrs);
815 break;
816 }
817 $this->addMaterialTag($a_xml_writer, $this->getColumn($i)->title);
818 switch ($this->getSubtype())
819 {
820 case 0:
821 $a_xml_writer->xmlEndTag("response_single");
822 break;
823 case 1:
824 $a_xml_writer->xmlEndTag("response_multiple");
825 break;
826 }
827 }
828
829 $a_xml_writer->xmlEndTag("responses");
830 $a_xml_writer->xmlEndTag("matrix");
831
832 if (count($this->material))
833 {
834 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
835 {
836 $attrs = array(
837 "label" => $this->material["title"]
838 );
839 $a_xml_writer->xmlStartTag("material", $attrs);
840 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
841 if (strcmp($matches[1], "") != 0)
842 {
843 $intlink = $this->material["internal_link"];
844 }
845 $a_xml_writer->xmlElement("mattext", NULL, $intlink);
846 $a_xml_writer->xmlEndTag("material");
847 }
848 }
849
850 $a_xml_writer->xmlStartTag("metadata");
851 $a_xml_writer->xmlStartTag("metadatafield");
852 $a_xml_writer->xmlElement("fieldlabel", NULL, "column_separators");
853 $a_xml_writer->xmlElement("fieldentry", NULL, $this->getColumnSeparators());
854 $a_xml_writer->xmlEndTag("metadatafield");
855
856 $a_xml_writer->xmlStartTag("metadatafield");
857 $a_xml_writer->xmlElement("fieldlabel", NULL, "row_separators");
858 $a_xml_writer->xmlElement("fieldentry", NULL, $this->getRowSeparators());
859 $a_xml_writer->xmlEndTag("metadatafield");
860
861 $a_xml_writer->xmlStartTag("metadatafield");
862 $a_xml_writer->xmlElement("fieldlabel", NULL, "neutral_column_separator");
863 $a_xml_writer->xmlElement("fieldentry", NULL, $this->getNeutralColumnSeparator());
864 $a_xml_writer->xmlEndTag("metadatafield");
865
866 $a_xml_writer->xmlStartTag("metadatafield");
867 $a_xml_writer->xmlElement("fieldlabel", NULL, "layout");
868 $a_xml_writer->xmlElement("fieldentry", NULL, serialize($this->getLayout()));
869 $a_xml_writer->xmlEndTag("metadatafield");
870
871 $a_xml_writer->xmlEndTag("metadata");
872
873 $a_xml_writer->xmlEndTag("question");
874 }
875
877 {
878 if ($this->getOriginalId())
879 {
880 parent::syncWithOriginal();
881 $this->saveColumnsToDb($this->getOriginalId());
882 $this->saveRowsToDb($this->getOriginalId());
883 }
884 }
885
886
894 function addStandardNumbers($lower_limit, $upper_limit)
895 {
896 for ($i = $lower_limit; $i <= $upper_limit; $i++)
897 {
898 $this->columns->addCategory($i);
899 }
900 }
901
910 {
911 global $ilUser;
912 global $ilDB;
913
914 $next_id = $ilDB->nextId('svy_phrase');
915 $affectedRows = $ilDB->manipulateF("INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
916 array('integer','text','text','integer','integer'),
917 array($next_id, $title, 1, $ilUser->getId(), time())
918 );
919 $phrase_id = $next_id;
920
921 $counter = 1;
922 foreach ($_SESSION['save_phrase_data'] as $data)
923 {
924 $next_id = $ilDB->nextId('svy_category');
925 $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
926 array('integer','text','text','integer','integer','text'),
927 array($next_id, $data['answer'], 1, $ilUser->getId(), time(), $data['neutral'])
928 );
929 $category_id = $next_id;
930 $next_id = $ilDB->nextId('svy_phrase_cat');
931 $affectedRows = $ilDB->manipulateF("INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence, other, scale) VALUES (%s, %s, %s, %s, %s, %s)",
932 array('integer', 'integer', 'integer','integer', 'integer', 'integer'),
933 array($next_id, $phrase_id, $category_id, $counter, ($data['other']) ? 1 : 0, $data['scale'])
934 );
935 $counter++;
936 }
937 }
938
946 {
947 return "SurveyMatrixQuestion";
948 }
949
957 {
958 return "svy_qst_matrix";
959 }
960
967 function &getWorkingDataFromUserInput($post_data)
968 {
969 $data = array();
970 foreach ($post_data as $key => $value)
971 {
972 switch ($this->getSubtype())
973 {
974 case 0:
975 if (preg_match("/matrix_" . $this->getId() . "_(\d+)/", $key, $matches))
976 {
977 if (is_array($value))
978 {
979 foreach ($value as $val)
980 {
981 array_push($data, array("value" => $val, "rowvalue" => $matches[1], "textanswer" => $post_data['matrix_other_' . $this->getId() . '_' . $matches[1]]));
982 }
983 }
984 else
985 {
986 array_push($data, array("value" => $value, "rowvalue" => $matches[1], "textanswer" => $post_data['matrix_other_' . $this->getId() . '_' . $matches[1]]));
987 }
988 }
989 break;
990 case 1:
991 if (preg_match("/matrix_" . $this->getId() . "_(\d+)/", $key, $matches))
992 {
993 if (is_array($value))
994 {
995 foreach ($value as $val)
996 {
997 array_push($data, array("value" => $val, "rowvalue" => $matches[1], "textanswer" => $post_data['matrix_other_' . $this->getId() . '_' . $matches[1]]));
998 }
999 }
1000 else
1001 {
1002 array_push($data, array("value" => $value, "rowvalue" => $matches[1], "textanswer" => $post_data['matrix_other_' . $this->getId() . '_' . $matches[1]]));
1003 }
1004 }
1005 break;
1006 }
1007 }
1008 return $data;
1009 }
1010
1020 function checkUserInput($post_data, $survey_id)
1021 {
1022 if (!$this->getObligatory($survey_id)) return "";
1023 switch ($this->getSubtype())
1024 {
1025 case 0:
1026 $counter = 0;
1027 foreach ($post_data as $key => $value)
1028 {
1029 if (preg_match("/matrix_" . $this->getId() . "_(\d+)/", $key, $matches))
1030 {
1031 if (array_key_exists('matrix_other_' . $this->getId() . "_" . $matches[1], $post_data) && strlen($post_data['matrix_other_' . $this->getId() . "_" . $matches[1]]) == 0)
1032 {
1033 return $this->lng->txt("question_mr_no_other_answer");
1034 }
1035 $counter++;
1036 }
1037 }
1038 if ($counter != $this->getRowCount()) return $this->lng->txt("matrix_question_radio_button_not_checked");
1039 break;
1040 case 1:
1041 $counter = 0;
1042 foreach ($post_data as $key => $value)
1043 {
1044 if (preg_match("/matrix_" . $this->getId() . "_(\d+)/", $key, $matches))
1045 {
1046 if (array_key_exists('matrix_other_' . $this->getId() . "_" . $matches[1], $post_data) && strlen($post_data['matrix_other_' . $this->getId() . "_" . $matches[1]]) == 0)
1047 {
1048 return $this->lng->txt("question_mr_no_other_answer");
1049 }
1050 $counter++;
1051 if ((!is_array($value)) || (count($value) < 1))
1052 {
1053 return $this->lng->txt("matrix_question_checkbox_not_checked");
1054 }
1055 }
1056 }
1057 if ($counter != $this->getRowCount()) return $this->lng->txt("matrix_question_checkbox_not_checked");
1058 break;
1059 }
1060 return "";
1061 }
1062
1063 function saveUserInput($post_data, $active_id, $a_return = false)
1064 {
1065 global $ilDB;
1066
1067 $answer_data = array();
1068
1069 // gather data
1070 switch ($this->getSubtype())
1071 {
1072 case 0:
1073 foreach ($post_data as $key => $value)
1074 {
1075 if (preg_match("/matrix_" . $this->getId() . "_(\d+)/", $key, $matches))
1076 {
1077 if(strlen($value))
1078 {
1079 $other_value = (array_key_exists('matrix_other_' . $this->getId() . '_' . $matches[1], $post_data))
1080 ? ($post_data['matrix_other_' . $this->getId() . '_' . $matches[1]])
1081 : null;
1082 $answer_data[] = array("value"=>$value,
1083 "textanswer"=>$other_value,
1084 "rowvalue"=>$matches[1]);
1085 }
1086 }
1087 }
1088 break;
1089
1090 case 1:
1091 foreach ($post_data as $key => $value)
1092 {
1093 if (preg_match("/matrix_" . $this->getId() . "_(\d+)/", $key, $matches))
1094 {
1095 $other_value = (array_key_exists('matrix_other_' . $this->getId() . '_' . $matches[1], $post_data))
1096 ? ($post_data['matrix_other_' . $this->getId() . '_' . $matches[1]])
1097 : null;
1098 foreach ($value as $checked)
1099 {
1100 $answer_data[] = array("value"=>$checked,
1101 "textanswer"=>$other_value,
1102 "rowvalue"=>$matches[1]);
1103 }
1104 }
1105 }
1106 break;
1107 }
1108
1109 if ($a_return)
1110 {
1111 return $answer_data;
1112 }
1113
1114 // #16387 - only if any input
1115 if(sizeof($answer_data))
1116 {
1117 // save data
1118 foreach ($answer_data as $item)
1119 {
1120 $next_id = $ilDB->nextId('svy_answer');
1121 #20216
1122 $fields = array();
1123 $fields['answer_id'] = array("integer", $next_id);
1124 $fields['question_fi'] = array("integer", $this->getId());
1125 $fields['active_fi'] = array("integer", $active_id);
1126 $fields['value'] = array("float", $item['value']);
1127 $fields['textanswer'] = array("clob", $item['textanswer']);
1128 $fields['rowvalue'] = array("integer", $item['rowvalue']);
1129 $fields['tstamp'] = array("integer", time());
1130
1131 $affectedRows = $ilDB->insert("svy_answer", $fields);
1132
1133 }
1134 }
1135 }
1136
1143 function deleteAdditionalTableData($question_id)
1144 {
1145 parent::deleteAdditionalTableData($question_id);
1146
1147 global $ilDB;
1148 $affectedRows = $ilDB->manipulateF("DELETE FROM svy_qst_matrixrows WHERE question_fi = %s",
1149 array('integer'),
1150 array($question_id)
1151 );
1152 }
1153
1160 function getSubtype()
1161 {
1162 return $this->subtype;
1163 }
1164
1171 function setSubtype($a_subtype = 0)
1172 {
1173 switch ($a_subtype)
1174 {
1175 case 1:
1176 case 2:
1177 case 3:
1178 case 4:
1179 case 5:
1180 case 6:
1181 $this->subtype = $a_subtype;
1182 break;
1183 case 0:
1184 default:
1185 $this->subtype = 0;
1186 break;
1187 }
1188 }
1189
1196 function setColumnSeparators($enable = 0)
1197 {
1198 switch ($enable)
1199 {
1200 case 1:
1201 $this->columnSeparators = 1;
1202 break;
1203 case 0:
1204 default:
1205 $this->columnSeparators = 0;
1206 break;
1207 }
1208 }
1209
1217 {
1218 return ($this->columnSeparators) ? 1 : 0;
1219 }
1220
1227 function setRowSeparators($enable = 0)
1228 {
1229 switch ($enable)
1230 {
1231 case 1:
1232 $this->rowSeparators = 1;
1233 break;
1234 case 0:
1235 default:
1236 $this->rowSeparators = 0;
1237 break;
1238 }
1239 }
1240
1248 {
1249 return ($this->rowSeparators) ? 1 : 0;
1250 }
1251
1258 function setNeutralColumnSeparator($enable = 0)
1259 {
1260 switch ($enable)
1261 {
1262 case 1:
1263 $this->neutralColumnSeparator = 1;
1264 break;
1265 case 0:
1266 default:
1267 $this->neutralColumnSeparator = 0;
1268 break;
1269 }
1270 }
1271
1279 {
1280 return ($this->neutralColumnSeparator) ? 1 : 0;
1281 }
1282
1292 {
1293 foreach ($a_meta as $key => $value)
1294 {
1295 switch ($value["label"])
1296 {
1297 case "column_separators":
1298 $this->setColumnSeparators($value["entry"]);
1299 break;
1300 case "row_separators":
1301 $this->setRowSeparators($value["entry"]);
1302 break;
1303 case "layout":
1304 $this->setLayout($value["entry"]);
1305 break;
1306 case "neutral_column_separator":
1307 $this->setNeutralColumnSeparator($value["entry"]);
1308 break;
1309 }
1310 }
1311 }
1312
1319 function importAdjectives($a_data)
1320 {
1321 $i = 0;
1322 foreach ($a_data as $adjective)
1323 {
1324 if (is_numeric($adjective["label"]))
1325 {
1326 $this->setBipolarAdjective($adjective["label"], $adjective["text"]);
1327 }
1328 else
1329 {
1330 $this->setBipolarAdjective($i, $adjective["text"]);
1331 }
1332 $i++;
1333 }
1334 }
1335
1342 function importMatrix($a_data)
1343 {
1344 foreach ($a_data as $row)
1345 {
1346 $this->addRow($row['title'], $row['other'], $row['label']);
1347 }
1348 }
1349
1356 function importResponses($a_data)
1357 {
1358 foreach ($a_data as $id => $data)
1359 {
1360 $column = "";
1361 foreach ($data["material"] as $material)
1362 {
1363 $column .= $material["text"];
1364 }
1365 $this->columns->addCategory($column, null, (strcmp($data["label"], "neutral") == 0) ? true : false);
1366 }
1367 }
1368
1376 {
1377 return FALSE;
1378 }
1379
1388 {
1389 return $value;
1390 }
1391
1398 public function getPreconditionSelectValue($default = "", $title, $variable)
1399 {
1400 include_once "./Services/Form/classes/class.ilSelectInputGUI.php";
1401 $step3 = new ilSelectInputGUI($title, $variable);
1403 $step3->setOptions($options);
1404 $step3->setValue($default);
1405 return $step3;
1406 }
1407
1417 function saveLayout($percent_row, $percent_columns, $percent_bipolar_adjective1 = "", $percent_bipolar_adjective2 = "", $percent_neutral)
1418 {
1419 global $ilDB;
1420
1421 $layout = array(
1422 "percent_row" => $percent_row,
1423 "percent_columns" => $percent_columns,
1424 "percent_bipolar_adjective1" => $percent_bipolar_adjective1,
1425 "percent_bipolar_adjective2" => $percent_bipolar_adjective2,
1426 "percent_neutral" => $percent_neutral
1427 );
1428 $affectedRows = $ilDB->manipulateF("UPDATE " . $this->getAdditionalTableName() . " SET layout = %s WHERE question_fi = %s",
1429 array('text', 'integer'),
1430 array(serialize($layout), $this->getId())
1431 );
1432 }
1433
1434 function getLayout()
1435 {
1436 if (!is_array($this->layout) || count($this->layout) == 0)
1437 {
1438 if ($this->hasBipolarAdjectives() && $this->hasNeutralColumn())
1439 {
1440 $this->layout = array(
1441 "percent_row" => 30,
1442 "percent_columns" => 40,
1443 "percent_bipolar_adjective1" => 10,
1444 "percent_bipolar_adjective2" => 10,
1445 "percent_neutral" => 10
1446 );
1447 }
1448 elseif ($this->hasBipolarAdjectives())
1449 {
1450 $this->layout = array(
1451 "percent_row" => 30,
1452 "percent_columns" => 50,
1453 "percent_bipolar_adjective1" => 10,
1454 "percent_bipolar_adjective2" => 10,
1455 "percent_neutral" => 0
1456 );
1457 }
1458 elseif ($this->hasNeutralColumn())
1459 {
1460 $this->layout = array(
1461 "percent_row" => 30,
1462 "percent_columns" => 50,
1463 "percent_bipolar_adjective1" => 0,
1464 "percent_bipolar_adjective2" => 0,
1465 "percent_neutral" => 20
1466 );
1467 }
1468 else
1469 {
1470 $this->layout = array(
1471 "percent_row" => 30,
1472 "percent_columns" => 70,
1473 "percent_bipolar_adjective1" => 0,
1474 "percent_bipolar_adjective2" => 0,
1475 "percent_neutral" => 0
1476 );
1477 }
1478 }
1479 return $this->layout;
1480 }
1481
1483 {
1484 if (is_array($layout))
1485 {
1486 $this->layout = $layout;
1487 }
1488 else
1489 {
1490 $this->layout = unserialize($layout);
1491 }
1492 }
1493
1500 {
1501 if ((strlen($this->getBipolarAdjective(0))) && (strlen($this->getBipolarAdjective(1))))
1502 {
1503 return TRUE;
1504 }
1505 else
1506 {
1507 return FALSE;
1508 }
1509 }
1510
1517 {
1518 for ($i = 0; $i < $this->getColumnCount(); $i++)
1519 {
1520 $column = $this->getColumn($i);
1521 if ($column->neutral && strlen($column->title)) return true;
1522 }
1523 return FALSE;
1524 }
1525
1531 function setColumnPlaceholders($a_value = 0)
1532 {
1533 $this->columnPlaceholders = ($a_value) ? 1 : 0;
1534 }
1535
1542 {
1543 return ($this->columnPlaceholders) ? 1 : 0;
1544 }
1545
1551 function setLegend($a_value = 0)
1552 {
1553 $this->legend = ($a_value) ? 1 : 0;
1554 }
1555
1561 function getLegend()
1562 {
1563 return ($this->legend) ? 1 : 0;
1564 }
1565
1566 function setSingleLineRowCaption($a_value = 0)
1567 {
1568 $this->singleLineRowCaption = ($a_value) ? 1 : 0;
1569 }
1570
1572 {
1573 return ($this->singleLineRowCaption) ? 1 : 0;
1574 }
1575
1576 function setRepeatColumnHeader($a_value = 0)
1577 {
1578 $this->repeatColumnHeader = ($a_value) ? 1 : 0;
1579 }
1580
1582 {
1583 return ($this->repeatColumnHeader) ? 1 : 0;
1584 }
1585
1586 function setColumnHeaderPosition($a_value)
1587 {
1588 $this->columnHeaderPosition = $a_value;
1589 }
1590
1592 {
1593 return ($this->columnHeaderPosition) ? $this->columnHeaderPosition : 0;
1594 }
1595
1596 function setRandomRows($a_value = 0)
1597 {
1598 $this->randomRows = ($a_value) ? 1 : 0;
1599 }
1600
1601 function getRandomRows()
1602 {
1603 return ($this->randomRows) ? 1 : 0;
1604 }
1605
1606 function setColumnOrder($a_value)
1607 {
1608 $this->columnOrder = $a_value;
1609 }
1610
1612 {
1613 return ($this->columnOrder) ? $this->columnOrder : 0;
1614 }
1615
1616 function setColumnImages($a_value = 0)
1617 {
1618 $this->columnImages = ($a_value) ? 1 : 0;
1619 }
1620
1622 {
1623 return ($this->columnImages) ? 1 : 0;
1624 }
1625
1626 function setRowImages($a_value = 0)
1627 {
1628 $this->rowImages = ($a_value) ? 1 : 0;
1629 }
1630
1631 function getRowImages()
1632 {
1633 return ($this->rowImages) ? 1 : 0;
1634 }
1635
1636 public function getRows()
1637 {
1638 return $this->rows;
1639 }
1640}
1641
1642?>
$column
Definition: 39dropdown.php:62
$result
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
Class SurveyCategories.
The SurveyMatrixQuestion class defines and encapsulates basic methods and attributes for matrix quest...
hasNeutralColumn()
Returns TRUE if a neutral column exists.
addRow($a_text, $a_other, $a_label)
Adds a row to the question.
addStandardNumbers($lower_limit, $upper_limit)
Adds standard numbers as columns.
setSubtype($a_subtype=0)
Sets the subtype of the matrix question.
__construct($title="", $description="", $author="", $questiontext="", $owner=-1)
SurveyMatrixQuestion constructor The constructor takes possible arguments an creates an instance of t...
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setRowSeparators($enable=0)
Enables/Disables separators for the matrix rows.
setBipolarAdjective($a_index, $a_value)
Sets one of the bipolar adjectives.
importMatrix($a_data)
Import matrix rows from the question import file.
removeRow($index)
Removes a row.
saveToDb($original_id=NULL, $withanswers=true)
Saves a SurveyMatrixQuestion object to a database.
importAdjectives($a_data)
Import bipolar adjectives from the question import file.
saveLayout($percent_row, $percent_columns, $percent_bipolar_adjective1="", $percent_bipolar_adjective2="", $percent_neutral)
Saves the layout of a matrix question.
getColumnIndex($name)
Returns the index of a column with a given name.
removeRows($array)
Removes rows from the question.
getQuestionDataArray($id)
Returns the question data fields from the database.
flushRows()
Empties the row list.
getBipolarAdjective($a_index)
Returns one of the bipolar adjectives.
saveUserInput($post_data, $active_id, $a_return=false)
removeColumnWithName($name)
Removes a column from the list of columns.
setColumnSeparators($enable=0)
Enables/Disables separators for the matrix columns.
insertXML(&$a_xml_writer, $a_include_header=TRUE)
Adds the question XML to a given XMLWriter object.
getSubtype()
Returns the subtype of the matrix question.
savePhrase($title)
Saves a set of columns to a default phrase.
getNeutralColumnSeparator()
Gets the separator enable state for the neutral column.
getLegend()
Get whether the legend should be shown or not.
saveColumnToDb($columntext, $neutral=0)
Saves a column to the database.
& getWorkingDataFromUserInput($post_data)
Creates the user data of the svy_answer table from the POST data.
getQuestionType()
Returns the question type of the question.
getColumn($index)
Returns the name of a column for a given index.
flushColumns()
Empties the columns list.
usableForPrecondition()
Returns if the question is usable for preconditions.
checkUserInput($post_data, $survey_id)
Checks the input of the active user for obligatory status and entered values.
setNeutralColumnSeparator($enable=0)
Enables/Disables a separator for the neutral column.
addPhrase($phrase_id)
Adds a phrase to the question.
importAdditionalMetadata($a_meta)
Import additional meta data from the question import file.
setColumnPlaceholders($a_value=0)
Set whether placeholders should be used for the column titles or not.
getColumnSeparators()
Gets the separators enable state for the matrix columns.
setLegend($a_value=0)
Set whether the legend should be shown or not.
removeColumn($index)
Removes a column from the list of columns.
toXML($a_include_header=TRUE, $obligatory_state="")
Returns an xml representation of the question.
removeColumns($array)
Removes many columns from the list of columns.
getColumnPlaceholders()
Get whether placeholders should be used for the column titles or not.
saveBipolarAdjectives($adjective1, $adjective2)
getColumnCount()
Returns the number of columns.
hasBipolarAdjectives()
Returns TRUE if bipolar adjectives exist.
getPreconditionValueOutput($value)
Returns the output for a precondition value.
loadFromDb($id)
Loads a SurveyMatrixQuestion object from the database.
getRow($a_index)
Returns a specific row.
importResponses($a_data)
Import response data from the question import file.
deleteAdditionalTableData($question_id)
Deletes datasets from the additional question table in the database.
getPreconditionSelectValue($default="", $title, $variable)
Creates a form property for the precondition value.
getRowCount()
Returns the number of rows in the question.
addRowAtPosition($a_text, $a_other, $a_position)
Adds a row at a given position.
getRowSeparators()
Gets the separators enable state for the matrix rows.
isComplete()
Returns 1 if the question is complete for use.
Basic class for all survey question types.
setQuestiontext($questiontext="")
Sets the questiontext of the SurveyQuestion object.
setId($id=-1)
Sets the id of the SurveyQuestion object.
setAuthor($author="")
Sets the authors name of the SurveyQuestion object.
getDescription()
Gets the description string of the SurveyQuestion object.
getId()
Gets the id of the SurveyQuestion object.
setDescription($description="")
Sets the description string of the SurveyQuestion object.
setObjId($obj_id=0)
Set the reference id of the container object.
getAuthor()
Gets the authors name of the SurveyQuestion object.
setOriginalId($original_id)
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getObligatory($survey_id="")
Gets the obligatory state of the question.
getTitle()
Gets the title string of the SurveyQuestion object.
setComplete($a_complete)
Sets the complete state of the question.
getPreconditionOptions()
Returns the options for preconditions.
saveMaterial()
save material to db
setOwner($owner="")
Sets the creator/owner ID of the SurveyQuestion object.
setTitle($title="")
Sets the title string of the SurveyQuestion object.
saveCompletionStatus($original_id="")
Saves the complete flag to the database.
addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag=TRUE, $add_mobs=TRUE, $a_attrs=null)
Creates an XML material tag from a plain text or xhtml text.
setObligatory($obligatory=1)
Sets the obligatory state of the question.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
This class represents a selection list property in a property form.
XML writer class.
xmlHeader()
Writes xml header @access public.
$counter
$insert
global $ilDB
if(!is_array($argv)) $options
$ilUser
Definition: imgupload.php:18