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);
166 if ((strlen($this->minimum) == 0) && ($this->
getSubtype() > 3))
170 return (strlen($this->minimum)) ? $this->minimum : NULL;
182 return (strlen($this->maximum)) ? $this->maximum : NULL;
202 return $ilDB->fetchAssoc(
$result);
233 $this->label =
$data[
'label'];
234 include_once(
"./Services/RTE/classes/class.ilRTE.php");
241 $result = $ilDB->queryF(
"SELECT svy_variable.* FROM svy_variable WHERE svy_variable.question_fi = %s",
249 $this->minimum =
$data[
"value1"];
250 if ((
$data[
"value2"] < 0) or (strcmp(
$data[
"value2"],
"") == 0))
256 $this->maximum =
$data[
"value2"];
296 if ($affectedRows == 1)
298 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
300 array($this->
getId())
302 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, subtype) VALUES (%s, %s)",
303 array(
'integer',
'text'),
304 array($this->
getId(), $this->getSubType())
311 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_variable WHERE question_fi = %s",
313 array($this->
getId())
316 if (preg_match(
"/[\D]/", $this->maximum) or (strcmp($this->maximum,
"∞") == 0))
324 $next_id = $ilDB->nextId(
'svy_variable');
325 $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)",
326 array(
'integer',
'integer',
'integer',
'float',
'float',
'integer',
'integer'),
327 array($next_id, 0, $this->
getId(), $this->
getMinimum(), $max, 0, time())
338 function toXML($a_include_header = TRUE, $obligatory_state =
"")
340 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
343 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
344 $xml = $a_xml_writer->xmlDumpMem(FALSE);
345 if (!$a_include_header)
347 $pos = strpos($xml,
"?>");
348 $xml = substr($xml, $pos + 2);
361 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state =
"")
364 "id" => $this->
getId(),
366 "type" => $this->getQuestiontype(),
370 $a_xml_writer->xmlStartTag(
"question", $attrs);
372 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
373 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
374 $a_xml_writer->xmlStartTag(
"questiontext");
376 $a_xml_writer->xmlEndTag(
"questiontext");
378 $a_xml_writer->xmlStartTag(
"responses");
412 "format" =>
"integer"
424 $a_xml_writer->xmlStartTag(
"response_num", $attrs);
425 $a_xml_writer->xmlEndTag(
"response_num");
427 $a_xml_writer->xmlEndTag(
"responses");
429 if (count($this->material))
431 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
434 "label" => $this->material[
"title"]
436 $a_xml_writer->xmlStartTag(
"material", $attrs);
437 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
438 if (strcmp($matches[1],
"") != 0)
440 $intlink = $this->material[
"internal_link"];
442 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
443 $a_xml_writer->xmlEndTag(
"material");
447 $a_xml_writer->xmlEndTag(
"question");
459 $result = $ilDB->queryF(
"SELECT questiontype_id FROM svy_qtype WHERE type_tag = %s",
464 return $row[
"questiontype_id"];
475 return "SurveyMetricQuestion";
486 return "svy_qst_metric";
497 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
499 if (strlen($entered_value))
501 array_push(
$data, array(
"value" => $entered_value));
517 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
519 $entered_value = str_replace(
",",
".", $entered_value);
523 if (strlen($entered_value) == 0)
return $this->lng->txt(
"survey_question_obligatory");
529 return $this->lng->txt(
"metric_question_out_of_bounds");
543 return $this->lng->txt(
"metric_question_out_of_bounds");
548 if (!is_numeric($entered_value))
550 return $this->lng->txt(
"metric_question_not_a_value");
553 if (($this->getSubType() ==
SUBTYPE_RATIO_ABSOLUTE) && (intval($entered_value) != doubleval($entered_value)))
555 return $this->lng->txt(
"metric_question_floating_point");
570 $next_id = $ilDB->nextId(
'svy_answer');
571 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
572 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
573 array($next_id, $this->
getId(), $active_id, $number, NULL, time())
581 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
584 $entered_value = str_replace(
",",
".", $entered_value);
588 return array(array(
"value"=>$entered_value,
"textanswer"=>null));
590 if (strlen($entered_value) == 0)
return;
592 $next_id = $ilDB->nextId(
'svy_answer');
593 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
594 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
595 array($next_id, $this->
getId(), $active_id, (strlen($entered_value)) ? $entered_value : NULL, NULL, time())
603 $question_id = $this->
getId();
605 $result_array = array();
608 $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",
609 array(
'integer',
'integer'),
620 $result_array[
"USERS_ANSWERED"] =
$result->numRows();
621 $result_array[
"USERS_SKIPPED"] = $nr_of_users -
$result->numRows();
623 $result_array[
"MODE_VALUE"] = key(
$cumulated);
627 foreach (
$cumulated as $value => $nr_of_users)
632 $percentage = (float)($nr_of_users/$numrows);
634 $result_array[
"values"][$counter++] = array(
"value" => $value,
"selected" => (
int)$nr_of_users,
"percentage" => $percentage);
641 $sum_part_zero =
false;
645 for ($i = 0; $i < $key; $i++)
647 array_push($median, $value);
652 $sum_part_zero =
true;
653 $x_i_inv += 1/$value;
661 $median_value = 0.5 * ($median[(
$total/2)-1] + $median[(
$total/2)]);
665 $median_value = $median[((
$total+1)/2)-1];
676 $result_array[
"ARITHMETIC_MEAN"] = $x_i/
$total;
680 $result_array[
"ARITHMETIC_MEAN"] = sprintf(
"%.2f", $x_i/
$total);
685 $result_array[
"ARITHMETIC_MEAN"] =
"";
687 $result_array[
"MEDIAN"] = $median_value;
688 $result_array[
"QUESTION_TYPE"] =
"SurveyMetricQuestion";
689 return $result_array;
703 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
704 $worksheet =& $workbook->addWorksheet();
706 switch ($export_label)
732 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_ANSWERED"]);
735 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_SKIPPED"]);
738 $worksheet->write($rowcounter, 0, $this->lng->txt(
"subtype"), $format_bold);
766 if (is_array($eval_data[
"values"]))
768 foreach ($eval_data[
"values"] as $key => $value)
786 if (count($resultset[
"answers"][$this->
getId()]))
788 foreach ($resultset[
"answers"][$this->
getId()] as $key => $answer)
790 array_push($a_array, $answer[
"value"]);
795 array_push($a_array, $this->lng->txt(
"skipped"));
812 $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",
813 array(
'integer',
'integer'),
818 $answers[
$row[
"active_fi"]] = $row[
"value"];
857 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
868 $template->setCurrentBlock(
"textfield");
869 $template->setVariable(
"TEXTFIELD_VALUE",
"");
870 $template->parseCurrentBlock();
881 include_once
"./Services/Form/classes/class.ilNumberInputGUI.php";
883 $step3->setValue($default);
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 .
")";