42 int $subtype = self::SUBTYPE_NON_RATIO
46 $this->db = $DIC->database();
50 $this->minimum =
null;
51 $this->maximum =
null;
54 public function setSubtype(
int $a_subtype = self::SUBTYPE_NON_RATIO): void
56 $this->subtype = $a_subtype;
76 if (is_null($this->minimum) && $this->
getSubtype() > 3) {
91 $result =
$ilDB->queryF(
96 if ($result->numRows() === 1) {
97 return $ilDB->fetchAssoc($result);
107 $result =
$ilDB->queryF(
112 if ($result->numRows() === 1) {
115 $this->
setTitle((
string) $data[
"title"]);
117 $this->
setObjId((
int) $data[
"obj_fi"]);
118 $this->
setAuthor((
string) $data[
"author"]);
119 $this->
setOwner((
int) $data[
"owner_fi"]);
120 $this->label = (string) $data[
'label'];
127 $result =
$ilDB->queryF(
128 "SELECT svy_variable.* FROM svy_variable WHERE svy_variable.question_fi = %s",
132 if ($result->numRows() > 0) {
133 if ($data =
$ilDB->fetchAssoc($result)) {
134 $this->minimum = is_null($data[
"value1"]) ?
null : (float) $data[
"value1"];
135 if (($data[
"value2"] < 0) or (strcmp((
string) $data[
"value2"],
"") == 0)) {
136 $this->maximum =
null;
138 $this->maximum = is_null($data[
"value2"] ??
null) ?
null : (float) $data[
"value2"];
143 parent::loadFromDb($question_id);
160 if ($affectedRows === 1) {
164 array($this->
getId())
168 array(
'integer',
'text'),
174 "DELETE FROM svy_variable WHERE question_fi = %s",
176 array($this->
getId())
179 if (preg_match(
"/[\D]/", $this->maximum) or (strcmp($this->maximum,
"∞") == 0)) {
184 $next_id =
$ilDB->nextId(
'svy_variable');
186 "INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, value2, sequence, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
187 array(
'integer',
'integer',
'integer',
'float',
'float',
'integer',
'integer'),
188 array($next_id, 0, $this->
getId(), $this->
getMinimum(), $max, 0, time())
191 return $affectedRows;
195 bool $a_include_header =
true 198 $a_xml_writer->xmlHeader();
199 $this->
insertXML($a_xml_writer, $a_include_header);
200 $xml = $a_xml_writer->xmlDumpMem(
false);
201 if (!$a_include_header) {
202 $pos = strpos($xml,
"?>");
203 $xml = substr($xml, $pos + 2);
210 bool $a_include_header =
true 213 "id" => $this->
getId(),
225 $a_xml_writer->
xmlEndTag(
"questiontext");
245 "format" =>
"integer" 255 $a_xml_writer->
xmlStartTag(
"response_num", $attrs);
256 $a_xml_writer->
xmlEndTag(
"response_num");
260 if (count($this->material) && preg_match(
261 "/il_(\d*?)_(\w+)_(\d+)/",
262 $this->material[
"internal_link"],
266 "label" => $this->material[
"title"]
269 $intlink =
"il_" .
IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
270 if (strcmp($matches[1],
"") !== 0) {
271 $intlink = $this->material[
"internal_link"];
283 $result =
$ilDB->queryF(
284 "SELECT questiontype_id FROM svy_qtype WHERE type_tag = %s",
288 $row =
$ilDB->fetchAssoc($result);
289 return (
int) $row[
"questiontype_id"];
294 return "SurveyMetricQuestion";
299 return "svy_qst_metric";
304 $entered_value = $post_data[$this->
getId() .
"_metric_question"] ??
"";
306 if (strlen($entered_value ??
"")) {
307 $data[] = array(
"value" => $entered_value);
319 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
321 $entered_value = str_replace(
",",
".", $entered_value);
323 if ((!$this->
getObligatory()) && (strlen($entered_value ??
"") == 0)) {
327 if (strlen($entered_value ??
"") == 0) {
328 return $this->
lng->txt(
"survey_question_obligatory");
331 if (!is_numeric(trim($entered_value))) {
332 return $this->
lng->txt(
"metric_question_not_a_value");
337 return $this->
lng->txt(
"metric_question_out_of_bounds");
344 } elseif ($entered_value > $this->
getMaximum()) {
345 return $this->
lng->txt(
"metric_question_out_of_bounds");
349 if (!is_numeric($entered_value)) {
350 return $this->
lng->txt(
"metric_question_not_a_value");
353 if ($this->
getSubtype() === self::SUBTYPE_RATIO_ABSOLUTE && ((
int) $entered_value != (
float) $entered_value)) {
354 return $this->
lng->txt(
"metric_question_floating_point");
362 bool $a_return =
false 366 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
369 $entered_value = str_replace(
",",
".", $entered_value);
372 return array(array(
"value" => $entered_value,
"textanswer" =>
null));
375 if ($entered_value ===
'') {
379 $next_id =
$ilDB->nextId(
'svy_answer');
382 $fields[
'answer_id'] = array(
"integer", $next_id);
383 $fields[
'question_fi'] = array(
"integer", $this->
getId());
384 $fields[
'active_fi'] = array(
"integer", $active_id);
385 $fields[
'value'] = array(
"float", $entered_value);
386 $fields[
'textanswer'] = array(
"clob",
null);
387 $fields[
'tstamp'] = array(
"integer", time());
389 $ilDB->insert(
"svy_answer", $fields);
409 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
431 $step3->setValue($default);
442 if ($min !==
'' && $max !==
'') {
443 return "(" . $min .
" " . strtolower($this->
lng->txt(
"to")) .
" " . $max .
")";
444 } elseif ($min !==
'') {
445 return "(>= " . $min .
")";
446 } elseif ($max !==
'') {
447 return "(<= " . $max .
")";
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setQuestiontext(string $questiontext="")
const SUBTYPE_RATIO_NON_ABSOLUTE
toXML(bool $a_include_header=true)
__construct(string $title="", string $description="", string $author="", string $questiontext="", int $owner=-1, int $subtype=self::SUBTYPE_NON_RATIO)
setObligatory(bool $obligatory=true)
loadFromDb(int $question_id)
setOriginalId(?int $original_id)
setMaximum(?float $maximum=null)
importResponses(array $a_data)
setComplete(bool $a_complete)
getQuestionDataArray(int $id)
checkUserInput(array $post_data, int $survey_id)
xmlEndTag(string $tag)
Writes an endtag.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setAuthor(string $author="")
setVariable($variable, $value='')
Sets a variable value.
addMaterialTag(ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true, ?array $a_attrs=null)
Creates an XML material tag from a plain text or xhtml text.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
saveToDb(int $original_id=0)
setTitle(string $title="")
setMinimum(?float $minimum=null)
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
saveUserInput(array $post_data, int $active_id, bool $a_return=false)
outPreconditionSelectValue(ilTemplate $template)
const SUBTYPE_RATIO_ABSOLUTE
__construct(Container $dic, ilPlugin $plugin)
getMinMaxText()
Creates a text for the input range of the metric question.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
setSubtype(int $a_subtype=self::SUBTYPE_NON_RATIO)
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
getWorkingDataFromUserInput(array $post_data)
setDescription(string $description="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getPreconditionSelectValue(string $default, string $title, string $variable)
Creates a form property for the precondition value.
setObjId(int $obj_id=0)
Set the reference(?) id of the container object.
insertXML(ilXmlWriter $a_xml_writer, bool $a_include_header=true)