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;
186 return $ilDB->fetchAssoc(
$result);
217 include_once(
"./Services/RTE/classes/class.ilRTE.php");
224 $result = $ilDB->queryF(
"SELECT svy_variable.* FROM svy_variable WHERE svy_variable.question_fi = %s",
232 $this->minimum =
$data[
"value1"];
233 if ((
$data[
"value2"] < 0) or (strcmp(
$data[
"value2"],
"") == 0))
239 $this->maximum =
$data[
"value2"];
255 if ($this->title and $this->author and $this->questiontext)
275 if ($affectedRows == 1)
277 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
279 array($this->
getId())
281 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, subtype) VALUES (%s, %s)",
282 array(
'integer',
'text'),
283 array($this->
getId(), $this->getSubType())
290 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_variable WHERE question_fi = %s",
292 array($this->
getId())
295 if (preg_match(
"/[\D]/", $this->maximum) or (strcmp($this->maximum,
"∞") == 0))
303 $next_id = $ilDB->nextId(
'svy_variable');
304 $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)",
305 array(
'integer',
'integer',
'integer',
'float',
'float',
'integer',
'integer'),
306 array($next_id, 0, $this->
getId(), $this->
getMinimum(), $max, 0, time())
317 function toXML($a_include_header = TRUE, $obligatory_state =
"")
319 include_once(
"./classes/class.ilXmlWriter.php");
322 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
323 $xml = $a_xml_writer->xmlDumpMem(FALSE);
324 if (!$a_include_header)
326 $pos = strpos($xml,
"?>");
327 $xml = substr($xml, $pos + 2);
340 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state =
"")
343 "id" => $this->
getId(),
345 "type" => $this->getQuestiontype(),
349 $a_xml_writer->xmlStartTag(
"question", $attrs);
351 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
352 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
353 $a_xml_writer->xmlStartTag(
"questiontext");
355 $a_xml_writer->xmlEndTag(
"questiontext");
357 $a_xml_writer->xmlStartTag(
"responses");
391 "format" =>
"integer"
403 $a_xml_writer->xmlStartTag(
"response_num", $attrs);
404 $a_xml_writer->xmlEndTag(
"response_num");
406 $a_xml_writer->xmlEndTag(
"responses");
408 if (count($this->material))
410 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
413 "label" => $this->material[
"title"]
415 $a_xml_writer->xmlStartTag(
"material", $attrs);
416 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
417 if (strcmp($matches[1],
"") != 0)
419 $intlink = $this->material[
"internal_link"];
421 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
422 $a_xml_writer->xmlEndTag(
"material");
426 $a_xml_writer->xmlEndTag(
"question");
438 $result = $ilDB->queryF(
"SELECT questiontype_id FROM svy_qtype WHERE type_tag = %s",
443 return $row[
"questiontype_id"];
454 return "SurveyMetricQuestion";
465 return "svy_qst_metric";
476 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
478 if (strlen($entered_value))
480 array_push(
$data, array(
"value" => $entered_value));
496 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
498 $entered_value = str_replace(
",",
".", $entered_value);
502 if (strlen($entered_value) == 0)
return $this->lng->txt(
"survey_question_obligatory");
508 return $this->lng->txt(
"metric_question_out_of_bounds");
522 return $this->lng->txt(
"metric_question_out_of_bounds");
527 if (!is_numeric($entered_value))
529 return $this->lng->txt(
"metric_question_not_a_value");
532 if (($this->getSubType() ==
SUBTYPE_RATIO_ABSOLUTE) && (intval($entered_value) != doubleval($entered_value)))
534 return $this->lng->txt(
"metric_question_floating_point");
549 $next_id = $ilDB->nextId(
'svy_answer');
550 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
551 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
552 array($next_id, $this->
getId(), $active_id, $number, NULL, time())
560 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
561 if (strlen($entered_value) == 0)
return;
563 $entered_value = str_replace(
",",
".", $entered_value);
564 $next_id = $ilDB->nextId(
'svy_answer');
565 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
566 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
567 array($next_id, $this->
getId(), $active_id, (strlen($entered_value)) ? $entered_value : NULL, NULL, time())
575 $question_id = $this->
getId();
577 $result_array = array();
580 $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",
581 array(
'integer',
'integer'),
592 $result_array[
"USERS_ANSWERED"] =
$result->numRows();
593 $result_array[
"USERS_SKIPPED"] = $nr_of_users -
$result->numRows();
595 $result_array[
"MODE_VALUE"] = key(
$cumulated);
599 foreach (
$cumulated as $value => $nr_of_users)
604 $percentage = (float)($nr_of_users/$numrows);
606 $result_array[
"values"][$counter++] = array(
"value" => $value,
"selected" => (
int)$nr_of_users,
"percentage" => $percentage);
613 $sum_part_zero =
false;
617 for ($i = 0; $i <
$key; $i++)
619 array_push($median, $value);
624 $sum_part_zero =
true;
625 $x_i_inv += 1/$value;
633 $median_value = 0.5 * ($median[(
$total/2)-1] + $median[(
$total/2)]);
637 $median_value = $median[((
$total+1)/2)-1];
648 $result_array[
"ARITHMETIC_MEAN"] = $x_i/
$total;
652 $result_array[
"ARITHMETIC_MEAN"] = sprintf(
"%.2f", $x_i/
$total);
657 $result_array[
"ARITHMETIC_MEAN"] =
"";
659 $result_array[
"MEDIAN"] = $median_value;
660 $result_array[
"QUESTION_TYPE"] =
"SurveyMetricQuestion";
661 return $result_array;
675 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
676 $worksheet =& $workbook->addWorksheet();
684 $worksheet->write(3, 1, $eval_data[
"USERS_ANSWERED"]);
686 $worksheet->write(4, 1, $eval_data[
"USERS_SKIPPED"]);
689 $worksheet->write($rowcounter, 0, $this->lng->txt(
"subtype"), $format_bold);
717 if (is_array($eval_data[
"values"]))
719 foreach ($eval_data[
"values"] as
$key => $value)
737 if (count($resultset[
"answers"][$this->
getId()]))
739 foreach ($resultset[
"answers"][$this->
getId()] as
$key => $answer)
741 array_push($a_array, $answer[
"value"]);
746 array_push($a_array, $this->lng->txt(
"skipped"));
763 $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",
764 array(
'integer',
'integer'),
769 $answers[
$row[
"active_fi"]] = $row[
"value"];
808 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
819 $template->setCurrentBlock(
"textfield");
820 $template->setVariable(
"TEXTFIELD_VALUE",
"");
821 $template->parseCurrentBlock();
834 include_once
"./classes/class.ilTemplate.php";
835 $template =
new ilTemplate(
"tpl.il_svy_svy_precondition_select_value_textfield.html", TRUE, TRUE,
"Modules/Survey");
836 if (strlen($default))
838 $template->setCurrentBlock(
"textfield");
840 $template->parseCurrentBlock();
844 $template->touchBlock(
"textfield");
846 $template->setVariable(
"SELECT_VALUE", $lng->txt(
"step") .
" 3: " . $lng->txt(
"enter_value"));
847 return $template->get();
860 if (count($this->cumulated) == 0)
862 include_once
"./Modules/Survey/classes/class.ilObjSurvey.php";
867 foreach ($this->cumulated[
"values"] as
$key => $value)
869 foreach ($value as $key2 => $value2)
871 $this->cumulated[
"variables"][
$key][$key2] = utf8_decode($value2);
874 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyChart.php";
875 $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"]);
888 if (strlen($min) && strlen($max))
890 return "(" . $min .
" " . strtolower($this->lng->txt(
"to")) .
" " . $max .
")";
892 else if (strlen($min))
894 return "(>= " . $min .
")";
896 else if (strlen($max))
898 return "(<= " . $max .
")";