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(
$data[
"value2"],
"") == 0)) {
136 $this->maximum =
null;
138 $this->maximum = is_null(
$data[
"value2"]) ? null : (float)
$data[
"value2"];
143 parent::loadFromDb($question_id);
160 if ($affectedRows === 1) {
164 array($this->
getId())
168 array(
'integer',
'text'),
177 "DELETE FROM svy_variable WHERE question_fi = %s",
179 array($this->
getId())
182 if (preg_match(
"/[\D]/", $this->maximum) or (strcmp($this->maximum,
"∞") == 0)) {
187 $next_id =
$ilDB->nextId(
'svy_variable');
189 "INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, value2, sequence, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
190 array(
'integer',
'integer',
'integer',
'float',
'float',
'integer',
'integer'),
191 array($next_id, 0, $this->
getId(), $this->
getMinimum(), $max, 0, time())
194 return $affectedRows;
198 bool $a_include_header =
true
202 $this->
insertXML($a_xml_writer, $a_include_header);
203 $xml = $a_xml_writer->xmlDumpMem(
false);
204 if (!$a_include_header) {
205 $pos = strpos(
$xml,
"?>");
213 bool $a_include_header =
true
216 "id" => $this->
getId(),
217 "title" => $this->getTitle(),
218 "type" => $this->getQuestionType(),
219 "subtype" => $this->getSubtype(),
220 "obligatory" => $this->getObligatory()
224 $a_xml_writer->
xmlElement(
"description",
null, $this->getDescription());
225 $a_xml_writer->
xmlElement(
"author",
null, $this->getAuthor());
227 $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
228 $a_xml_writer->
xmlEndTag(
"questiontext");
231 switch ($this->getSubtype()) {
238 if ((
string) $this->getMinimum() !==
'') {
239 $attrs[
"min"] = $this->getMinimum();
241 if ((
string) $this->getMaximum() !==
'') {
242 $attrs[
"max"] = $this->getMaximum();
248 "format" =>
"integer"
250 if ((
string) $this->getMinimum() !==
'') {
251 $attrs[
"min"] = $this->getMinimum();
253 if ((
string) $this->getMaximum() !==
'') {
254 $attrs[
"max"] = $this->getMaximum();
258 $a_xml_writer->
xmlStartTag(
"response_num", $attrs);
259 $a_xml_writer->
xmlEndTag(
"response_num");
263 if (count($this->material) && preg_match(
264 "/il_(\d*?)_(\w+)_(\d+)/",
265 $this->material[
"internal_link"],
269 "label" => $this->material[
"title"]
272 $intlink =
"il_" .
IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
273 if (strcmp($matches[1],
"") !== 0) {
274 $intlink = $this->material[
"internal_link"];
276 $a_xml_writer->
xmlElement(
"mattext",
null, $intlink);
286 $result =
$ilDB->queryF(
287 "SELECT questiontype_id FROM svy_qtype WHERE type_tag = %s",
289 array($this->getQuestionType())
291 $row =
$ilDB->fetchAssoc($result);
292 return (
int) $row[
"questiontype_id"];
297 return "SurveyMetricQuestion";
302 return "svy_qst_metric";
307 $entered_value = $post_data[$this->
getId() .
"_metric_question"] ??
"";
309 if (strlen($entered_value)) {
310 $data[] = array(
"value" => $entered_value);
322 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
324 $entered_value = str_replace(
",",
".", $entered_value);
326 if ((!$this->getObligatory()) && (strlen($entered_value) == 0)) {
330 if (strlen($entered_value) == 0) {
331 return $this->
lng->txt(
"survey_question_obligatory");
334 if (strlen($this->getMinimum())) {
335 if ($entered_value < $this->getMinimum()) {
336 return $this->
lng->txt(
"metric_question_out_of_bounds");
340 if (strlen($this->getMaximum())) {
341 if (($this->getMaximum() == 1) && ($this->getMaximum() < $this->getMinimum())) {
343 } elseif ($entered_value > $this->getMaximum()) {
344 return $this->
lng->txt(
"metric_question_out_of_bounds");
348 if (!is_numeric($entered_value)) {
349 return $this->
lng->txt(
"metric_question_not_a_value");
352 if ($this->getSubtype() === self::SUBTYPE_RATIO_ABSOLUTE && ((
int) $entered_value != (
float) $entered_value)) {
353 return $this->
lng->txt(
"metric_question_floating_point");
361 bool $a_return =
false
365 $entered_value = $post_data[$this->
getId() .
"_metric_question"];
368 $entered_value = str_replace(
",",
".", $entered_value);
371 return array(array(
"value" => $entered_value,
"textanswer" =>
null));
374 if ($entered_value ===
'') {
378 $next_id =
$ilDB->nextId(
'svy_answer');
381 $fields[
'answer_id'] = array(
"integer", $next_id);
382 $fields[
'question_fi'] = array(
"integer", $this->
getId());
383 $fields[
'active_fi'] = array(
"integer", $active_id);
384 $fields[
'value'] = array(
"float", $entered_value);
385 $fields[
'textanswer'] = array(
"clob",
null);
386 $fields[
'tstamp'] = array(
"integer", time());
388 $ilDB->insert(
"svy_answer", $fields);
396 $this->setMinimum(
$data[
"min"]);
397 $this->setMaximum(
$data[
"max"]);
408 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
414 $template->setCurrentBlock(
"textfield");
439 $min = (string) $this->getMinimum();
440 $max = (string) $this->getMaximum();
441 if ($min !==
'' && $max !==
'') {
442 return "(" . $min .
" " . strtolower($this->
lng->txt(
"to")) .
" " . $max .
")";
443 } elseif ($min !==
'') {
444 return "(>= " . $min .
")";
445 } elseif ($max !==
'') {
446 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