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);
150 if ((strlen($this->minimum) == 0) && ($this->
getSubtype() > 3))
154 return (strlen($this->minimum)) ? $this->minimum : NULL;
166 return (strlen($this->maximum)) ? $this->maximum : NULL;
184 if ($result->numRows() == 1)
186 return $ilDB->fetchAssoc($result);
208 if ($result->numRows() == 1)
210 $data = $ilDB->fetchAssoc($result);
217 $this->label =
$data[
'label'];
218 include_once(
"./Services/RTE/classes/class.ilRTE.php");
225 $result = $ilDB->queryF(
"SELECT svy_variable.* FROM svy_variable WHERE svy_variable.question_fi = %s",
229 if ($result->numRows() > 0)
231 if (
$data = $ilDB->fetchAssoc($result))
233 $this->minimum =
$data[
"value1"];
234 if ((
$data[
"value2"] < 0) or (strcmp(
$data[
"value2"],
"") == 0))
240 $this->maximum =
$data[
"value2"];
256 if ($this->title and $this->author and $this->questiontext)
276 if ($affectedRows == 1)
278 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
280 array($this->
getId())
282 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, subtype) VALUES (%s, %s)",
283 array(
'integer',
'text'),
284 array($this->
getId(), $this->getSubType())
291 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_variable WHERE question_fi = %s",
293 array($this->
getId())
296 if (preg_match(
"/[\D]/", $this->maximum) or (strcmp($this->maximum,
"∞") == 0))
304 $next_id = $ilDB->nextId(
'svy_variable');
305 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, value2, sequence, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
306 array(
'integer',
'integer',
'integer',
'float',
'float',
'integer',
'integer'),
307 array($next_id, 0, $this->
getId(), $this->
getMinimum(), $max, 0, time())
318 function toXML($a_include_header = TRUE, $obligatory_state =
"")
320 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
323 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
324 $xml = $a_xml_writer->xmlDumpMem(FALSE);
325 if (!$a_include_header)
327 $pos = strpos($xml,
"?>");
328 $xml = substr($xml,
$pos + 2);
341 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state =
"")
344 "id" => $this->
getId(),
346 "type" => $this->getQuestiontype(),
350 $a_xml_writer->xmlStartTag(
"question", $attrs);
352 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
353 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
354 $a_xml_writer->xmlStartTag(
"questiontext");
356 $a_xml_writer->xmlEndTag(
"questiontext");
358 $a_xml_writer->xmlStartTag(
"responses");
392 "format" =>
"integer"
404 $a_xml_writer->xmlStartTag(
"response_num", $attrs);
405 $a_xml_writer->xmlEndTag(
"response_num");
407 $a_xml_writer->xmlEndTag(
"responses");
409 if (count($this->material))
411 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
414 "label" => $this->material[
"title"]
416 $a_xml_writer->xmlStartTag(
"material", $attrs);
417 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
418 if (strcmp($matches[1],
"") != 0)
420 $intlink = $this->material[
"internal_link"];
422 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
423 $a_xml_writer->xmlEndTag(
"material");
427 $a_xml_writer->xmlEndTag(
"question");
439 $result = $ilDB->queryF(
"SELECT questiontype_id FROM svy_qtype WHERE type_tag = %s",
443 $row = $ilDB->fetchAssoc($result);
444 return $row[
"questiontype_id"];
455 return "SurveyMetricQuestion";
466 return "svy_qst_metric";
477 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
479 if (strlen($entered_value))
481 array_push(
$data, array(
"value" => $entered_value));
497 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
499 $entered_value = str_replace(
",",
".", $entered_value);
503 if (strlen($entered_value) == 0)
return $this->lng->txt(
"survey_question_obligatory");
509 return $this->lng->txt(
"metric_question_out_of_bounds");
523 return $this->lng->txt(
"metric_question_out_of_bounds");
528 if (!is_numeric($entered_value))
530 return $this->lng->txt(
"metric_question_not_a_value");
533 if (($this->getSubType() ==
SUBTYPE_RATIO_ABSOLUTE) && (intval($entered_value) != doubleval($entered_value)))
535 return $this->lng->txt(
"metric_question_floating_point");
550 $next_id = $ilDB->nextId(
'svy_answer');
551 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
552 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
553 array($next_id, $this->
getId(), $active_id, $number, NULL, time())
561 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
562 if (strlen($entered_value) == 0)
return;
564 $entered_value = str_replace(
",",
".", $entered_value);
565 $next_id = $ilDB->nextId(
'svy_answer');
566 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
567 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
568 array($next_id, $this->
getId(), $active_id, (strlen($entered_value)) ? $entered_value : NULL, NULL, time())
576 $question_id = $this->
getId();
578 $result_array = array();
581 $result = $ilDB->queryF(
"SELECT svy_answer.* FROM svy_answer, svy_finished WHERE svy_answer.question_fi = %s AND svy_finished.survey_fi = %s AND svy_finished.finished_id = svy_answer.active_fi",
582 array(
'integer',
'integer'),
586 while (
$row = $ilDB->fetchAssoc($result))
592 $numrows = $result->numRows();
593 $result_array[
"USERS_ANSWERED"] = $result->numRows();
594 $result_array[
"USERS_SKIPPED"] = $nr_of_users - $result->numRows();
596 $result_array[
"MODE_VALUE"] = key(
$cumulated);
600 foreach (
$cumulated as $value => $nr_of_users)
605 $percentage = (float)($nr_of_users/$numrows);
607 $result_array[
"values"][$counter++] = array(
"value" => $value,
"selected" => (
int)$nr_of_users,
"percentage" => $percentage);
614 $sum_part_zero =
false;
618 for ($i = 0; $i < $key; $i++)
620 array_push($median, $value);
625 $sum_part_zero =
true;
626 $x_i_inv += 1/$value;
634 $median_value = 0.5 * ($median[(
$total/2)-1] + $median[(
$total/2)]);
638 $median_value = $median[((
$total+1)/2)-1];
649 $result_array[
"ARITHMETIC_MEAN"] = $x_i/
$total;
653 $result_array[
"ARITHMETIC_MEAN"] = sprintf(
"%.2f", $x_i/
$total);
658 $result_array[
"ARITHMETIC_MEAN"] =
"";
660 $result_array[
"MEDIAN"] = $median_value;
661 $result_array[
"QUESTION_TYPE"] =
"SurveyMetricQuestion";
662 return $result_array;
674 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
675 $adapter->addWorksheet($this->
getTitle());
676 $adapter->setActiveWorksheet($adapter->getWorksheetCount()-1);
678 switch ($export_label)
682 $adapter->setCellValue(0, 1, $this->label);
686 $adapter->setCellValue(0, 1, $this->
getTitle());
690 $adapter->setCellValue(0, 1, $this->
getTitle());
692 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"label"),
CELL_FORMAT_BOLD);
693 $adapter->setCellValue($rowcounter, 1, $this->label);
697 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"question"),
CELL_FORMAT_BOLD);
700 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"question_type"),
CELL_FORMAT_BOLD);
701 $adapter->setCellValue($rowcounter, 1, $this->lng->txt($this->getQuestionType()));
703 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"users_answered"),
CELL_FORMAT_BOLD);
704 $adapter->setCellValue($rowcounter, 1, $eval_data[
"TOTAL"][
"USERS_ANSWERED"]);
706 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"users_skipped"),
CELL_FORMAT_BOLD);
707 $adapter->setCellValue($rowcounter, 1, $eval_data[
"TOTAL"][
"USERS_SKIPPED"]);
710 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"subtype"),
CELL_FORMAT_BOLD);
714 $adapter->setCellValue($rowcounter++, 1, $this->lng->txt(
"non_ratio"),
CELL_FORMAT_BOLD);
717 $adapter->setCellValue($rowcounter++, 1, $this->lng->txt(
"ratio_non_absolute"),
CELL_FORMAT_BOLD);
720 $adapter->setCellValue($rowcounter++, 1, $this->lng->txt(
"ratio_absolute"),
CELL_FORMAT_BOLD);
723 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"mode"),
CELL_FORMAT_BOLD);
724 $adapter->setCellValue($rowcounter++, 1, $eval_data[
"MODE"]);
725 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"mode_text"),
CELL_FORMAT_BOLD);
726 $adapter->setCellValue($rowcounter++, 1, $eval_data[
"MODE"]);
727 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"mode_nr_of_selections"),
CELL_FORMAT_BOLD);
728 $adapter->setCellValue($rowcounter++, 1, $eval_data[
"MODE_NR_OF_SELECTIONS"]);
729 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"median"),
CELL_FORMAT_BOLD);
730 $adapter->setCellValue($rowcounter++, 1, $eval_data[
"MEDIAN"]);
731 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"arithmetic_mean"),
CELL_FORMAT_BOLD);
732 $adapter->setCellValue($rowcounter++, 1, $eval_data[
"ARITHMETIC_MEAN"]);
733 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"values"),
CELL_FORMAT_BOLD);
734 $adapter->setCellValue($rowcounter, 1, $this->lng->txt(
"value"),
CELL_FORMAT_TITLE);
735 $adapter->setCellValue($rowcounter, 2, $this->lng->txt(
"category_nr_selected"),
CELL_FORMAT_TITLE);
736 $adapter->setCellValue($rowcounter++, 3, $this->lng->txt(
"percentage_of_selections"),
CELL_FORMAT_TITLE);
738 if (is_array($eval_data[
"values"]))
740 foreach ($eval_data[
"values"] as $key => $value)
742 $adapter->setCellValue($rowcounter, 1, $value[
"value"]);
743 $adapter->setCellValue($rowcounter, 2, $value[
"selected"]);
758 if (count($resultset[
"answers"][$this->
getId()]))
760 foreach ($resultset[
"answers"][$this->
getId()] as $key => $answer)
762 array_push($a_array, $answer[
"value"]);
767 array_push($a_array, $this->lng->txt(
"skipped"));
784 $result = $ilDB->queryF(
"SELECT svy_answer.* FROM svy_answer, svy_finished WHERE svy_finished.survey_fi = %s AND svy_answer.question_fi = %s AND svy_finished.finished_id = svy_answer.active_fi",
785 array(
'integer',
'integer'),
788 while (
$row = $ilDB->fetchAssoc($result))
790 $answers[
$row[
"active_fi"]] = $row[
"value"];
829 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
840 $template->setCurrentBlock(
"textfield");
841 $template->setVariable(
"TEXTFIELD_VALUE",
"");
842 $template->parseCurrentBlock();
853 include_once
"./Services/Form/classes/class.ilNumberInputGUI.php";
855 $step3->setValue($default);
869 if (count($this->cumulated) == 0)
871 include_once
"./Modules/Survey/classes/class.ilObjSurvey.php";
876 foreach ($this->cumulated[
"values"] as $key => $value)
878 foreach ($value as $key2 => $value2)
880 $this->cumulated[
"variables"][$key][$key2] = utf8_decode($value2);
883 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyChart.php";
884 $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"]);
897 if (strlen($min) && strlen($max))
899 return "(" . $min .
" " . strtolower($this->lng->txt(
"to")) .
" " . $max .
")";
901 else if (strlen($min))
903 return "(>= " . $min .
")";
905 else if (strlen($max))
907 return "(<= " . $max .
")";