24include_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;
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",
248 $this->minimum =
$data[
"value1"];
249 if ((
$data[
"value2"] < 0) or (strcmp(
$data[
"value2"],
"") == 0))
255 $this->maximum =
$data[
"value2"];
260 parent::loadFromDb(
$id);
294 $affectedRows = parent::saveToDb($original_id);
295 if ($affectedRows == 1)
299 array($this->
getId())
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');
594 $fields[
'answer_id'] = array(
"integer", $next_id);
595 $fields[
'question_fi'] = array(
"integer", $this->
getId());
596 $fields[
'active_fi'] = array(
"integer", $active_id);
597 $fields[
'value'] = array(
"float", (strlen($entered_value)) ? $entered_value : NULL);
598 $fields[
'textanswer'] = array(
"clob", NULL);
599 $fields[
'tstamp'] = array(
"integer", time());
601 $affectedRows =
$ilDB->insert(
"svy_answer", $fields);
608 $question_id = $this->
getId();
610 $result_array = array();
613 $sql =
"SELECT svy_answer.* FROM svy_answer".
614 " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
615 " WHERE svy_answer.question_fi = ".$ilDB->quote($question_id,
"integer").
616 " AND svy_finished.survey_fi = ".$ilDB->quote(
$survey_id,
"integer");
619 $sql .=
" AND ".$ilDB->in(
"svy_finished.finished_id", $finished_ids,
"",
"integer");
630 $result_array[
"USERS_ANSWERED"] =
$result->numRows();
631 $result_array[
"USERS_SKIPPED"] = $nr_of_users -
$result->numRows();
635 $result_array[
"MODE_VALUE"] = key(
$cumulated);
640 foreach (
$cumulated as $value => $nr_of_users)
645 $percentage = (float)($nr_of_users/$numrows);
647 $result_array[
"values"][$counter++] = array(
"value" => $value,
"selected" => (
int)$nr_of_users,
"percentage" => $percentage);
654 $sum_part_zero =
false;
658 for ($i = 0; $i < $key; $i++)
660 array_push($median, $value);
665 $sum_part_zero =
true;
666 $x_i_inv += 1/$value;
674 $median_value = 0.5 * ($median[(
$total/2)-1] + $median[(
$total/2)]);
678 $median_value = $median[((
$total+1)/2)-1];
689 $result_array[
"ARITHMETIC_MEAN"] = $x_i/
$total;
693 $result_array[
"ARITHMETIC_MEAN"] = sprintf(
"%.2f", $x_i/
$total);
698 $result_array[
"ARITHMETIC_MEAN"] =
"";
700 $result_array[
"MEDIAN"] = $median_value;
701 $result_array[
"QUESTION_TYPE"] =
"SurveyMetricQuestion";
702 return $result_array;
716 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
717 $worksheet =& $workbook->addWorksheet();
719 switch ($export_label)
745 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_ANSWERED"]);
748 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_SKIPPED"]);
751 $worksheet->write($rowcounter, 0, $this->lng->txt(
"subtype"), $format_bold);
779 if (is_array($eval_data[
"values"]))
781 foreach ($eval_data[
"values"] as $key => $value)
799 if (count($resultset[
"answers"][$this->
getId()]))
801 foreach ($resultset[
"answers"][$this->
getId()] as $key => $answer)
803 array_push($a_array, $answer[
"value"]);
825 $sql =
"SELECT svy_answer.* FROM svy_answer".
826 " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
827 " WHERE svy_answer.question_fi = ".$ilDB->quote($this->
getId(),
"integer").
828 " AND svy_finished.survey_fi = ".$ilDB->quote(
$survey_id,
"integer");
831 $sql .=
" AND ".$ilDB->in(
"svy_finished.finished_id", $finished_ids,
"",
"integer");
837 $answers[
$row[
"active_fi"]] =
$row[
"value"];
876 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
887 $template->setCurrentBlock(
"textfield");
888 $template->setVariable(
"TEXTFIELD_VALUE",
"");
889 $template->parseCurrentBlock();
900 include_once
"./Services/Form/classes/class.ilNumberInputGUI.php";
902 $step3->setValue($default);
916 if (strlen($min) && strlen($max))
918 return "(" . $min .
" " . strtolower($this->lng->txt(
"to")) .
" " . $max .
")";
920 else if (strlen($min))
922 return "(>= " . $min .
")";
924 else if (strlen($max))
926 return "(<= " . $max .
")";
getQuestionType()
Returns the question type of the question.
& getUserAnswers($survey_id, $finished_ids)
Returns an array containing all answers to this question in a given survey.
saveToDb($original_id="")
Saves a SurveyMetricQuestion object to a database.
getQuestionTypeID()
Returns the question type ID of the question.
getSubtype()
Gets the question subtype.
setMaximum($maximum="")
Sets the maximum value.
outPreconditionSelectValue(&$template)
Creates a value selection for preconditions.
getPreconditionSelectValue($default="", $title, $variable)
Creates a form property for the precondition value.
SurveyMetricQuestion( $title="", $description="", $author="", $questiontext="", $owner=-1, $subtype=self::SUBTYPE_NON_RATIO)
SurveyMetricQuestion constructor.
addUserSpecificResultsData(&$a_array, &$resultset)
Adds the values for the user specific results export for a given user.
getAvailableRelations()
Returns the available relations for the question.
checkUserInput($post_data, $survey_id)
Checks the input of the active user for obligatory status and entered values.
const SUBTYPE_RATIO_NON_ABSOLUTE
getMinMaxText()
Creates a text for the input range of the metric question.
saveRandomData($active_id)
Saves random answers for a given active user in the database.
getMinimum()
Returns the minimum value of the question.
const SUBTYPE_RATIO_ABSOLUTE
getAdditionalTableName()
Returns the name of the additional question data table in the database.
saveUserInput($post_data, $active_id, $a_return=false)
& getCumulatedResults($survey_id, $nr_of_users, $finished_ids)
setSubtype($subtype=self::SUBTYPE_NON_RATIO)
Sets the question subtype.
insertXML(&$a_xml_writer, $a_include_header=TRUE, $obligatory_state="")
Adds the question XML to a given XMLWriter object.
isComplete()
Returns true if the question is complete for use.
getMaximum()
Returns the maximum value of the question.
toXML($a_include_header=TRUE, $obligatory_state="")
Returns an xml representation of the question.
loadFromDb($id)
Loads a SurveyMetricQuestion object from the database.
& getWorkingDataFromUserInput($post_data)
Creates the user data of the svy_answer table from the POST data.
setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
Creates an Excel worksheet for the detailed cumulated results of this question.
_getQuestionDataArray($id)
Returns the question data fields from the database.
importResponses($a_data)
Import response data from the question import file.
setMinimum($minimum=0)
Sets the minimum value.
usableForPrecondition()
Returns if the question is usable for preconditions.
Basic class for all survey question types.
setQuestiontext($questiontext="")
Sets the questiontext of the SurveyQuestion object.
setId($id=-1)
Sets the id of the SurveyQuestion object.
setAuthor($author="")
Sets the authors name of the SurveyQuestion object.
SurveyQuestion( $title="", $description="", $author="", $questiontext="", $owner=-1)
SurveyQuestion constructor The constructor takes possible arguments an creates an instance of the Sur...
getDescription()
Gets the description string of the SurveyQuestion object.
getId()
Gets the id of the SurveyQuestion object.
setDescription($description="")
Sets the description string of the SurveyQuestion object.
setObjId($obj_id=0)
Set the reference id of the container object.
getAuthor()
Gets the authors name of the SurveyQuestion object.
setOriginalId($original_id)
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getObligatory($survey_id="")
Gets the obligatory state of the question.
getTitle()
Gets the title string of the SurveyQuestion object.
setComplete($a_complete)
Sets the complete state of the question.
saveMaterial()
save material to db
setOwner($owner="")
Sets the creator/owner ID of the SurveyQuestion object.
setTitle($title="")
Sets the title string of the SurveyQuestion object.
$cumulated
An array containing the cumulated results of the question for a given survey.
addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag=TRUE, $add_mobs=TRUE, $a_attrs=null)
Creates an XML material tag from a plain text or xhtml text.
setObligatory($obligatory=1)
Sets the obligatory state of the question.
_convert_text($a_text, $a_target="has been removed")
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
xmlHeader()
Writes xml header @access public.