24 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
25 include_once
"./Modules/Survey/classes/inc.SurveyConstants.php";
191 $this->columns = array();
192 $this->rows = array();
193 $this->neutralColumn =
"";
194 $this->bipolar_adjective1 =
"";
195 $this->bipolar_adjective2 =
"";
196 $this->rowSeparators = 0;
197 $this->columnSeparators = 0;
198 $this->neutralColumnSeparator = 1;
247 $this->neutralColumn = $a_text;
261 return count($this->columns);
276 if (array_key_exists($position, $this->columns))
278 $head = array_slice($this->columns, 0, $position);
279 $tail = array_slice($this->columns, $position);
280 $this->columns = array_merge($head, array($columnname), $tail);
284 array_push($this->columns, $columnname);
300 array_push($this->columns, $columnname);
314 $this->columns = array_merge($this->columns,
$columns);
328 unset($this->columns[$index]);
329 $this->columns = array_values($this->columns);
343 foreach ($array as $index)
345 unset($this->columns[$index]);
347 $this->columns = array_values($this->columns);
361 foreach ($this->columns as $index => $column)
363 if (strcmp($column, $name) == 0)
382 if (array_key_exists($index, $this->columns))
384 return $this->columns[$index];
410 foreach ($this->columns as $index => $column)
412 if (strcmp($column, $name) == 0)
431 $this->columns = array();
444 return count($this->rows);
457 array_push($this->rows, $a_text);
470 $this->rows = array();
483 if (array_key_exists($a_index, $this->rows))
485 return $this->rows[$a_index];
501 foreach ($array as $index)
503 unset($this->rows[$index]);
505 $this->rows = array_values($this->rows);
545 $this->bipolar_adjective2 = $a_value;
549 $this->bipolar_adjective1 = $a_value;
567 $query = sprintf(
"SELECT survey_category.* FROM survey_category, survey_phrase_category WHERE survey_phrase_category.category_fi = survey_category.category_id AND survey_phrase_category.phrase_fi = %s AND (survey_category.owner_fi = 0 OR survey_category.owner_fi = %s) ORDER BY survey_phrase_category.sequence",
568 $ilDB->quote($phrase_id),
569 $ilDB->quote($ilUser->id)
571 $result = $ilDB->query($query);
572 while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
574 if (($row->defaultvalue == 1) and ($row->owner_fi == 0))
576 $this->
addColumn($this->lng->txt($row->title));
598 $query = sprintf(
"SELECT survey_question.*, survey_question_matrix.* FROM survey_question, survey_question_matrix WHERE survey_question.question_id = %s AND survey_question.question_id = survey_question_matrix.question_fi",
601 $result = $ilDB->query($query);
602 if ($result->numRows() == 1)
604 return $result->fetchRow(MDB2_FETCHMODE_ASSOC);
623 $query = sprintf(
"SELECT survey_question.*, survey_question_matrix.* FROM survey_question, survey_question_matrix WHERE survey_question.question_id = %s AND survey_question.question_id = survey_question_matrix.question_fi",
626 $result = $ilDB->query($query);
627 if ($result->numRows() == 1)
629 $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
630 $this->
id =
$data->question_id;
631 $this->title =
$data->title;
632 $this->description =
$data->description;
633 $this->obj_id =
$data->obj_fi;
634 $this->author =
$data->author;
635 $this->owner =
$data->owner_fi;
636 include_once(
"./Services/RTE/classes/class.ilRTE.php");
638 $this->obligatory =
$data->obligatory;
639 $this->complete =
$data->complete;
640 $this->original_id =
$data->original_id;
662 $query = sprintf(
"SELECT survey_variable.*, survey_category.title, survey_category.neutral FROM survey_variable, survey_category WHERE survey_variable.question_fi = %s AND survey_variable.category_fi = survey_category.category_id ORDER BY sequence ASC",
665 $result = $ilDB->query($query);
666 if ($result->numRows() > 0)
668 while (
$data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
670 if (
$data->neutral == 0)
681 $query = sprintf(
"SELECT * FROM survey_question_matrix_rows WHERE question_fi = %s ORDER BY sequence",
682 $ilDB->quote(
$id .
"")
684 $result = $ilDB->query($query);
685 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
687 $this->
addRow($row[
"title"]);
726 function saveToDb($original_id =
"", $withanswers =
true)
736 $original_id = $ilDB->quote($original_id);
740 $original_id =
"NULL";
744 include_once(
"./Services/RTE/classes/class.ilRTE.php");
752 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
753 $query = sprintf(
"INSERT INTO survey_question (question_id, questiontype_fi, obj_fi, owner_fi, title, description, author, questiontext, obligatory, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
754 $ilDB->quote($this->getQuestionTypeID()),
755 $ilDB->quote($this->obj_id),
756 $ilDB->quote($this->owner),
757 $ilDB->quote($this->title),
758 $ilDB->quote($this->description),
759 $ilDB->quote($this->author),
761 $ilDB->quote(sprintf(
"%d", $this->obligatory)),
762 $ilDB->quote(
"$complete"),
763 $ilDB->quote($created),
766 $result = $ilDB->query($query);
767 if (!PEAR::isError($result))
769 $this->
id = $ilDB->getLastInsertId();
770 $query = sprintf(
"INSERT INTO survey_question_matrix (
775 neutral_column_separator,
778 singleline_row_caption,
779 repeat_column_header,
780 column_header_position,
789 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
790 $ilDB->quote($this->id .
""),
791 $ilDB->quote(sprintf(
"%d", $this->
getSubtype())),
806 $ilDB->quote(serialize($this->
getLayout()) .
"")
808 $ilDB->query($query);
814 $query = sprintf(
"UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
815 $ilDB->quote($this->title),
816 $ilDB->quote($this->description),
817 $ilDB->quote($this->author),
819 $ilDB->quote(sprintf(
"%d", $this->obligatory)),
820 $ilDB->quote(
"$complete"),
821 $ilDB->quote($this->
id)
823 $result = $ilDB->query($query);
824 $query = sprintf(
"UPDATE survey_question_matrix SET
826 column_separators = %s,
828 neutral_column_separator = %s,
829 column_placeholders = %s,
831 singleline_row_caption = %s,
832 repeat_column_header = %s,
833 column_header_position = %s,
838 bipolar_adjective1 = %s,
839 bipolar_adjective2 = %s,
841 WHERE question_fi = %s",
842 $ilDB->quote(sprintf(
"%d", $this->
getSubtype())),
857 $ilDB->quote(serialize($this->
getLayout()) .
""),
858 $ilDB->quote($this->
id .
"")
860 $result = $ilDB->query($query);
879 $query = sprintf(
"UPDATE survey_question_matrix SET bipolar_adjective1 = %s, bipolar_adjective2 = %s WHERE question_fi = %s",
880 $ilDB->quote($adjective1 .
""),
881 $ilDB->quote($adjective2 .
""),
882 $ilDB->quote($this->
getId() .
"")
884 $result = $ilDB->query($query);
899 global $ilUser, $ilDB;
901 $query = sprintf(
"SELECT title, category_id FROM survey_category WHERE title = %s AND neutral = %s AND owner_fi = %s",
902 $ilDB->quote($columntext .
""),
903 $ilDB->quote($neutral .
""),
904 $ilDB->quote($ilUser->getId() .
"")
906 $result = $ilDB->query($query);
912 while ($row =
$result->fetchRow(MDB2_FETCHMODE_OBJECT))
914 if (strcmp($row->title, $columntext) == 0)
916 $returnvalue = $row->category_id;
927 $query = sprintf(
"INSERT INTO survey_category (category_id, title, neutral, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
928 $ilDB->quote($columntext .
""),
929 $ilDB->quote($neutral .
""),
930 $ilDB->quote($ilUser->getId() .
"")
932 $result = $ilDB->query($query);
933 $returnvalue = $ilDB->getLastInsertId();
944 $question_id = $this->
getId();
945 if (strlen($original_id))
947 $question_id = $original_id;
951 $query = sprintf(
"DELETE FROM survey_variable WHERE question_fi = %s",
952 $ilDB->quote($question_id)
954 $result = $ilDB->query($query);
960 $query = sprintf(
"INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
961 $ilDB->quote($column_id .
""),
962 $ilDB->quote($question_id .
""),
963 $ilDB->quote(($i + 1) .
""),
964 $ilDB->quote($i .
"")
966 $answer_result = $ilDB->query($query);
971 $query = sprintf(
"INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
972 $ilDB->quote($column_id .
""),
973 $ilDB->quote($question_id .
""),
974 $ilDB->quote(($i + 1) .
""),
975 $ilDB->quote($i .
"")
977 $answer_result = $ilDB->query($query);
987 $question_id = $this->
getId();
988 if (strlen($original_id))
990 $question_id = $original_id;
994 $query = sprintf(
"DELETE FROM survey_question_matrix_rows WHERE question_fi = %s",
995 $ilDB->quote($question_id .
"")
997 $result = $ilDB->query($query);
1001 $row = $this->
getRow($i);
1002 $query = sprintf(
"INSERT INTO survey_question_matrix_rows (id_survey_question_matrix_rows, title, sequence, question_fi) VALUES (NULL, %s, %s, %s)",
1003 $ilDB->quote($row .
""),
1004 $ilDB->quote($i .
""),
1005 $ilDB->quote($question_id .
"")
1007 $answer_result = $ilDB->query($query);
1020 function toXML($a_include_header = TRUE, $obligatory_state =
"")
1022 include_once(
"./classes/class.ilXmlWriter.php");
1025 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
1026 $xml = $a_xml_writer->xmlDumpMem(FALSE);
1027 if (!$a_include_header)
1029 $pos = strpos($xml,
"?>");
1030 $xml = substr($xml, $pos + 2);
1045 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state =
"")
1048 "id" => $this->
getId(),
1050 "type" => $this->getQuestiontype(),
1054 $a_xml_writer->xmlStartTag(
"question", $attrs);
1056 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
1057 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
1058 $a_xml_writer->xmlStartTag(
"questiontext");
1060 $a_xml_writer->xmlEndTag(
"questiontext");
1062 $a_xml_writer->xmlStartTag(
"matrix");
1063 $a_xml_writer->xmlStartTag(
"matrixrows");
1069 $a_xml_writer->xmlStartTag(
"matrixrow", $attrs);
1071 $a_xml_writer->xmlEndTag(
"matrixrow");
1073 $a_xml_writer->xmlEndTag(
"matrixrows");
1075 $a_xml_writer->xmlStartTag(
"responses");
1078 $a_xml_writer->xmlStartTag(
"bipolar_adjectives");
1087 $a_xml_writer->xmlEndTag(
"bipolar_adjectives");
1097 $a_xml_writer->xmlStartTag(
"response_single", $attrs);
1100 $a_xml_writer->xmlStartTag(
"response_multiple", $attrs);
1107 $a_xml_writer->xmlEndTag(
"response_single");
1110 $a_xml_writer->xmlEndTag(
"response_multiple");
1118 "label" =>
"neutral"
1123 $a_xml_writer->xmlStartTag(
"response_single", $attrs);
1126 $a_xml_writer->xmlStartTag(
"response_multiple", $attrs);
1133 $a_xml_writer->xmlEndTag(
"response_single");
1136 $a_xml_writer->xmlEndTag(
"response_multiple");
1141 $a_xml_writer->xmlEndTag(
"responses");
1142 $a_xml_writer->xmlEndTag(
"matrix");
1144 if (count($this->material))
1146 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
1149 "label" => $this->material[
"title"]
1151 $a_xml_writer->xmlStartTag(
"material", $attrs);
1152 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
1153 if (strcmp($matches[1],
"") != 0)
1155 $intlink = $this->material[
"internal_link"];
1157 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
1158 $a_xml_writer->xmlEndTag(
"material");
1162 $a_xml_writer->xmlStartTag(
"metadata");
1163 $a_xml_writer->xmlStartTag(
"metadatafield");
1164 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"column_separators");
1166 $a_xml_writer->xmlEndTag(
"metadatafield");
1168 $a_xml_writer->xmlStartTag(
"metadatafield");
1169 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"row_separators");
1171 $a_xml_writer->xmlEndTag(
"metadatafield");
1173 $a_xml_writer->xmlStartTag(
"metadatafield");
1174 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"neutral_column_separator");
1176 $a_xml_writer->xmlEndTag(
"metadatafield");
1178 $a_xml_writer->xmlStartTag(
"metadatafield");
1179 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"layout");
1180 $a_xml_writer->xmlElement(
"fieldentry", NULL, serialize($this->
getLayout()));
1181 $a_xml_writer->xmlEndTag(
"metadatafield");
1183 $a_xml_writer->xmlEndTag(
"metadata");
1185 $a_xml_writer->xmlEndTag(
"question");
1191 if ($this->original_id)
1198 $query = sprintf(
"UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
1199 $ilDB->quote($this->title .
""),
1200 $ilDB->quote($this->description .
""),
1201 $ilDB->quote($this->author .
""),
1202 $ilDB->quote($this->questiontext .
""),
1203 $ilDB->quote(sprintf(
"%d", $this->obligatory) .
""),
1204 $ilDB->quote($complete .
""),
1205 $ilDB->quote($this->original_id .
"")
1207 $result = $ilDB->query($query);
1208 $query = sprintf(
"UPDATE survey_question_matrix SET row_separators = %s, column_separators = %s, neutral_column_separator = %s, bipolar_adjective1 = %s, bipolar_adjective2 = %s WHERE question_fi = %s",
1209 $ilDB->quote($this->getRowSeparators() .
""),
1210 $ilDB->quote($this->getColumnSeparators() .
""),
1211 $ilDB->quote($this->getNeutralColumnSeparator() .
""),
1212 $ilDB->quote($this->getBipolarAdjective(0) .
""),
1213 $ilDB->quote($this->getBipolarAdjective(1) .
""),
1214 $ilDB->quote($this->original_id .
"")
1216 $result = $ilDB->query($query);
1217 if (PEAR::isError($result))
1220 $ilias->raiseError($result->getMessage());
1244 for ($i = $lower_limit; $i <= $upper_limit; $i++)
1264 $query = sprintf(
"INSERT INTO survey_phrase (phrase_id, title, defaultvalue, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
1265 $ilDB->quote(
$title .
""),
1267 $ilDB->quote($ilUser->id .
"")
1269 $result = $ilDB->query($query);
1270 $phrase_id = $ilDB->getLastInsertId();
1273 foreach ($phrases as $column_index)
1275 $column = $this->
getColumn($column_index);
1276 $query = sprintf(
"INSERT INTO survey_category (category_id, title, neutral, defaultvalue, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
1277 $ilDB->quote($column .
""),
1280 $ilDB->quote($ilUser->getId() .
"")
1282 $result = $ilDB->query($query);
1283 $column_id = $ilDB->getLastInsertId();
1284 $query = sprintf(
"INSERT INTO survey_phrase_category (phrase_category_id, phrase_fi, category_fi, sequence) VALUES (NULL, %s, %s, %s)",
1285 $ilDB->quote($phrase_id .
""),
1286 $ilDB->quote($column_id .
""),
1287 $ilDB->quote($counter .
"")
1289 $result = $ilDB->query($query);
1304 return "SurveyMatrixQuestion";
1317 return "survey_question_matrix";
1331 foreach ($post_data as $key => $value)
1336 if (preg_match(
"/matrix_" . $this->
getId() .
"_(\d+)/", $key, $matches))
1338 if (is_array($value))
1340 foreach ($value as $val)
1342 array_push(
$data, array(
"value" => $val,
"row" => $matches[1]));
1347 array_push(
$data, array(
"value" => $value,
"row" => $matches[1]));
1352 if (preg_match(
"/matrix_" . $this->
getId() .
"_(\d+)/", $key, $matches))
1354 if (is_array($value))
1356 foreach ($value as $val)
1358 array_push(
$data, array(
"value" => $val,
"row" => $matches[1]));
1363 array_push(
$data, array(
"value" => $value,
"row" => $matches[1]));
1391 foreach ($post_data as $key => $value)
1393 if (preg_match(
"/matrix_" . $this->
getId() .
"_(\d+)/", $key, $matches))
1398 if ($counter != $this->
getRowCount())
return $this->lng->txt(
"matrix_question_radio_button_not_checked");
1402 foreach ($post_data as $key => $value)
1404 if (preg_match(
"/matrix_" . $this->
getId() .
"_(\d+)/", $key, $matches))
1407 if ((!is_array($value)) || (count($value) < 1))
1409 return $this->lng->txt(
"matrix_question_checkbox_not_checked");
1413 if ($counter != $this->
getRowCount())
return $this->lng->txt(
"matrix_question_checkbox_not_checked");
1428 for ($row = 0; $row < $this->
getRowCount(); $row++)
1430 if ($this->getSubType() == 1)
1433 for ($i = 0; $i < $columncount; $i++)
1437 $query = sprintf(
"INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, row, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, %s, NULL)",
1438 $ilDB->quote($this->getId() .
""),
1439 $ilDB->quote($active_id .
""),
1440 $ilDB->quote($i .
""),
1441 $ilDB->quote($row .
"")
1443 $result = $ilDB->query($query);
1450 $category = rand(0, $columncount-1);
1451 $query = sprintf(
"INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, row, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, %s, NULL)",
1452 $ilDB->quote($this->getId() .
""),
1453 $ilDB->quote($active_id .
""),
1454 $ilDB->quote($category .
""),
1455 $ilDB->quote($row .
"")
1457 $result = $ilDB->query($query);
1469 foreach ($post_data as $key => $value)
1471 if (preg_match(
"/matrix_" . $this->
getId() .
"_(\d+)/", $key, $matches))
1473 $query = sprintf(
"INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, row, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
1474 $ilDB->quote($this->getId() .
""),
1475 $ilDB->quote($active_id .
""),
1476 $ilDB->quote($value .
""),
1478 $ilDB->quote($matches[1] .
"")
1480 $result = $ilDB->query($query);
1485 foreach ($post_data as $key => $value)
1487 if (preg_match(
"/matrix_" . $this->
getId() .
"_(\d+)/", $key, $matches))
1489 foreach ($value as $checked)
1491 if (strlen($checked))
1493 $query = sprintf(
"INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, row, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
1494 $ilDB->quote($this->getId() .
""),
1495 $ilDB->quote($active_id .
""),
1496 $ilDB->quote($checked .
""),
1498 $ilDB->quote($matches[1] .
"")
1500 $result = $ilDB->query($query);
1522 $query = sprintf(
"DELETE FROM survey_question_matrix_rows WHERE question_fi = %s",
1523 $ilDB->quote($question_id .
"")
1525 $result = $ilDB->query($query);
1541 $query = sprintf(
"SELECT DISTINCT(CONCAT(survey_answer.active_fi,survey_answer.question_fi)) AS participants FROM survey_answer, survey_finished WHERE survey_answer.question_fi = %s AND survey_finished.survey_fi = %s AND survey_finished.finished_id = survey_answer.active_fi",
1542 $ilDB->quote($this->getId() .
""),
1545 $result = $ilDB->query($query);
1546 return $result->numRows();
1563 $question_id = $this->
getId();
1565 $result_array = array();
1566 $cumulated = array();
1568 $query = sprintf(
"SELECT survey_answer.* FROM survey_answer, survey_finished WHERE survey_answer.question_fi = %s AND survey_finished.survey_fi = %s AND survey_answer.row = %s AND survey_finished.finished_id = survey_answer.active_fi",
1569 $ilDB->quote($question_id .
""),
1571 $ilDB->quote($rowindex .
"")
1573 $result = $ilDB->query($query);
1579 while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
1581 $cumulated[$row->value]++;
1583 asort($cumulated, SORT_NUMERIC);
1587 $numrows = $result->numRows();
1592 if (strcmp(key($cumulated),
"") != 0)
1594 $prefix = (key($cumulated)+1) .
" - ";
1596 $cat = $this->
getColumn(key($cumulated));
1597 $result_array[
"MODE"] = $prefix . $cat;
1598 $result_array[
"MODE_VALUE"] = key($cumulated)+1;
1599 $result_array[
"MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
1605 $percentage = (float)((
int)$cumulated[$key]/$numrows);
1608 $result_array[
"variables"][$key] = array(
"title" => $cat,
"selected" => (
int)$cumulated[$key],
"percentage" => $percentage);
1619 ksort($cumulated, SORT_NUMERIC);
1622 foreach ($cumulated as $value => $key)
1625 for ($i = 0; $i < $key; $i++)
1627 array_push($median, $value+1);
1634 $median_value = 0.5 * ($median[(
$total/2)-1] + $median[(
$total/2)]);
1635 if (round($median_value) != $median_value)
1637 $cat = $this->
getColumn((
int)floor($median_value)-1);
1638 $cat2 = $this->
getColumn((
int)ceil($median_value)-1);
1639 $median_value = $median_value .
"<br />" .
"(" . $this->lng->txt(
"median_between") .
" " . (floor($median_value)) .
"-" . $cat .
" " . $this->lng->txt(
"and") .
" " . (ceil($median_value)) .
"-" . $cat2 .
")";
1644 $median_value = $median[((
$total+1)/2)-1];
1651 $result_array[
"ARITHMETIC_MEAN"] =
"";
1652 $result_array[
"MEDIAN"] = $median_value;
1653 $result_array[
"QUESTION_TYPE"] =
"SurveyMatrixQuestion";
1654 $result_array[
"ROW"] = $this->
getRow($rowindex);
1655 return $result_array;
1671 $question_id = $this->
getId();
1673 $result_array = array();
1674 $cumulated = array();
1676 $query = sprintf(
"SELECT survey_answer.* FROM survey_answer, survey_finished WHERE survey_answer.question_fi = %s AND survey_finished.survey_fi = %s AND survey_finished.finished_id = survey_answer.active_fi",
1677 $ilDB->quote($question_id),
1680 $result = $ilDB->query($query);
1686 while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
1688 $cumulated[$row->value]++;
1690 asort($cumulated, SORT_NUMERIC);
1694 $numrows = $result->numRows();
1699 if (strcmp(key($cumulated),
"") != 0)
1701 $prefix = (key($cumulated)+1) .
" - ";
1703 $cat = $this->
getColumn(key($cumulated));
1704 $result_array[
"MODE"] = $prefix . $cat;
1705 $result_array[
"MODE_VALUE"] = key($cumulated)+1;
1706 $result_array[
"MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
1712 $percentage = (float)((
int)$cumulated[$key]/$numrows);
1715 $result_array[
"variables"][$key] = array(
"title" => $cat,
"selected" => (
int)$cumulated[$key],
"percentage" => $percentage);
1726 ksort($cumulated, SORT_NUMERIC);
1729 foreach ($cumulated as $value => $key)
1732 for ($i = 0; $i < $key; $i++)
1734 array_push($median, $value+1);
1741 $median_value = 0.5 * ($median[(
$total/2)-1] + $median[(
$total/2)]);
1742 if (round($median_value) != $median_value)
1744 $cat = $this->
getColumn((
int)floor($median_value)-1);
1745 $cat2 = $this->
getColumn((
int)ceil($median_value)-1);
1746 $median_value = $median_value .
"<br />" .
"(" . $this->lng->txt(
"median_between") .
" " . (floor($median_value)) .
"-" . $cat .
" " . $this->lng->txt(
"and") .
" " . (ceil($median_value)) .
"-" . $cat2 .
")";
1751 $median_value = $median[((
$total+1)/2)-1];
1758 $result_array[
"ARITHMETIC_MEAN"] =
"";
1759 $result_array[
"MEDIAN"] = $median_value;
1760 $result_array[
"QUESTION_TYPE"] =
"SurveyMatrixQuestion";
1762 $cumulated_results = array();
1763 $cumulated_results[
"TOTAL"] = $result_array;
1767 $cumulated_results[$i] = $rowresult;
1769 return $cumulated_results;
1787 include_once (
"./classes/class.ilExcelUtils.php");
1791 $worksheet->write($row, 3, $eval_data[
"TOTAL"][
"USERS_ANSWERED"]);
1792 $worksheet->write($row, 4, $eval_data[
"TOTAL"][
"USERS_SKIPPED"]);
1795 $worksheet->write($row, 7, $eval_data[
"TOTAL"][
"MODE_NR_OF_SELECTIONS"]);
1797 $worksheet->write($row, 9, $eval_data[
"TOTAL"][
"ARITHMETIC_MEAN"]);
1799 foreach ($eval_data as $evalkey => $evalvalue)
1801 if (is_numeric($evalkey))
1804 $worksheet->write($row, 3, $evalvalue[
"USERS_ANSWERED"]);
1805 $worksheet->write($row, 4, $evalvalue[
"USERS_SKIPPED"]);
1808 $worksheet->write($row, 7, $evalvalue[
"MODE_NR_OF_SELECTIONS"]);
1810 $worksheet->write($row, 9, $evalvalue[
"ARITHMETIC_MEAN"]);
1833 foreach ($eval_data as $evalkey => $evalvalue)
1836 if (is_numeric($evalkey))
1838 array_push($csvrow,
"");
1839 array_push($csvrow, $evalvalue[
"ROW"]);
1840 array_push($csvrow,
"");
1844 array_push($csvrow, $this->
getTitle());
1846 array_push($csvrow, $this->lng->txt($evalvalue[
"QUESTION_TYPE"]));
1848 array_push($csvrow, $evalvalue[
"USERS_ANSWERED"]);
1849 array_push($csvrow, $evalvalue[
"USERS_SKIPPED"]);
1850 array_push($csvrow, $evalvalue[
"MODE"]);
1851 array_push($csvrow, $evalvalue[
"MODE_NR_OF_SELECTIONS"]);
1852 array_push($csvrow, $evalvalue[
"MEDIAN"]);
1853 array_push($csvrow, $evalvalue[
"ARITHMETIC_MEAN"]);
1872 include_once (
"./classes/class.ilExcelUtils.php");
1873 $worksheet =& $workbook->addWorksheet();
1881 $worksheet->write(3, 1, $eval_data[
"TOTAL"][
"USERS_ANSWERED"]);
1883 $worksheet->write(4, 1, $eval_data[
"TOTAL"][
"USERS_SKIPPED"]);
1886 preg_match(
"/(.*?)\s+-\s+(.*)/", $eval_data[
"TOTAL"][
"MODE"], $matches);
1901 foreach ($eval_data[
"TOTAL"][
"variables"] as $key => $value)
1904 $worksheet->write($rowcounter, 2, $key+1);
1909 foreach ($eval_data as $evalkey => $evalvalue)
1911 if (is_numeric($evalkey))
1916 $worksheet->write($rowcounter + 1, 1, $evalvalue[
"USERS_ANSWERED"]);
1918 $worksheet->write($rowcounter + 2, 1, $evalvalue[
"USERS_SKIPPED"]);
1919 $rowcounter = $rowcounter + 3;
1921 preg_match(
"/(.*?)\s+-\s+(.*)/", $evalvalue[
"MODE"], $matches);
1936 foreach ($evalvalue[
"variables"] as $key => $value)
1939 $worksheet->write($rowcounter, 2, $key+1);
1946 $format_center =& $workbook->addFormat();
1947 $format_center->setColor(
'black');
1948 $format_center->setAlign(
'center');
1954 $worksheet->write($rowcounter, $counter,
"", $format_title);
1955 foreach ($eval_data[
"TOTAL"][
"variables"] as $variable)
1962 foreach ($eval_data as $index =>
$data)
1964 if (is_numeric($index))
1968 foreach (
$data[
"variables"] as $vardata)
1970 $worksheet->write($rowcounter, $counter, $vardata[
"selected"], $format_center);
1991 array_push($a_array, $this->
getRow($i));
2000 array_push($a_array, ($index+1) .
" - $col");
2022 if (count($resultset[
"answers"][$this->
getId()]))
2024 array_push($a_array,
"");
2031 foreach ($resultset[
"answers"][$this->
getId()] as
$result)
2036 array_push($a_array,
$result[
"value"] + 1);
2041 array_push($a_array, $this->lng->txt(
"skipped"));
2049 $checked_values = array();
2050 foreach ($resultset[
"answers"][$this->
getId()] as
$result)
2052 if ($result[
"row"] == $i)
2055 array_push($checked_values, $result[
"value"] + 1);
2060 array_push($a_array, $this->lng->txt(
"skipped"));
2064 array_push($a_array,
"");
2070 array_push($a_array,
"");
2074 if (in_array($index+1, $checked_values))
2076 array_push($a_array, 1);
2080 array_push($a_array, 0);
2088 array_push($a_array,
"");
2094 array_push($a_array, 1);
2098 array_push($a_array, 0);
2108 array_push($a_array, $this->lng->txt(
"skipped"));
2111 array_push($a_array,
"");
2119 array_push($a_array,
"");
2123 array_push($a_array,
"");
2146 $query = sprintf(
"SELECT survey_answer.* FROM survey_answer, survey_finished WHERE survey_finished.survey_fi = %s AND survey_answer.question_fi = %s AND survey_finished.finished_id = survey_answer.active_fi ORDER BY row, value",
2148 $ilDB->quote($this->
getId())
2150 $result = $ilDB->query($query);
2152 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
2154 $column = $this->
getColumn($row[
"value"]);
2155 if (!is_array($answers[$row[
"active_fi"]])) $answers[$row[
"active_fi"]] = array();
2156 array_push($answers[$row[
"active_fi"]], $this->
getRow($row[
"row"]) .
": " . ($row[
"value"] + 1) .
" - " . $column);
2158 foreach ($answers as $key => $value)
2160 $answers[$key] = implode(
"<br />", $value);
2196 $this->subtype = $a_subtype;
2218 $this->columnSeparators = 1;
2222 $this->columnSeparators = 0;
2253 $this->rowSeparators = 1;
2257 $this->rowSeparators = 0;
2288 $this->neutralColumnSeparator = 1;
2292 $this->neutralColumnSeparator = 0;
2322 foreach ($a_meta as $key => $value)
2324 switch ($value[
"label"])
2326 case "column_separators":
2329 case "row_separators":
2335 case "neutral_column_separator":
2353 foreach ($a_data as $adjective)
2355 if (is_numeric($adjective[
"label"]))
2377 foreach ($a_data as $row)
2398 $column .= $material[
"text"];
2400 if (strcmp(
$data[
"label"],
"neutral") == 0)
2450 if (count($this->cumulated) == 0)
2452 include_once
"./Modules/Survey/classes/class.ilObjSurvey.php";
2457 if (is_numeric($type))
2459 foreach ($this->cumulated[$type][
"variables"] as $key => $value)
2461 foreach ($value as $key2 => $value2)
2463 $this->cumulated[
"variables"][$key][$key2] = utf8_decode($value2);
2466 $title = preg_replace(
"/<[^>]+?>/ims",
"", $this->
getRow($type));
2467 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyChart.php";
2468 $b1 =
new SurveyChart(
"bars", 400, 250, utf8_decode(
$title),utf8_decode($this->lng->txt(
"answers")), utf8_decode($this->lng->txt(
"users_answered")), $this->cumulated[$type][
"variables"]);
2483 function saveLayout($percent_row, $percent_columns, $percent_bipolar_adjective1 =
"", $percent_bipolar_adjective2 =
"", $percent_neutral)
2488 "percent_row" => $percent_row,
2489 "percent_columns" => $percent_columns,
2490 "percent_bipolar_adjective1" => $percent_bipolar_adjective1,
2491 "percent_bipolar_adjective2" => $percent_bipolar_adjective2,
2492 "percent_neutral" => $percent_neutral
2494 $query = sprintf(
"UPDATE survey_question_matrix SET layout = %s WHERE question_fi = %s",
2495 $ilDB->quote(serialize(
$layout) .
""),
2496 $ilDB->quote($this->
getId() .
"")
2498 $ilDB->query($query);
2503 if (!is_array($this->layout) || count($this->layout) == 0)
2507 $this->layout = array(
2508 "percent_row" => 30,
2509 "percent_columns" => 40,
2510 "percent_bipolar_adjective1" => 10,
2511 "percent_bipolar_adjective2" => 10,
2512 "percent_neutral" => 10
2517 $this->layout = array(
2518 "percent_row" => 30,
2519 "percent_columns" => 50,
2520 "percent_bipolar_adjective1" => 10,
2521 "percent_bipolar_adjective2" => 10,
2522 "percent_neutral" => 0
2527 $this->layout = array(
2528 "percent_row" => 30,
2529 "percent_columns" => 50,
2530 "percent_bipolar_adjective1" => 0,
2531 "percent_bipolar_adjective2" => 0,
2532 "percent_neutral" => 20
2537 $this->layout = array(
2538 "percent_row" => 30,
2539 "percent_columns" => 70,
2540 "percent_bipolar_adjective1" => 0,
2541 "percent_bipolar_adjective2" => 0,
2542 "percent_neutral" => 0
2557 $this->layout = unserialize(
$layout);
2608 $this->columnPlaceholders = TRUE;
2612 $this->columnPlaceholders = FALSE;
2635 $this->legend = TRUE;
2639 $this->legend = FALSE;
2657 $this->singleLineRowCaption = TRUE;
2661 $this->singleLineRowCaption = FALSE;
2674 $this->repeatColumnHeader = TRUE;
2678 $this->repeatColumnHeader = FALSE;
2689 $this->columnHeaderPosition = $a_value;
2701 $this->randomRows = TRUE;
2705 $this->randomRows = FALSE;
2716 $this->columnOrder = $a_value;
2728 $this->columnImages = TRUE;
2732 $this->columnImages = FALSE;
2745 $this->rowImages = TRUE;
2749 $this->rowImages = FALSE;