24 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
83 $subtype = self::SUBTYPE_NON_RATIO
113 if($minimum !== NULL)
115 $minimum = (float)$minimum;
133 if($maximum !== NULL)
135 $maximum = (float)$maximum;
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);
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)
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"];
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 .
")";
getQuestionTypeID()
Returns the question type ID of the question.
_getQuestionDataArray($id)
Returns the question data fields from the database.
outPreconditionSelectValue(&$template)
Creates a value selection for preconditions.
const SUBTYPE_RATIO_NON_ABSOLUTE
addUserSpecificResultsData(&$a_array, &$resultset)
Adds the values for the user specific results export for a given user.
getAuthor()
Gets the authors name of the SurveyQuestion object.
$cumulated
An array containing the cumulated results of the question for a given survey.
& getUserAnswers($survey_id, $finished_ids)
Returns an array containing all answers to this question in a given survey.
getTitle()
Gets the title string of the SurveyQuestion object.
getObligatory($survey_id="")
Gets the obligatory state of the question.
setSubtype($subtype=self::SUBTYPE_NON_RATIO)
Sets the question subtype.
getMaximum()
Returns the maximum value of the question.
setObligatory($obligatory=1)
Sets the obligatory state of the question.
_convert_text($a_text, $a_target="has been removed")
setId($id=-1)
Sets the id of the SurveyQuestion object.
saveRandomData($active_id)
Saves random answers for a given active user in the database.
getAvailableRelations()
Returns the available relations for the question.
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getSubtype()
Gets the question subtype.
setOwner($owner="")
Sets the creator/owner ID of the SurveyQuestion object.
isComplete()
Returns true if the question is complete for use.
setComplete($a_complete)
Sets the complete state of the question.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setMinimum($minimum=0)
Sets the minimum value.
loadFromDb($id)
Loads a SurveyMetricQuestion object from the database.
setOriginalId($original_id)
fetchAssoc($a_set)
Fetch row as associative array from result set.
SurveyQuestion( $title="", $description="", $author="", $questiontext="", $owner=-1)
SurveyQuestion constructor The constructor takes possible arguments an creates an instance of the Sur...
setQuestiontext($questiontext="")
Sets the questiontext of the SurveyQuestion object.
getId()
Gets the id of the SurveyQuestion object.
getMinimum()
Returns the minimum value of the question.
setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
Creates an Excel worksheet for the detailed cumulated results of this question.
saveToDb($original_id="")
Saves a SurveyMetricQuestion object to a database.
importResponses($a_data)
Import response data from the question import file.
& getCumulatedResults($survey_id, $nr_of_users, $finished_ids)
Basic class for all survey question types.
saveMaterial()
save material to db
insertXML(&$a_xml_writer, $a_include_header=TRUE, $obligatory_state="")
Adds the question XML to a given XMLWriter object.
xmlHeader()
Writes xml header public.
toXML($a_include_header=TRUE, $obligatory_state="")
Returns an xml representation of the question.
usableForPrecondition()
Returns if the question is usable for preconditions.
getQuestionType()
Returns the question type of the question.
saveUserInput($post_data, $active_id, $a_return=false)
static _replaceMediaObjectImageSrc($a_text, $a_direction=0)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
setAuthor($author="")
Sets the authors name of the SurveyQuestion object.
const SUBTYPE_RATIO_ABSOLUTE
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.
setDescription($description="")
Sets the description string of the SurveyQuestion object.
checkUserInput($post_data, $survey_id)
Checks the input of the active user for obligatory status and entered values.
getMinMaxText()
Creates a text for the input range of the metric question.
getPreconditionSelectValue($default="", $title, $variable)
Creates a form property for the precondition value.
getDescription()
Gets the description string of the SurveyQuestion object.
setObjId($obj_id=0)
Set the reference id of the container object.
setMaximum($maximum="")
Sets the maximum value.
& getWorkingDataFromUserInput($post_data)
Creates the user data of the svy_answer table from the POST data.
setTitle($title="")
Sets the title string of the SurveyQuestion object.
SurveyMetricQuestion( $title="", $description="", $author="", $questiontext="", $owner=-1, $subtype=self::SUBTYPE_NON_RATIO)
SurveyMetricQuestion constructor.