39         $this->db = $DIC->database();
    40         $this->
lng = $DIC->language();
    51         $result = 
$ilDB->queryF(
    56         if ($result->numRows() === 1) {
    57             return $ilDB->fetchAssoc($result);
    67         $result = 
$ilDB->queryF(
    72         if ($result->numRows() === 1) {
    76             $this->label = (string) $data[
'label'];
    78             $this->
setObjId((
int) $data[
"obj_fi"]);
    79             $this->
setAuthor((
string) $data[
"author"]);
    80             $this->
setOwner((
int) $data[
"owner_fi"]);
    86             $this->use_min_answers = (bool) $data[
'use_min_answers'];
    87             $this->nr_min_answers = (string) $data[
'nr_min_answers'];
    88             $this->nr_max_answers = (string) $data[
'nr_max_answers'];
    90             $this->categories->flushCategories();
    91             $result = 
$ilDB->queryF(
    92                 "SELECT svy_variable.*, svy_category.title, svy_category.neutral FROM svy_variable, svy_category WHERE svy_variable.question_fi = %s AND svy_variable.category_fi = svy_category.category_id ORDER BY sequence ASC",
    96             if ($result->numRows() > 0) {
    97                 while ($data = 
$ilDB->fetchAssoc($result)) {
    98                     $this->categories->addCategory($data[
"title"], $data[
"other"], $data[
"neutral"], null, ($data[
'scale']) ?: ($data[
'sequence'] + 1));
   102         parent::loadFromDb($question_id);
   111             $this->categories->getCategoryCount()
   120         if ($affectedRows === 1) {
   124                 array($this->
getId())
   127                 "INSERT INTO " . $this->
getAdditionalTableName() . 
" (question_fi, orientation, use_min_answers, nr_min_answers, nr_max_answers) VALUES (%s, %s, %s, %s, %s)",
   128                 array(
'integer', 
'text', 
'integer', 
'integer', 
'integer'),
   132                     ($this->use_min_answers) ? 1 : 0,
   133                     ($this->nr_min_answers > 0) ? $this->nr_min_answers : null,
   134                     ($this->nr_max_answers > 0) ? $this->nr_max_answers : null
   140         return $affectedRows;
   147         $affectedRows = 
$ilDB->manipulateF(
   148             "DELETE FROM svy_variable WHERE question_fi = %s",
   150             array($this->
getId())
   153         for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
   154             $cat = $this->categories->getCategory($i);
   156             $next_id = 
$ilDB->nextId(
'svy_variable');
   157             $affectedRows = 
$ilDB->manipulateF(
   158                 "INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, other, sequence, scale, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
   159                 array(
'integer',
'integer',
'integer',
'float',
'integer',
'integer', 
'integer',
'integer'),
   160                 array($next_id, $category_id, $this->
getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
   167         bool $a_include_header = 
true,
   168         bool $obligatory_state = 
false   171         $a_xml_writer->xmlHeader();
   172         $this->
insertXML($a_xml_writer, $a_include_header);
   173         $xml = $a_xml_writer->xmlDumpMem(
false);
   174         if (!$a_include_header) {
   175             $pos = strpos($xml, 
"?>");
   176             $xml = substr($xml, $pos + 2);
   186         bool $a_include_header = 
true   189             "id" => $this->
getId(),
   198         if (strlen($this->label ?? 
"")) {
   200                 "label" => $this->label,
   205         $a_xml_writer->
xmlStartTag(
"questiontext", $attrs);
   207         $a_xml_writer->
xmlEndTag(
"questiontext");
   211         for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
   215             if (strlen($this->categories->getCategory($i)->other ?? 
"")) {
   216                 $attrs[
'other'] = $this->categories->getCategory($i)->other;
   218             if (strlen($this->categories->getCategory($i)->neutral ?? 
"")) {
   219                 $attrs[
'neutral'] = $this->categories->getCategory($i)->neutral;
   221             if (strlen($this->categories->getCategory($i)->label ?? 
"")) {
   222                 $attrs[
'label'] = $this->categories->getCategory($i)->label;
   224             if (strlen($this->categories->getCategory($i)->scale ?? 
"")) {
   225                 $attrs[
'scale'] = $this->categories->getCategory($i)->scale;
   227             $a_xml_writer->
xmlStartTag(
"response_multiple", $attrs);
   228             $this->
addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
   229             $a_xml_writer->
xmlEndTag(
"response_multiple");
   234         if (count($this->material)) {
   235             if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches)) {
   237                     "label" => $this->material[
"title"]
   240                 $intlink = 
"il_" . 
IL_INST_ID . 
"_" . $matches[2] . 
"_" . $matches[3];
   241                 if (strcmp($matches[1], 
"") !== 0) {
   242                     $intlink = $this->material[
"internal_link"];
   244                 $a_xml_writer->
xmlElement(
"mattext", null, $intlink);
   251         $a_xml_writer->
xmlElement(
"fieldlabel", null, 
"orientation");
   253         $a_xml_writer->
xmlEndTag(
"metadatafield");
   255         $a_xml_writer->
xmlElement(
"fieldlabel", null, 
"use_min_answers");
   256         $a_xml_writer->
xmlElement(
"fieldentry", null, $this->use_min_answers);
   257         $a_xml_writer->
xmlEndTag(
"metadatafield");
   259         $a_xml_writer->
xmlElement(
"fieldlabel", null, 
"nr_min_answers");
   260         $a_xml_writer->
xmlElement(
"fieldentry", null, $this->nr_min_answers);
   261         $a_xml_writer->
xmlEndTag(
"metadatafield");
   263         $a_xml_writer->
xmlElement(
"fieldlabel", null, 
"nr_max_answers");
   264         $a_xml_writer->
xmlElement(
"fieldentry", null, $this->nr_max_answers);
   265         $a_xml_writer->
xmlEndTag(
"metadatafield");
   273         return "SurveyMultipleChoiceQuestion";
   283         $entered_value = $post_data[$this->
getId() . 
"_value"] ?? 
"";
   285         if (is_array($entered_value)) {
   286             foreach ($entered_value as $idx => $value) {
   287                 $data[] = array(
"value" => $value,
   288                                 "textanswer" => $post_data[$this->
getId() . 
'_' . $value . 
'_other'] ?? 
""   292         for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
   293             $cat = $this->categories->getCategory($i);
   296                 if (!is_array($entered_value) || !in_array($i, $entered_value)) {
   297                     if (strlen($post_data[$this->
getId() . 
"_" . $i . 
"_other"] ?? 
"")) {
   298                         $data[] = array(
"value" => $i,
   299                                         "textanswer" => $post_data[$this->
getId() . 
'_' . $i . 
'_other'] ?? 
"",
   316         $entered_value = (array) ($post_data[$this->
getId() . 
"_value"] ?? []);
   317         if (!$this->
getObligatory() && (count($entered_value) === 0)) {
   321         if ($this->use_min_answers && $this->nr_min_answers > 0 && $this->nr_max_answers > 0 && $this->nr_min_answers == $this->nr_max_answers && count($entered_value) !== (
int) $this->nr_max_answers) {
   322             return sprintf($this->
lng->txt(
"err_no_exact_answers"), $this->nr_min_answers);
   324         if ($this->use_min_answers && $this->nr_min_answers > 0 && count($entered_value) < $this->nr_min_answers) {
   325             return sprintf($this->
lng->txt(
"err_no_min_answers"), $this->nr_min_answers);
   327         if ($this->use_min_answers && $this->nr_max_answers > 0 && count($entered_value) > $this->nr_max_answers) {
   328             return sprintf($this->
lng->txt(
"err_no_max_answers"), $this->nr_max_answers);
   330         if (count($entered_value) == 0) {
   331             return $this->
lng->txt(
"question_mr_not_checked");
   333         for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
   334             $cat = $this->categories->getCategory($i);
   336                 if (in_array($i, $entered_value)) {
   337                     if (array_key_exists($this->
getId() . 
"_" . $i . 
"_other", $post_data) && !strlen($post_data[$this->
getId() . 
"_" . $i . 
"_other"] ?? 
"")) {
   338                         return $this->
lng->txt(
"question_mr_no_other_answer");
   340                 } elseif (strlen($post_data[$this->
getId() . 
"_" . $i . 
"_other"] ?? 
"")) {
   341                     return $this->
lng->txt(
"question_mr_no_other_answer_checked");
   351         bool $a_return = 
false   356             $return_data = array();
   358         if (is_array($post_data[$this->
getId() . 
"_value"] ?? null)) {
   359             foreach ($post_data[$this->
getId() . 
"_value"] as $entered_value) {
   360                 if (strlen($entered_value ?? 
"") > 0) {
   362                         $next_id = 
$ilDB->nextId(
'svy_answer');
   366                         $fields[
'answer_id'] = array(
"integer", $next_id);
   367                         $fields[
'question_fi'] = array(
"integer", $this->
getId());
   368                         $fields[
'active_fi'] = array(
"integer", $active_id);
   369                         $fields[
'value'] = array(
"float", (strlen($entered_value ?? 
"")) ? $entered_value : null);
   370                         $fields[
'textanswer'] = array(
"clob", isset($post_data[$this->
getId() . 
"_" . $entered_value . 
"_other"]) ? $this->
stripSlashesAddSpaceFallback($post_data[$this->
getId() . 
"_" . $entered_value . 
"_other"]) : null);
   371                         $fields[
'tstamp'] = array(
"integer", time());
   373                         $affectedRows = 
$ilDB->insert(
"svy_answer", $fields);
   375                         $return_data[] = array(
"value" => $entered_value,
   376                                 "textanswer" => $post_data[$this->
getId() . 
"_" . $entered_value . 
"_other"] ?? 
"");
   389         foreach ($a_meta as $key => $value) {
   390             switch ($value[
"label"]) {
   394                 case "use_min_answers":
   395                     $this->use_min_answers = $value[
"entry"];
   397                 case "nr_min_answers":
   398                     $this->nr_min_answers = $value[
"entry"];
   400                 case "nr_max_answers":
   401                     $this->nr_max_answers = $value[
"entry"];
   412                 $categorytext .= $material[
"text"];
   414             $this->categories->addCategory(
   416                 strlen(
$data[
'other'] ?? 
"") ? 
$data[
'other'] : 0,
   417                 strlen($data[
'neutral'] ?? 
"") ? $data[
'neutral'] : 0,
   418                 strlen($data[
'label'] ?? 
"") ? $data[
'label'] : null,
   419                 strlen($data[
'scale'] ?? 
"") ? $data[
'scale'] : null
   431         return array(
"=", 
"<>");
   437         for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
   438             $category = $this->categories->getCategory($i);
   439             $options[$category->scale - 1] = $category->scale . 
" - " . $category->title;
   451         $step3->setOptions($options);
   452         $step3->setValue($default);
   460         $category = $this->categories->getCategoryForScale((
int) $value + 1);
   463         return $category->scale .
   465             ((strlen($category->title ?? 
"")) ? $category->title : $this->lng->txt(
'other_answer'));
   478         $db = $DIC->database();
   480             "SELECT SUM(scale) sum_sum_score FROM svy_svy_qst sq " .
   481             "JOIN svy_question q ON (sq.question_fi = q.question_id) " .
   482             "JOIN svy_variable v ON (v.question_fi = q.question_id) " .
   483             "WHERE sq.survey_fi  = %s AND q.questiontype_fi = %s ",
   484             [
"integer", 
"integer"],
   488         return (
int) $rec[
"sum_sum_score"];
 
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...
 
setQuestiontext(string $questiontext="")
 
saveCompletionStatus(int $original_id=0)
Saves the complete flag to the database. 
 
saveToDb(int $original_id=0)
 
insertXML(ilXmlWriter $a_xml_writer, bool $a_include_header=true)
Adds the question XML to a given XMLWriter object. 
 
setObligatory(bool $obligatory=true)
 
fetchAssoc(ilDBStatement $statement)
 
importAdditionalMetadata(array $a_meta)
 
setOriginalId(?int $original_id)
 
loadFromDb(int $question_id)
 
setComplete(bool $a_complete)
 
saveCategoryToDb(string $categorytext, int $neutral=0)
Saves a category to the database. 
 
__construct(string $title="", string $description="", string $author="", string $questiontext="", int $owner=-1, int $orientation=0)
 
stripSlashesAddSpaceFallback(string $a_str)
Strip slashes with add space fallback, see https://mantis.ilias.de/view.php?id=19727 and https://mant...
 
xmlEndTag(string $tag)
Writes an endtag. 
 
getWorkingDataFromUserInput(array $post_data)
 
setOrientation(int $orientation=0)
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
setAuthor(string $author="")
 
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...
 
toXML(bool $a_include_header=true, bool $obligatory_state=false)
 
getPreconditionSelectValue(string $default, string $title, string $variable)
 
getQuestionDataArray(int $id)
 
setTitle(string $title="")
 
queryF(string $query, array $types, array $values)
 
saveUserInput(array $post_data, int $active_id, bool $a_return=false)
 
static getMaxSumScore(int $survey_id)
 
__construct(Container $dic, ilPlugin $plugin)
 
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag. 
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
SurveyCategories $categories
 
getPreconditionValueOutput(string $value)
 
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content) 
 
setDescription(string $description="")
 
importResponses(array $a_data)
 
setObjId(int $obj_id=0)
Set the reference(?) id of the container object. 
 
checkUserInput(array $post_data, int $survey_id)