24 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
165 if ((strlen($this->minimum) == 0) && ($this->
getSubtype() > 3))
169 return (strlen($this->minimum)) ? $this->minimum : NULL;
181 return (strlen($this->maximum)) ? $this->maximum : NULL;
201 return $ilDB->fetchAssoc(
$result);
225 $data = $ilDB->fetchAssoc(
$result);
226 $this->
setId($data[
"question_id"]);
232 $this->label = $data[
'label'];
233 include_once(
"./Services/RTE/classes/class.ilRTE.php");
240 $result = $ilDB->queryF(
"SELECT svy_variable.* FROM svy_variable WHERE svy_variable.question_fi = %s",
246 if ($data = $ilDB->fetchAssoc(
$result))
248 $this->minimum = $data[
"value1"];
249 if (($data[
"value2"] < 0) or (strcmp($data[
"value2"],
"") == 0))
255 $this->maximum = $data[
"value2"];
295 if ($affectedRows == 1)
297 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
299 array($this->
getId())
301 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, subtype) VALUES (%s, %s)",
302 array(
'integer',
'text'),
303 array($this->
getId(), $this->getSubType())
310 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_variable WHERE question_fi = %s",
312 array($this->
getId())
315 if (preg_match(
"/[\D]/", $this->maximum) or (strcmp($this->maximum,
"∞") == 0))
323 $next_id = $ilDB->nextId(
'svy_variable');
324 $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)",
325 array(
'integer',
'integer',
'integer',
'float',
'float',
'integer',
'integer'),
326 array($next_id, 0, $this->
getId(), $this->
getMinimum(), $max, 0, time())
337 function toXML($a_include_header = TRUE, $obligatory_state =
"")
339 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
342 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
343 $xml = $a_xml_writer->xmlDumpMem(FALSE);
344 if (!$a_include_header)
346 $pos = strpos($xml,
"?>");
347 $xml = substr($xml, $pos + 2);
360 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state =
"")
363 "id" => $this->
getId(),
365 "type" => $this->getQuestiontype(),
369 $a_xml_writer->xmlStartTag(
"question", $attrs);
371 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
372 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
373 $a_xml_writer->xmlStartTag(
"questiontext");
375 $a_xml_writer->xmlEndTag(
"questiontext");
377 $a_xml_writer->xmlStartTag(
"responses");
411 "format" =>
"integer"
423 $a_xml_writer->xmlStartTag(
"response_num", $attrs);
424 $a_xml_writer->xmlEndTag(
"response_num");
426 $a_xml_writer->xmlEndTag(
"responses");
428 if (count($this->material))
430 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
433 "label" => $this->material[
"title"]
435 $a_xml_writer->xmlStartTag(
"material", $attrs);
436 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
437 if (strcmp($matches[1],
"") != 0)
439 $intlink = $this->material[
"internal_link"];
441 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
442 $a_xml_writer->xmlEndTag(
"material");
446 $a_xml_writer->xmlEndTag(
"question");
458 $result = $ilDB->queryF(
"SELECT questiontype_id FROM svy_qtype WHERE type_tag = %s",
463 return $row[
"questiontype_id"];
474 return "SurveyMetricQuestion";
485 return "svy_qst_metric";
496 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
498 if (strlen($entered_value))
500 array_push($data, array(
"value" => $entered_value));
516 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
518 $entered_value = str_replace(
",",
".", $entered_value);
522 if (strlen($entered_value) == 0)
return $this->lng->txt(
"survey_question_obligatory");
528 return $this->lng->txt(
"metric_question_out_of_bounds");
542 return $this->lng->txt(
"metric_question_out_of_bounds");
547 if (!is_numeric($entered_value))
549 return $this->lng->txt(
"metric_question_not_a_value");
552 if (($this->getSubType() == self::SUBTYPE_RATIO_ABSOLUTE) && (intval($entered_value) != doubleval($entered_value)))
554 return $this->lng->txt(
"metric_question_floating_point");
569 $next_id = $ilDB->nextId(
'svy_answer');
570 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
571 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
572 array($next_id, $this->
getId(), $active_id, $number, NULL, time())
580 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
583 $entered_value = str_replace(
",",
".", $entered_value);
587 return array(array(
"value"=>$entered_value,
"textanswer"=>null));
589 if (strlen($entered_value) == 0)
return;
591 $next_id = $ilDB->nextId(
'svy_answer');
592 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
593 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
594 array($next_id, $this->
getId(), $active_id, (strlen($entered_value)) ? $entered_value : NULL, NULL, time())
602 $question_id = $this->
getId();
604 $result_array = array();
607 $sql =
"SELECT svy_answer.* FROM svy_answer".
608 " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
609 " WHERE svy_answer.question_fi = ".$ilDB->quote($question_id,
"integer").
610 " AND svy_finished.survey_fi = ".$ilDB->quote(
$survey_id,
"integer");
613 $sql .=
" AND ".$ilDB->in(
"svy_finished.finished_id", $finished_ids,
"",
"integer");
624 $result_array[
"USERS_ANSWERED"] =
$result->numRows();
625 $result_array[
"USERS_SKIPPED"] = $nr_of_users -
$result->numRows();
629 $result_array[
"MODE_VALUE"] = key(
$cumulated);
634 foreach (
$cumulated as $value => $nr_of_users)
639 $percentage = (float)($nr_of_users/$numrows);
641 $result_array[
"values"][$counter++] = array(
"value" => $value,
"selected" => (
int)$nr_of_users,
"percentage" => $percentage);
648 $sum_part_zero =
false;
652 for ($i = 0; $i < $key; $i++)
654 array_push($median, $value);
659 $sum_part_zero =
true;
660 $x_i_inv += 1/$value;
668 $median_value = 0.5 * ($median[(
$total/2)-1] + $median[(
$total/2)]);
672 $median_value = $median[((
$total+1)/2)-1];
683 $result_array[
"ARITHMETIC_MEAN"] = $x_i/
$total;
687 $result_array[
"ARITHMETIC_MEAN"] = sprintf(
"%.2f", $x_i/
$total);
692 $result_array[
"ARITHMETIC_MEAN"] =
"";
694 $result_array[
"MEDIAN"] = $median_value;
695 $result_array[
"QUESTION_TYPE"] =
"SurveyMetricQuestion";
696 return $result_array;
710 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
711 $worksheet =& $workbook->addWorksheet();
713 switch ($export_label)
739 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_ANSWERED"]);
742 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_SKIPPED"]);
745 $worksheet->write($rowcounter, 0, $this->lng->txt(
"subtype"), $format_bold);
748 case self::SUBTYPE_NON_RATIO:
751 case self::SUBTYPE_RATIO_NON_ABSOLUTE:
754 case self::SUBTYPE_RATIO_ABSOLUTE:
773 if (is_array($eval_data[
"values"]))
775 foreach ($eval_data[
"values"] as $key => $value)
793 if (count($resultset[
"answers"][$this->
getId()]))
795 foreach ($resultset[
"answers"][$this->
getId()] as $key => $answer)
797 array_push($a_array, $answer[
"value"]);
819 $sql =
"SELECT svy_answer.* FROM svy_answer".
820 " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
821 " WHERE svy_answer.question_fi = ".$ilDB->quote($this->
getId(),
"integer").
822 " AND svy_finished.survey_fi = ".$ilDB->quote(
$survey_id,
"integer");
825 $sql .=
" AND ".$ilDB->in(
"svy_finished.finished_id", $finished_ids,
"",
"integer");
831 $answers[
$row[
"active_fi"]] = $row[
"value"];
844 foreach ($a_data as
$id => $data)
870 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
881 $template->setCurrentBlock(
"textfield");
882 $template->setVariable(
"TEXTFIELD_VALUE",
"");
883 $template->parseCurrentBlock();
894 include_once
"./Services/Form/classes/class.ilNumberInputGUI.php";
896 $step3->setValue($default);
910 if (strlen($min) && strlen($max))
912 return "(" . $min .
" " . strtolower($this->lng->txt(
"to")) .
" " . $max .
")";
914 else if (strlen($min))
916 return "(>= " . $min .
")";
918 else if (strlen($max))
920 return "(<= " . $max .
")";