66 $this->
user = $DIC->user();
67 $this->db = $DIC->database();
73 $this->bipolar_adjective1 =
"";
74 $this->bipolar_adjective2 =
"";
75 $this->rowSeparators = 0;
76 $this->columnSeparators = 0;
77 $this->neutralColumnSeparator = 1;
82 return $this->columns->getCategoryCount();
87 $this->columns->removeCategory($index);
95 $this->columns->removeCategories($array);
100 $this->columns->removeCategoryWithName($name);
110 return $this->columns->getCategory($index);
115 return $this->columns->getCategoryForScale($scale);
120 return $this->columns->getCategoryIndex($name);
125 $this->columns->flushCategories();
130 return $this->rows->getCategoryCount();
138 $this->rows->addCategory($a_text, (
int) $a_other, 0, $a_label);
146 $this->rows->addCategoryAtPosition($a_text, $a_position, $a_other);
156 return $this->rows->getCategory($a_index);
161 $this->rows->moveCategoryUp($index);
166 $this->rows->moveCategoryDown($index);
174 $this->rows->removeCategories($array);
179 $this->rows->removeCategory($index);
188 if ($a_index === 1) {
198 if ($a_index === 1) {
199 $this->bipolar_adjective2 = $a_value;
201 $this->bipolar_adjective1 = $a_value;
213 $result =
$ilDB->queryF(
214 "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",
215 array(
'integer',
'integer',
'integer'),
216 array($phrase_id, 0,
$ilUser->getId())
218 while ($row =
$ilDB->fetchAssoc($result)) {
219 $neutral = $row[
"neutral"];
220 if ((
int) $row[
"defaultvalue"] === 1 && (
int) $row[
"owner_fi"] === 0) {
221 $this->columns->addCategory($this->
lng->txt($row[
"title"]), 0, $neutral);
223 $this->columns->addCategory($row[
"title"], 0, $neutral);
235 $result =
$ilDB->queryF(
240 if ($result->numRows() === 1) {
241 return $ilDB->fetchAssoc($result);
250 $result =
$ilDB->queryF(
255 if ($result->numRows() === 1) {
258 $this->
setTitle((
string) $data[
"title"]);
259 $this->label = (string) $data[
'label'];
261 $this->
setObjId((
int) $data[
"obj_fi"]);
262 $this->
setAuthor((
string) $data[
"author"]);
263 $this->
setOwner((
int) $data[
"owner_fi"]);
273 $this->
setLegend((
bool) $data[
"legend"]);
281 $result =
$ilDB->queryF(
282 "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",
286 if ($result->numRows() > 0) {
287 while ($data =
$ilDB->fetchAssoc($result)) {
288 $this->columns->addCategory((
string) $data[
"title"], (
int) $data[
"other"], (
int) $data[
"neutral"], null, ($data[
'scale']) ?: ($data[
'sequence'] + 1));
292 $result =
$ilDB->queryF(
293 "SELECT * FROM svy_qst_matrixrows WHERE question_fi = %s ORDER BY sequence",
297 while ($row =
$ilDB->fetchAssoc($result)) {
298 $this->
addRow((
string) $row[
"title"], (
string) $row[
'other'], (
string) ($row[
'label'] ??
""));
301 parent::loadFromDb($question_id);
321 if ($affectedRows === 1) {
325 array($this->
getId())
329 question_fi, subtype, column_separators, row_separators, neutral_column_separator,column_placeholders, 330 legend, singleline_row_caption, repeat_column_header, 331 bipolar_adjective1, bipolar_adjective2, layout, tstamp) 332 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
334 'integer',
'integer',
'text',
'text',
'text',
'integer',
'text',
'text',
'text',
335 'text',
'text',
'text',
'integer' 360 return $affectedRows;
370 "UPDATE " . $this->
getAdditionalTableName() .
" SET bipolar_adjective1 = %s, bipolar_adjective2 = %s WHERE question_fi = %s",
371 array(
'text',
'text',
'integer'),
372 array(($adjective1 !==
'') ? $adjective1 : null, ($adjective2 !==
'') ? $adjective2 : null, $this->
getId())
383 $result =
$ilDB->queryF(
384 "SELECT title, category_id FROM svy_category WHERE title = %s AND neutral = %s AND owner_fi = %s",
385 array(
'text',
'text',
'integer'),
386 array($columntext, $neutral,
$ilUser->getId())
391 if ($result->numRows()) {
392 while ($row =
$ilDB->fetchAssoc($result)) {
393 if (strcmp($row[
"title"] ??
'', $columntext) === 0) {
394 $returnvalue = $row[
"category_id"];
400 $next_id =
$ilDB->nextId(
'svy_category');
401 $affectedRows =
$ilDB->manipulateF(
402 "INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, neutral, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
403 array(
'integer',
'text',
'text',
'integer',
'text',
'integer'),
404 array($next_id, $columntext, 0,
$ilUser->getId(), $neutral, time())
406 $returnvalue = $next_id;
417 $question_id = $this->
getId();
423 $affectedRows =
$ilDB->manipulateF(
424 "DELETE FROM svy_variable WHERE question_fi = %s",
432 $next_id =
$ilDB->nextId(
'svy_variable');
433 $affectedRows =
$ilDB->manipulateF(
434 "INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, other, sequence, scale, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
435 array(
'integer',
'integer',
'integer',
'float',
'integer',
'integer',
'integer',
'integer'),
436 array($next_id, $column_id, $question_id, (
$i + 1), $cat->other,
$i, ($cat->scale > 0) ? $cat->scale : null, time())
448 $question_id = $this->
getId();
454 $affectedRows =
$ilDB->manipulateF(
455 "DELETE FROM svy_qst_matrixrows WHERE question_fi = %s",
462 $next_id =
$ilDB->nextId(
'svy_qst_matrixrows');
463 $affectedRows =
$ilDB->manipulateF(
464 "INSERT INTO svy_qst_matrixrows (id_svy_qst_matrixrows, title, label, other, sequence, question_fi) VALUES (%s, %s, %s, %s, %s, %s)",
465 array(
'integer',
'text',
'text',
'integer',
'integer',
'integer'),
466 array($next_id, $row->title, $row->label, ($row->other) ? 1 : 0,
$i, $question_id)
479 bool $a_include_header =
true,
480 bool $obligatory_state =
false 483 $a_xml_writer->xmlHeader();
484 $this->
insertXML($a_xml_writer, $a_include_header);
485 $xml = $a_xml_writer->xmlDumpMem(
false);
486 if (!$a_include_header) {
487 $pos = strpos(
$xml,
"?>");
498 bool $a_include_header =
true 501 "id" => $this->
getId(),
513 $a_xml_writer->
xmlEndTag(
"questiontext");
521 if (strlen($this->
getRow(
$i)->label)) {
522 $attrs[
'label'] = $this->
getRow(
$i)->label;
544 $a_xml_writer->
xmlEndTag(
"bipolar_adjectives");
551 $attrs[
'label'] =
'neutral';
555 $a_xml_writer->
xmlStartTag(
"response_single", $attrs);
558 $a_xml_writer->
xmlStartTag(
"response_multiple", $attrs);
564 $a_xml_writer->
xmlEndTag(
"response_single");
567 $a_xml_writer->
xmlEndTag(
"response_multiple");
575 if (count($this->material)) {
576 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches)) {
578 "label" => $this->material[
"title"]
581 $intlink =
"il_" .
IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
582 if (strcmp($matches[1],
"") !== 0) {
583 $intlink = $this->material[
"internal_link"];
585 $a_xml_writer->
xmlElement(
"mattext", null, $intlink);
592 $a_xml_writer->
xmlElement(
"fieldlabel", null,
"column_separators");
594 $a_xml_writer->
xmlEndTag(
"metadatafield");
597 $a_xml_writer->
xmlElement(
"fieldlabel", null,
"row_separators");
599 $a_xml_writer->
xmlEndTag(
"metadatafield");
602 $a_xml_writer->
xmlElement(
"fieldlabel", null,
"neutral_column_separator");
604 $a_xml_writer->
xmlEndTag(
"metadatafield");
607 $a_xml_writer->
xmlElement(
"fieldlabel", null,
"layout");
609 $a_xml_writer->
xmlEndTag(
"metadatafield");
619 parent::syncWithOriginal();
632 for (
$i = $lower_limit;
$i <= $upper_limit;
$i++) {
633 $this->columns->addCategory(
$i);
647 $next_id =
$ilDB->nextId(
'svy_phrase');
649 "INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
650 array(
'integer',
'text',
'text',
'integer',
'integer'),
651 array($next_id, $title, 1,
$ilUser->getId(), time())
653 $phrase_id = $next_id;
656 $phrase_data = $this->edit_manager->getPhraseData();
657 foreach ($phrase_data as
$data) {
658 $next_id =
$ilDB->nextId(
'svy_category');
659 $affectedRows =
$ilDB->manipulateF(
660 "INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
661 array(
'integer',
'text',
'text',
'integer',
'integer',
'text'),
662 array($next_id, $data[
'answer'], 1,
$ilUser->getId(), time(), $data[
'neutral'])
664 $category_id = $next_id;
665 $next_id =
$ilDB->nextId(
'svy_phrase_cat');
666 $affectedRows =
$ilDB->manipulateF(
667 "INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence, other, scale) VALUES (%s, %s, %s, %s, %s, %s)",
668 array(
'integer',
'integer',
'integer',
'integer',
'integer',
'integer'),
669 array($next_id, $phrase_id, $category_id, $counter, ($data[
'other']) ? 1 : 0, $data[
'scale'])
677 return "SurveyMatrixQuestion";
685 return "svy_qst_matrix";
691 foreach ($post_data as
$key => $value) {
695 if (preg_match(
"/matrix_" . $this->
getId() .
"_(\d+)/",
$key, $matches)) {
696 if (is_array($value)) {
697 foreach ($value as $val) {
698 $data[] = array(
"value" => $val,
699 "rowvalue" => $matches[1],
700 "textanswer" => $post_data[
'matrix_other_' . $this->
getId(
701 ) .
'_' . $matches[1]] ??
"" 705 $data[] = array(
"value" => $value,
706 "rowvalue" => $matches[1],
707 "textanswer" => $post_data[
'matrix_other_' . $this->
getId(
708 ) .
'_' . $matches[1]] ??
"" 733 foreach ($post_data as
$key => $value) {
734 if (preg_match(
"/matrix_" . $this->
getId() .
"_(\d+)/",
$key, $matches)) {
735 if (array_key_exists(
'matrix_other_' . $this->
getId() .
"_" . $matches[1], $post_data) && strlen($post_data[
'matrix_other_' . $this->
getId() .
"_" . $matches[1]]) == 0) {
736 return $this->
lng->txt(
"question_mr_no_other_answer");
742 return $this->
lng->txt(
"matrix_question_radio_button_not_checked");
747 foreach ($post_data as
$key => $value) {
748 if (preg_match(
"/matrix_" . $this->
getId() .
"_(\d+)/",
$key, $matches)) {
749 if (array_key_exists(
'matrix_other_' . $this->
getId() .
"_" . $matches[1], $post_data) && strlen($post_data[
'matrix_other_' . $this->
getId() .
"_" . $matches[1]]) == 0) {
750 return $this->
lng->txt(
"question_mr_no_other_answer");
753 if ((!is_array($value)) || (count($value) < 1)) {
754 return $this->
lng->txt(
"matrix_question_checkbox_not_checked");
759 return $this->
lng->txt(
"matrix_question_checkbox_not_checked");
769 bool $a_return =
false 773 $answer_data = array();
778 foreach ($post_data as
$key => $value) {
779 if (preg_match(
"/matrix_" . $this->
getId() .
"_(\d+)/",
$key, $matches)) {
780 if (strlen($value)) {
781 $other_value = (array_key_exists(
'matrix_other_' . $this->
getId() .
'_' . $matches[1], $post_data))
784 $answer_data[] = array(
"value" => $value,
785 "textanswer" => $other_value,
786 "rowvalue" => $matches[1]);
793 foreach ($post_data as
$key => $value) {
794 if (preg_match(
"/matrix_" . $this->
getId() .
"_(\d+)/",
$key, $matches)) {
795 $other_value = (array_key_exists(
'matrix_other_' . $this->
getId() .
'_' . $matches[1], $post_data))
798 foreach ($value as $checked) {
799 $answer_data[] = array(
"value" => $checked,
800 "textanswer" => $other_value,
801 "rowvalue" => $matches[1]);
813 if (count($answer_data)) {
815 foreach ($answer_data as $item) {
816 $next_id =
$ilDB->nextId(
'svy_answer');
819 $fields[
'answer_id'] = array(
"integer", $next_id);
820 $fields[
'question_fi'] = array(
"integer", $this->
getId());
821 $fields[
'active_fi'] = array(
"integer", $active_id);
822 $fields[
'value'] = array(
"float", $item[
'value']);
823 $fields[
'textanswer'] = array(
"clob", $item[
'textanswer']);
824 $fields[
'rowvalue'] = array(
"integer", $item[
'rowvalue']);
825 $fields[
'tstamp'] = array(
"integer", time());
827 $affectedRows =
$ilDB->insert(
"svy_answer", $fields);
839 parent::deleteAdditionalTableData($question_id);
843 "DELETE FROM svy_qst_matrixrows WHERE question_fi = %s",
862 switch ($a_subtype) {
869 $this->subtype = $a_subtype;
883 $this->columnSeparators = $enable;
896 $this->rowSeparators = $enable;
906 $this->neutralColumnSeparator = $enable;
919 foreach ($a_meta as
$key => $value) {
920 switch ($value[
"label"]) {
921 case "column_separators":
924 case "row_separators":
930 case "neutral_column_separator":
943 foreach ($a_data as $adjective) {
944 if (is_numeric($adjective[
"label"])) {
959 foreach ($a_data as $row) {
960 $this->
addRow($row[
'title'], $row[
'other'], $row[
'label']);
972 $column .= $material[
"text"];
974 $this->columns->addCategory($column, 0, strcmp(
$data[
"label"],
"neutral") == 0);
1004 $step3->setOptions($options);
1005 $step3->setValue($default);
1020 float $percent_columns,
1021 float $percent_bipolar_adjective1 = 0,
1022 float $percent_bipolar_adjective2 = 0,
1023 float $percent_neutral = 0
1028 "percent_row" => $percent_row,
1029 "percent_columns" => $percent_columns,
1030 "percent_bipolar_adjective1" => $percent_bipolar_adjective1,
1031 "percent_bipolar_adjective2" => $percent_bipolar_adjective2,
1032 "percent_neutral" => $percent_neutral
1034 $affectedRows =
$ilDB->manipulateF(
1036 array(
'text',
'integer'),
1037 array(serialize($layout), $this->
getId())
1043 if (count($this->layout) === 0) {
1045 $this->layout = array(
1046 "percent_row" => 30,
1047 "percent_columns" => 40,
1048 "percent_bipolar_adjective1" => 10,
1049 "percent_bipolar_adjective2" => 10,
1050 "percent_neutral" => 10
1053 $this->layout = array(
1054 "percent_row" => 30,
1055 "percent_columns" => 50,
1056 "percent_bipolar_adjective1" => 10,
1057 "percent_bipolar_adjective2" => 10,
1058 "percent_neutral" => 0
1061 $this->layout = array(
1062 "percent_row" => 30,
1063 "percent_columns" => 50,
1064 "percent_bipolar_adjective1" => 0,
1065 "percent_bipolar_adjective2" => 0,
1066 "percent_neutral" => 20
1069 $this->layout = array(
1070 "percent_row" => 30,
1071 "percent_columns" => 70,
1072 "percent_bipolar_adjective1" => 0,
1073 "percent_bipolar_adjective2" => 0,
1074 "percent_neutral" => 0
1086 if (is_array($layout)) {
1089 $this->layout = unserialize($layout, [
'allowed_classes' =>
false]) ?: [];
1108 if ($column->neutral && strlen($column->title)) {
1120 $this->columnPlaceholders = $a_value;
1133 $this->legend = $a_value;
1143 $this->singleLineRowCaption = $a_value;
1153 $this->repeatColumnHeader = $a_value;
1172 $db = $DIC->database();
1175 "SELECT MAX(scale) max_sum_score, q.question_id FROM svy_svy_qst sq " .
1176 "JOIN svy_question q ON (sq.question_fi = q.question_id) " .
1177 "JOIN svy_variable v ON (v.question_fi = q.question_id) " .
1178 "WHERE sq.survey_fi = %s AND q.questiontype_fi = %s " .
1179 "GROUP BY (q.question_id)",
1180 [
"integer",
"integer"],
1185 $max_score[$rec[
"question_id"]] = $rec[
"max_sum_score"];
1189 "SELECT COUNT(mr.id_svy_qst_matrixrows) cnt_rows, q.question_id FROM svy_svy_qst sq " .
1190 "JOIN svy_question q ON (sq.question_fi = q.question_id) " .
1191 "JOIN svy_qst_matrixrows mr ON (mr.question_fi = q.question_id) " .
1192 "WHERE sq.survey_fi = %s AND q.questiontype_fi = %s " .
1193 "GROUP BY (q.question_id)",
1194 [
"integer",
"integer"],
1199 $cnt_rows[$rec[
"question_id"]] = $rec[
"cnt_rows"];
1203 foreach ($max_score as $qid => $s) {
1204 $sum_sum_score += $s * $cnt_rows[$qid];
1207 return $sum_sum_score;
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
setQuestiontext(string $questiontext="")
saveCompletionStatus(int $original_id=0)
Saves the complete flag to the database.
setSingleLineRowCaption(bool $a_value=false)
addStandardNumbers(int $lower_limit, int $upper_limit)
Adds standard numbers as columns.
addRowAtPosition(string $a_text, string $a_other, int $a_position)
importAdjectives(array $a_data)
Import bipolar adjectives from the question import file.
bool $singleLineRowCaption
addPhrase(int $phrase_id)
Adds a phrase to the question.
saveRowsToDb(int $original_id=0)
static getMaxSumScore(int $survey_id)
setObligatory(bool $obligatory=true)
removeColumnWithName(string $name)
fetchAssoc(ilDBStatement $statement)
setOriginalId(?int $original_id)
getPreconditionValueOutput(string $value)
Returns the output for a precondition value.
saveColumnsToDb(int $original_id=0)
string $bipolar_adjective1
getColumnForScale(int $scale)
saveBipolarAdjectives(string $adjective1, string $adjective2)
hasBipolarAdjectives()
Returns TRUE if bipolar adjectives exist.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setComplete(bool $a_complete)
int $subtype
Matrix question subtype 0 = Single choice 1 = Multiple choice 2 = Text 3 = Integer 4 = Double 5 = Dat...
setBipolarAdjective(int $a_index, string $a_value)
stripSlashesAddSpaceFallback(string $a_str)
Strip slashes with add space fallback, see https://mantis.ilias.de/view.php?id=19727 and https://mant...
saveLayout(float $percent_row, float $percent_columns, float $percent_bipolar_adjective1=0, float $percent_bipolar_adjective2=0, float $percent_neutral=0)
Saves the layout of a matrix question.
getPreconditionOptions()
Returns the options for preconditions.
setNeutralColumnSeparator(bool $enable=true)
setLegend(bool $a_value=false)
Set whether the legend should be shown or not.
xmlEndTag(string $tag)
Writes an endtag.
getSingleLineRowCaption()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
hasNeutralColumn()
Returns TRUE if a neutral column exists.
getPreconditionSelectValue(string $default, string $title, string $variable)
Creates a form property for the precondition value.
setColumnPlaceholders(bool $a_value=false)
Set whether placeholders should be used for the column titles or not.
setAuthor(string $author="")
setColumnSeparators(bool $enable=false)
Enables/Disables separators for the matrix columns.
addMaterialTag(ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true, ?array $a_attrs=null)
Creates an XML material tag from a plain text or xhtml text.
usableForPrecondition()
Returns if the question is usable for preconditions.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
saveUserInput(array $post_data, int $active_id, bool $a_return=false)
importMatrix(array $a_data)
Import matrix rows from the question import file.
__construct(string $title="", string $description="", string $author="", string $questiontext="", int $owner=-1)
deleteAdditionalTableData(int $question_id)
Delete question data from additional table.
savePhrase(string $title)
Saves a set of columns to a default phrase (data currently comes from session)
setTitle(string $title="")
importAdditionalMetadata(array $a_meta)
Import additional meta data from the question import file.
getSubtype()
Returns the subtype of the matrix question.
setSubtype(int $a_subtype=0)
Sets the subtype of the matrix question.
getBipolarAdjective(int $a_index)
Returns one of the bipolar adjectives.
queryF(string $query, array $types, array $values)
checkUserInput(array $post_data, int $survey_id)
Checks the input of the active user for obligatory status and entered values.
addRow(string $a_text, string $a_other, string $a_label)
setRepeatColumnHeader(bool $a_value=false)
bool $neutralColumnSeparator
getQuestionDataArray(int $id)
Returns the question data fields from the database.
setRowSeparators(bool $enable=false)
Enables/Disables separators for the matrix rows.
removeColumns(array $array)
toXML(bool $a_include_header=true, bool $obligatory_state=false)
Returns an xml representation of the question.
__construct(Container $dic, ilPlugin $plugin)
string $bipolar_adjective2
insertXML(ilXmlWriter $a_xml_writer, bool $a_include_header=true)
Adds the question XML to a given XMLWriter object.
loadFromDb(int $question_id)
SurveyCategories $columns
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
setDescription(string $description="")
getAdditionalTableName()
Returns the name of the additional question data table in the database.
importResponses(array $a_data)
Import response data from the question import file.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getColumnIndex(string $name)
setObjId(int $obj_id=0)
Set the reference(?) id of the container object.
saveColumnToDb(string $columntext, int $neutral=0)
saveToDb(int $original_id=0)
getNeutralColumnSeparator()
getWorkingDataFromUserInput(array $post_data)