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) {
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
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(),
215 "type" => $this->getQuestionType(),
216 "subtype" => $this->getSubtype(),
217 "obligatory" => $this->getObligatory()
221 $a_xml_writer->
xmlElement(
"description",
null, $this->getDescription());
222 $a_xml_writer->
xmlElement(
"author",
null, $this->getAuthor());
224 $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
225 $a_xml_writer->
xmlEndTag(
"questiontext");
228 switch ($this->getSubtype()) {
235 if ((
string) $this->getMinimum() !==
'') {
236 $attrs[
"min"] = $this->getMinimum();
238 if ((
string) $this->getMaximum() !==
'') {
239 $attrs[
"max"] = $this->getMaximum();
245 "format" =>
"integer"
247 if ((
string) $this->getMinimum() !==
'') {
248 $attrs[
"min"] = $this->getMinimum();
250 if ((
string) $this->getMaximum() !==
'') {
251 $attrs[
"max"] = $this->getMaximum();
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"];
273 $a_xml_writer->
xmlElement(
"mattext",
null, $intlink);
283 $result =
$ilDB->queryF(
284 "SELECT questiontype_id FROM svy_qtype WHERE type_tag = %s",
286 array($this->getQuestionType())
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");
335 if (strlen($this->getMinimum() ??
"")) {
336 if ($entered_value < $this->getMinimum()) {
337 return $this->
lng->txt(
"metric_question_out_of_bounds");
341 if (strlen($this->getMaximum() ??
"")) {
342 if (($this->getMaximum() == 1) && ($this->getMaximum() < $this->getMinimum())) {
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);
397 $this->setMinimum(
$data[
"min"]);
398 $this->setMaximum(
$data[
"max"]);
409 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
415 $template->setCurrentBlock(
"textfield");
440 $min = (string) $this->getMinimum();
441 $max = (string) $this->getMaximum();
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 .
")";
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
setVariable($variable, $value='')
Sets a variable value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
loadFromDb(int $question_id)
load question data into object note: this base implementation only loads the material data
getAvailableRelations()
Returns the available relations for the question.
const SUBTYPE_RATIO_NON_ABSOLUTE
getMinMaxText()
Creates a text for the input range of the metric question.
const SUBTYPE_RATIO_ABSOLUTE
saveUserInput(array $post_data, int $active_id, bool $a_return=false)
getQuestionDataArray(int $id)
Returns the question data.
checkUserInput(array $post_data, int $survey_id)
setMaximum(?float $maximum=null)
__construct(string $title="", string $description="", string $author="", string $questiontext="", int $owner=-1, int $subtype=self::SUBTYPE_NON_RATIO)
setSubtype(int $a_subtype=self::SUBTYPE_NON_RATIO)
toXML(bool $a_include_header=true)
saveToDb(int $original_id=0)
Saves a SurveyQuestion object to a database.
getWorkingDataFromUserInput(array $post_data)
Creates the user data of the svy_answer table from the POST data.
insertXML(ilXmlWriter $a_xml_writer, bool $a_include_header=true)
getPreconditionSelectValue(string $default, string $title, string $variable)
Creates a form property for the precondition value.
importResponses(array $a_data)
Import response data from the question import file.
outPreconditionSelectValue(ilTemplate $template)
setMinimum(?float $minimum=null)
usableForPrecondition()
Returns if the question is usable for preconditions.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTitle(string $title="")
setQuestiontext(string $questiontext="")
setDescription(string $description="")
setObjId(int $obj_id=0)
Set the reference(?) id of the container object.
setComplete(bool $a_complete)
setOriginalId(?int $original_id)
setObligatory(bool $obligatory=true)
setAuthor(string $author="")
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...
special template class to simplify handling of ITX/PEAR
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlHeader()
Writes xml header.
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc