24 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
25 include_once
"./Modules/Survey/classes/inc.SurveyConstants.php";
27 define(
"SUBTYPE_NON_RATIO", 3);
28 define(
"SUBTYPE_RATIO_NON_ABSOLUTE", 4);
29 define(
"SUBTYPE_RATIO_ABSOLUTE", 5);
165 if ((strlen($this->minimum) == 0) && ($this->
getSubtype() > 3))
199 $query = sprintf(
"SELECT survey_question.*, survey_question_metric.* FROM survey_question, survey_question_metric WHERE survey_question.question_id = %s AND survey_question.question_id = survey_question_metric.question_fi",
202 $result = $ilDB->query($query);
203 if ($result->numRows() == 1)
205 return $result->fetchRow(MDB2_FETCHMODE_ASSOC);
224 $query = sprintf(
"SELECT survey_question.*, survey_question_metric.* FROM survey_question, survey_question_metric WHERE survey_question.question_id = %s AND survey_question.question_id = survey_question_metric.question_fi",
227 $result = $ilDB->query($query);
228 if ($result->numRows() == 1)
230 $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
231 $this->
id =
$data->question_id;
232 $this->title =
$data->title;
233 $this->description =
$data->description;
234 $this->obj_id =
$data->obj_fi;
235 $this->obligatory =
$data->obligatory;
236 $this->author =
$data->author;
237 $this->subtype =
$data->subtype;
238 $this->original_id =
$data->original_id;
239 $this->owner =
$data->owner_fi;
240 include_once(
"./Services/RTE/classes/class.ilRTE.php");
242 $this->complete =
$data->complete;
246 $query = sprintf(
"SELECT survey_variable.* FROM survey_variable WHERE survey_variable.question_fi = %s",
249 $result = $ilDB->query($query);
250 if ($result->numRows() > 0)
252 if (
$data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
254 $this->minimum =
$data->value1;
255 if ((
$data->value2 < 0) or (strcmp(
$data->value2,
"") == 0))
261 $this->maximum =
$data->value2;
279 if ($this->title and $this->author and $this->questiontext)
306 $original_id = $ilDB->quote($original_id);
310 $original_id =
"NULL";
313 include_once(
"./Services/RTE/classes/class.ilRTE.php");
321 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
322 $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)",
323 $ilDB->quote($this->getQuestionTypeID()),
324 $ilDB->quote($this->obj_id),
325 $ilDB->quote($this->owner),
326 $ilDB->quote($this->title),
327 $ilDB->quote($this->description),
328 $ilDB->quote($this->author),
330 $ilDB->quote(sprintf(
"%d", $this->obligatory)),
331 $ilDB->quote(
"$complete"),
332 $ilDB->quote($created),
335 $result = $ilDB->query($query);
336 if (PEAR::isError($result))
339 $ilias->raiseError($result->getMessage());
343 $this->
id = $ilDB->getLastInsertId();
344 $query = sprintf(
"INSERT INTO survey_question_metric (question_fi, subtype) VALUES (%s, %s)",
345 $ilDB->quote($this->id .
""),
346 $ilDB->quote($this->getSubType() .
"")
348 $ilDB->query($query);
354 $query = sprintf(
"UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
355 $ilDB->quote($this->title),
356 $ilDB->quote($this->description),
357 $ilDB->quote($this->author),
359 $ilDB->quote(sprintf(
"%d", $this->obligatory)),
360 $ilDB->quote(
"$complete"),
361 $ilDB->quote($this->
id)
363 $result = $ilDB->query($query);
364 $query = sprintf(
"UPDATE survey_question_metric SET subtype = %s WHERE question_fi = %s",
365 $ilDB->quote($this->getSubType() .
""),
366 $ilDB->quote($this->id .
"")
368 $result = $ilDB->query($query);
373 $ilias->raiseError(
$result->getMessage());
381 $query = sprintf(
"DELETE FROM survey_variable WHERE question_fi = %s",
382 $ilDB->quote($this->id)
384 $result = $ilDB->query($query);
386 if (strcmp($this->minimum,
"") == 0)
392 $min = $ilDB->quote($this->minimum);
394 if (preg_match(
"/[\D]/", $this->maximum) or (strcmp($this->maximum,
"∞") == 0))
400 if (strcmp($this->maximum,
"") == 0)
406 $max = $ilDB->quote($this->maximum);
409 $query = sprintf(
"INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, value2, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
411 $ilDB->quote($this->
id),
416 $answer_result = $ilDB->query($query);
429 function toXML($a_include_header = TRUE, $obligatory_state =
"")
431 include_once(
"./classes/class.ilXmlWriter.php");
434 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
435 $xml = $a_xml_writer->xmlDumpMem(FALSE);
436 if (!$a_include_header)
438 $pos = strpos($xml,
"?>");
439 $xml = substr($xml, $pos + 2);
454 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state =
"")
457 "id" => $this->
getId(),
459 "type" => $this->getQuestiontype(),
463 $a_xml_writer->xmlStartTag(
"question", $attrs);
465 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
466 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
467 $a_xml_writer->xmlStartTag(
"questiontext");
469 $a_xml_writer->xmlEndTag(
"questiontext");
471 $a_xml_writer->xmlStartTag(
"responses");
505 "format" =>
"integer"
517 $a_xml_writer->xmlStartTag(
"response_num", $attrs);
518 $a_xml_writer->xmlEndTag(
"response_num");
520 $a_xml_writer->xmlEndTag(
"responses");
522 if (count($this->material))
524 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
527 "label" => $this->material[
"title"]
529 $a_xml_writer->xmlStartTag(
"material", $attrs);
530 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
531 if (strcmp($matches[1],
"") != 0)
533 $intlink = $this->material[
"internal_link"];
535 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
536 $a_xml_writer->xmlEndTag(
"material");
540 $a_xml_writer->xmlEndTag(
"question");
546 if ($this->original_id)
553 $query = sprintf(
"UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
554 $ilDB->quote($this->title .
""),
555 $ilDB->quote($this->description .
""),
556 $ilDB->quote($this->author .
""),
557 $ilDB->quote($this->questiontext .
""),
558 $ilDB->quote(sprintf(
"%d", $this->obligatory) .
""),
559 $ilDB->quote($complete .
""),
560 $ilDB->quote($this->original_id .
"")
562 $result = $ilDB->query($query);
563 $query = sprintf(
"UPDATE survey_question_metric SET subtype = %s WHERE question_fi = %s",
564 $ilDB->quote($this->getSubType() .
""),
565 $ilDB->quote($this->original_id .
"")
567 $result = $ilDB->query($query);
568 if (PEAR::isError($result))
571 $ilias->raiseError($result->getMessage());
578 $query = sprintf(
"DELETE FROM survey_variable WHERE question_fi = %s",
579 $ilDB->quote($this->original_id)
581 $result = $ilDB->query($query);
583 if (strcmp($this->minimum,
"") == 0)
589 $min = $ilDB->quote($this->minimum .
"");
591 if (preg_match(
"/[\D]/", $this->maximum) or (strcmp($this->maximum,
"∞") == 0))
597 if (strcmp($this->maximum,
"") == 0)
603 $max = $ilDB->quote($this->maximum .
"");
606 $query = sprintf(
"INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, value2, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
608 $ilDB->quote($this->original_id .
""),
613 $answer_result = $ilDB->query($query);
630 $query = sprintf(
"SELECT questiontype_id FROM survey_questiontype WHERE type_tag = %s",
631 $ilDB->quote($this->getQuestionType())
633 $result = $ilDB->query($query);
634 $row =
$result->fetchRow(MDB2_FETCHMODE_ASSOC);
635 return $row[
"questiontype_id"];
648 return "SurveyMetricQuestion";
661 return "survey_question_metric";
674 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
676 if (strlen($entered_value))
678 array_push(
$data, array(
"value" => $entered_value));
697 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
699 $entered_value = str_replace(
",",
".", $entered_value);
703 if (strlen($entered_value) == 0)
return $this->lng->txt(
"survey_question_obligatory");
709 return $this->lng->txt(
"metric_question_out_of_bounds");
723 return $this->lng->txt(
"metric_question_out_of_bounds");
728 if (!is_numeric($entered_value))
730 return $this->lng->txt(
"metric_question_not_a_value");
733 if (($this->getSubType() ==
SUBTYPE_RATIO_ABSOLUTE) && (intval($entered_value) != doubleval($entered_value)))
735 return $this->lng->txt(
"metric_question_floating_point");
750 $query = sprintf(
"INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, NULL)",
751 $ilDB->quote($this->getId()),
752 $ilDB->quote($active_id),
753 $ilDB->quote($number)
755 $result = $ilDB->query($query);
762 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
763 if (strlen($entered_value) == 0)
return;
765 $entered_value = str_replace(
",",
".", $entered_value);
767 if (strlen($entered_value) == 0)
769 $entered_value =
"NULL";
773 $entered_value = $ilDB->quote($entered_value .
"");
775 $query = sprintf(
"INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
776 $ilDB->quote($this->getId() .
""),
777 $ilDB->quote($active_id .
""),
781 $result = $ilDB->query($query);
788 $question_id = $this->
getId();
790 $result_array = array();
791 $cumulated = array();
793 $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",
794 $ilDB->quote($question_id),
797 $result = $ilDB->query($query);
799 while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
801 $cumulated[
"$row->value"]++;
803 asort($cumulated, SORT_NUMERIC);
805 $numrows = $result->numRows();
806 $result_array[
"USERS_ANSWERED"] = $result->numRows();
807 $result_array[
"USERS_SKIPPED"] = $nr_of_users - $result->numRows();
808 $result_array[
"MODE"] = key($cumulated);
809 $result_array[
"MODE_VALUE"] = key($cumulated);
810 $result_array[
"MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
811 ksort($cumulated, SORT_NUMERIC);
813 foreach ($cumulated as $value => $nr_of_users)
818 $percentage = (float)($nr_of_users/$numrows);
820 $result_array[
"values"][$counter++] = array(
"value" => $value,
"selected" => (
int)$nr_of_users,
"percentage" => $percentage);
827 $sum_part_zero =
false;
828 foreach ($cumulated as $value => $key)
831 for ($i = 0; $i < $key; $i++)
833 array_push($median, $value);
838 $sum_part_zero =
true;
839 $x_i_inv += 1/$value;
847 $median_value = 0.5 * ($median[(
$total/2)-1] + $median[(
$total/2)]);
851 $median_value = $median[((
$total+1)/2)-1];
862 $result_array[
"ARITHMETIC_MEAN"] = $x_i/
$total;
866 $result_array[
"ARITHMETIC_MEAN"] = sprintf(
"%.2f", $x_i/
$total);
871 $result_array[
"ARITHMETIC_MEAN"] =
"";
873 $result_array[
"MEDIAN"] = $median_value;
874 $result_array[
"QUESTION_TYPE"] =
"SurveyMetricQuestion";
875 return $result_array;
891 include_once (
"./classes/class.ilExcelUtils.php");
892 $worksheet =& $workbook->addWorksheet();
900 $worksheet->write(3, 1, $eval_data[
"USERS_ANSWERED"]);
902 $worksheet->write(4, 1, $eval_data[
"USERS_SKIPPED"]);
905 $worksheet->write($rowcounter, 0, $this->lng->txt(
"subtype"), $format_bold);
933 if (is_array($eval_data[
"values"]))
935 foreach ($eval_data[
"values"] as $key => $value)
955 if (count($resultset[
"answers"][$this->
getId()]))
957 foreach ($resultset[
"answers"][$this->
getId()] as $key => $answer)
959 array_push($a_array, $answer[
"value"]);
964 array_push($a_array, $this->lng->txt(
"skipped"));
983 $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",
985 $ilDB->quote($this->
getId())
987 $result = $ilDB->query($query);
988 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
990 $answers[$row[
"active_fi"]] = $row[
"value"];
1035 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
1048 $template->setCurrentBlock(
"textfield");
1049 $template->setVariable(
"TEXTFIELD_VALUE",
"");
1050 $template->parseCurrentBlock();
1065 include_once
"./classes/class.ilTemplate.php";
1066 $template =
new ilTemplate(
"tpl.il_svy_svy_precondition_select_value_textfield.html", TRUE, TRUE,
"Modules/Survey");
1067 if (strlen($default))
1069 $template->setCurrentBlock(
"textfield");
1071 $template->parseCurrentBlock();
1075 $template->touchBlock(
"textfield");
1077 $template->setVariable(
"SELECT_VALUE", $lng->txt(
"step") .
" 3: " . $lng->txt(
"enter_value"));
1078 return $template->get();
1093 if (count($this->cumulated) == 0)
1095 include_once
"./Modules/Survey/classes/class.ilObjSurvey.php";
1100 foreach ($this->cumulated[
"values"] as $key => $value)
1102 foreach ($value as $key2 => $value2)
1104 $this->cumulated[
"variables"][$key][$key2] = utf8_decode($value2);
1107 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyChart.php";
1108 $b1 =
new SurveyChart(
"bars",400,250,utf8_decode($this->
getTitle()),utf8_decode($this->lng->txt(
"answers")),utf8_decode($this->lng->txt(
"users_answered")),$this->cumulated[
"values"]);
1123 if (strlen($min) && strlen($max))
1125 return "(" . $min .
" " . strtolower($this->lng->txt(
"to")) .
" " . $max .
")";
1127 else if (strlen($min))
1129 return "(>= " . $min .
")";
1131 else if (strlen($max))
1133 return "(<= " . $max .
")";