ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
SurveyMultipleChoiceQuestion Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for SurveyMultipleChoiceQuestion:
+ Collaboration diagram for SurveyMultipleChoiceQuestion:

Public Member Functions

 __construct (string $title="", string $description="", string $author="", string $questiontext="", int $owner=-1, int $orientation=0)
 
 getQuestionDataArray (int $id)
 Returns the question data. More...
 
 loadFromDb (int $question_id)
 load question data into object note: this base implementation only loads the material data More...
 
 isComplete ()
 
 saveToDb (int $original_id=0)
 Saves a SurveyQuestion object to a database. More...
 
 saveCategoriesToDb ()
 
 toXML (bool $a_include_header=true, bool $obligatory_state=false)
 
 insertXML (ilXmlWriter $a_xml_writer, bool $a_include_header=true)
 Adds the question XML to a given XMLWriter object. More...
 
 getQuestionType ()
 
 getAdditionalTableName ()
 
 getWorkingDataFromUserInput (array $post_data)
 Creates the user data of the svy_answer table from the POST data. More...
 
 checkUserInput (array $post_data, int $survey_id)
 
 saveUserInput (array $post_data, int $active_id, bool $a_return=false)
 
 importAdditionalMetadata (array $a_meta)
 Import additional meta data from the question import file. More...
 
 importResponses (array $a_data)
 Import response data from the question import file. More...
 
 usableForPrecondition ()
 Returns if the question is usable for preconditions. More...
 
 getAvailableRelations ()
 Returns the available relations for the question. More...
 
 getPreconditionOptions ()
 Returns the options for preconditions. More...
 
 getPreconditionSelectValue (string $default, string $title, string $variable)
 Creates a form property for the precondition value. More...
 
 getPreconditionValueOutput (string $value)
 Returns the output for a precondition value. More...
 
 getCategories ()
 
- Public Member Functions inherited from SurveyQuestion
 __construct (string $title="", string $description="", string $author="", string $questiontext="", int $owner=-1)
 
 setComplete (bool $a_complete)
 
 isComplete ()
 
 questionTitleExists (string $title, int $questionpool_object=0)
 
 setTitle (string $title="")
 
 setObligatory (bool $obligatory=true)
 
 setOrientation (int $orientation=0)
 
 setId (int $id=-1)
 
 setSurveyId (int $id=-1)
 
 setDescription (string $description="")
 
 addMaterials (string $materials_file, string $materials_name="")
 
 setMaterialsfile (string $materials_filename, string $materials_tempfilename="", string $materials_name="")
 Uploads and adds a material. More...
 
 deleteMaterial (string $materials_name="")
 
 flushMaterials ()
 Deletes all materials uris. More...
 
 setAuthor (string $author="")
 
 setQuestiontext (string $questiontext="")
 
 setOwner (int $owner=0)
 
 getTitle ()
 
 getLabel ()
 
 getId ()
 
 getObligatory ()
 
 getSurveyId ()
 
 getOrientation ()
 
 getDescription ()
 
 getAuthor ()
 
 getOwner ()
 
 getQuestiontext ()
 
 getObjId ()
 Get the reference(?) id of the container object. More...
 
 setObjId (int $obj_id=0)
 Set the reference(?) id of the container object. More...
 
 duplicate (bool $for_survey=true, string $title="", string $author="", int $owner=0, int $a_survey_id=0)
 
 copyObject (int $target_questionpool, string $title="")
 
 copyXHTMLMediaObjectsOfQuestion (int $a_q_id)
 Copy media object usages from other question. More...
 
 loadFromDb (int $question_id)
 load question data into object note: this base implementation only loads the material data More...
 
 saveCompletionStatus (int $original_id=0)
 Saves the complete flag to the database. More...
 
 saveToDb (int $original_id=0)
 Saves a SurveyQuestion object to a database. More...
 
 createNewQuestion ()
 Creates a new question with a 0 timestamp when a new question is created This assures that an ID is given to the question if a file upload or something else occurs. More...
 
 getImagePath ()
 Returns the image path for web accessible images of a question. More...
 
 getMaterialsPath ()
 Returns the materials path for web accessible materials of a question. More...
 
 getImagePathWeb ()
 Returns the web image path for web accessible images of a question. More...
 
 getMaterialsPathWeb ()
 Returns the web image path for web accessable images of a question. More...
 
 saveCategoryToDb (string $categorytext, int $neutral=0)
 Saves a category to the database. More...
 
 deleteAdditionalTableData (int $question_id)
 Deletes datasets from the additional question table in the database. More...
 
 delete (int $question_id)
 Deletes a question and all materials from the database. More...
 
 syncWithOriginal ()
 
 getQuestionTypeID ()
 
 getQuestionType ()
 
 isHTML (string $a_text)
 
 QTIMaterialToString (ilQTIMaterial $a_material)
 Reads an QTI material tag an creates a text string. More...
 
 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. More...
 
 prepareTextareaOutput (string $txt_output, bool $prepare_for_latex_output=false)
 Prepares string for a text area output in surveys. More...
 
 getQuestionDataArray (int $id)
 Returns the question data. More...
 
 getWorkingDataFromUserInput (array $post_data)
 Creates the user data of the svy_answer table from the POST data. More...
 
 importAdditionalMetadata (array $a_meta)
 Import additional meta data from the question import file. More...
 
 importResponses (array $a_data)
 Import response data from the question import file. More...
 
 importAdjectives (array $a_data)
 Import bipolar adjectives from the question import file. More...
 
 importMatrix (array $a_data)
 Import matrix rows from the question import file. More...
 
 usableForPrecondition ()
 Returns if the question is usable for preconditions. More...
 
 getAvailableRelations ()
 Returns the available relations for the question. More...
 
 getPreconditionOptions ()
 Returns the options for preconditions. More...
 
 getPreconditionValueOutput (string $value)
 Returns the output for a precondition value. More...
 
 getPreconditionSelectValue (string $default, string $title, string $variable)
 Creates a form property for the precondition value. More...
 
 setOriginalId (?int $original_id)
 
 getOriginalId ()
 
 getMaterial ()
 
 setSubtype (int $a_subtype)
 
 getSubtype ()
 
 __get (string $value)
 
 __set (string $key, mixed $value)
 
 getCopyIds (bool $a_group_by_survey=false)
 
 hasCopies ()
 
 stripSlashesAddSpaceFallback (string $a_str)
 Strip slashes with add space fallback, see https://mantis.ilias.de/view.php?id=19727 and https://mantis.ilias.de/view.php?id=24200. More...
 

Static Public Member Functions

static getMaxSumScore (int $survey_id)
 Get max sum score for specific survey (and this question type) More...
 
- Static Public Member Functions inherited from SurveyQuestion
static _isComplete (int $question_id)
 Checks whether the question is complete or not. More...
 
static _getQuestionType (int $question_id)
 Returns the question type of a question with a given id. More...
 
static _getTitle (int $question_id)
 Returns the question title of a question with a given id. More...
 
static _getOriginalId (int $question_id, bool $a_return_question_id_if_no_original=true)
 Returns the original id of a question. More...
 
static _questionExists (int $question_id)
 
static _resolveInternalLink (string $internal_link)
 
static _resolveIntLinks (int $question_id)
 
static _getInternalLinkHref (string $target="", ?int $a_parent_ref_id=null)
 
static _isWriteable (int $question_id, int $user_id)
 is question writeable by a certain user More...
 
static _includeClass (string $question_type, int $gui=0)
 Include the php class file for a given question type. More...
 
static _getQuestionTypeName (string $type_tag)
 Return the translation for a given question type. More...
 
static _instanciateQuestion (int $question_id)
 Get question object. More...
 
static _instanciateQuestionGUI (int $question_id)
 Get question gui object. More...
 
static _instanciateQuestionEvaluation (int $question_id, ?array $a_finished_ids=null)
 
static _changeOriginalId (int $a_question_id, int $a_original_id, int $a_object_id)
 Change original id of existing question in db. More...
 
static _lookupSurveyObjId (int $a_question_id)
 
static lookupObjFi (int $a_qid)
 
static getMaxSumScore (int $survey_id)
 Get max sum score for specific survey (and this question type) More...
 

Data Fields

SurveyCategories $categories
 
- Data Fields inherited from SurveyQuestion
int $id
 
string $title
 
string $description
 
int $owner
 
string $author
 
array $materials
 
int $survey_id
 
int $obj_id
 
string $questiontext
 
bool $obligatory
 
ilLanguage $lng
 
int $orientation
 
array $material
 
bool $complete
 

Additional Inherited Members

- Protected Attributes inherited from SurveyQuestion
int $original_id
 
ILIAS SurveyQuestionPool Editing EditSessionRepository $edit_manager
 
ilObjUser $user
 
ilDBInterface $db
 
array $cumulated
 
ilLogger $log
 
ILIAS SurveyQuestionPool Export ImportSessionRepository $import_manager
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning MultipleChoice survey question The SurveyMultipleChoiceQuestion class defines and encapsulates basic methods and attributes for multiple choice survey question types.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m

Definition at line 27 of file class.SurveyMultipleChoiceQuestion.php.

Constructor & Destructor Documentation

◆ __construct()

SurveyMultipleChoiceQuestion::__construct ( string  $title = "",
string  $description = "",
string  $author = "",
string  $questiontext = "",
int  $owner = -1,
int  $orientation = 0 
)

Definition at line 31 of file class.SurveyMultipleChoiceQuestion.php.

38 {
39 global $DIC;
40
41 $this->db = $DIC->database();
42 $this->lng = $DIC->language();
44
45 $this->orientation = $orientation;
46 $this->categories = new SurveyCategories();
47 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26

References SurveyQuestion\$author, SurveyQuestion\$description, $DIC, SurveyQuestion\$orientation, SurveyQuestion\$owner, SurveyQuestion\$questiontext, SurveyQuestion\$title, ILIAS\GlobalScreen\Provider\__construct(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Member Function Documentation

◆ checkUserInput()

SurveyMultipleChoiceQuestion::checkUserInput ( array  $post_data,
int  $survey_id 
)
Returns
string Empty string if the input is ok, an error message otherwise

Definition at line 320 of file class.SurveyMultipleChoiceQuestion.php.

323 : string {
324 $entered_value = (array) ($post_data[$this->getId() . "_value"] ?? []);
325 if (!$this->getObligatory() && (count($entered_value) === 0)) {
326 return "";
327 }
328
329 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) {
330 return sprintf($this->lng->txt("err_no_exact_answers"), $this->nr_min_answers);
331 }
332 if ($this->use_min_answers && $this->nr_min_answers > 0 && count($entered_value) < $this->nr_min_answers) {
333 return sprintf($this->lng->txt("err_no_min_answers"), $this->nr_min_answers);
334 }
335 if ($this->use_min_answers && $this->nr_max_answers > 0 && count($entered_value) > $this->nr_max_answers) {
336 return sprintf($this->lng->txt("err_no_max_answers"), $this->nr_max_answers);
337 }
338 if (count($entered_value) == 0) {
339 return $this->lng->txt("question_mr_not_checked");
340 }
341 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
342 $cat = $this->categories->getCategory($i);
343 if ($cat->other) {
344 if (in_array($i, $entered_value)) {
345 if (array_key_exists($this->getId() . "_" . $i . "_other", $post_data) && !strlen((string) ($post_data[$this->getId() . "_" . $i . "_other"] ?? ""))) {
346 return $this->lng->txt("question_mr_no_other_answer");
347 }
348 } elseif (strlen((string) ($post_data[$this->getId() . "_" . $i . "_other"] ?? ""))) {
349 return $this->lng->txt("question_mr_no_other_answer_checked");
350 }
351 }
352 }
353 return "";
354 }

◆ getAdditionalTableName()

SurveyMultipleChoiceQuestion::getAdditionalTableName ( )

Definition at line 284 of file class.SurveyMultipleChoiceQuestion.php.

284 : string
285 {
286 return "svy_qst_mc";
287 }

Referenced by getQuestionDataArray(), loadFromDb(), and saveToDb().

+ Here is the caller graph for this function:

◆ getAvailableRelations()

SurveyMultipleChoiceQuestion::getAvailableRelations ( )

Returns the available relations for the question.

Reimplemented from SurveyQuestion.

Definition at line 437 of file class.SurveyMultipleChoiceQuestion.php.

437 : array
438 {
439 return array("=", "<>");
440 }

◆ getCategories()

SurveyMultipleChoiceQuestion::getCategories ( )

Definition at line 483 of file class.SurveyMultipleChoiceQuestion.php.

◆ getMaxSumScore()

static SurveyMultipleChoiceQuestion::getMaxSumScore ( int  $survey_id)
static

Get max sum score for specific survey (and this question type)

Reimplemented from SurveyQuestion.

Definition at line 488 of file class.SurveyMultipleChoiceQuestion.php.

488 : int
489 {
490 global $DIC;
491
492 // we need sum of scale values of multiple choice questions (type 1)
493 $db = $DIC->database();
494 $set = $db->queryF(
495 "SELECT SUM(scale) sum_sum_score FROM svy_svy_qst sq " .
496 "JOIN svy_question q ON (sq.question_fi = q.question_id) " .
497 "JOIN svy_variable v ON (v.question_fi = q.question_id) " .
498 "WHERE sq.survey_fi = %s AND q.questiontype_fi = %s ",
499 ["integer", "integer"],
500 [$survey_id, 1]
501 );
502 $rec = $db->fetchAssoc($set);
503 return (int) $rec["sum_sum_score"];
504 }
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)

References $DIC.

◆ getPreconditionOptions()

SurveyMultipleChoiceQuestion::getPreconditionOptions ( )

Returns the options for preconditions.

Reimplemented from SurveyQuestion.

Definition at line 442 of file class.SurveyMultipleChoiceQuestion.php.

442 : array
443 {
444 $options = array();
445 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
446 $category = $this->categories->getCategory($i);
447 $options[$category->scale - 1] = $category->scale . " - " . $category->title;
448 }
449 return $options;
450 }

References ILIAS\UI\Implementation\Component\Input\Field\$options.

◆ getPreconditionSelectValue()

SurveyMultipleChoiceQuestion::getPreconditionSelectValue ( string  $default,
string  $title,
string  $variable 
)

Creates a form property for the precondition value.

Reimplemented from SurveyQuestion.

Definition at line 452 of file class.SurveyMultipleChoiceQuestion.php.

457 $step3 = new ilSelectInputGUI($title, $variable);
459 $step3->setOptions($options);
460 $step3->setValue($default);
461 return $step3;
462 }
getPreconditionOptions()
Returns the options for preconditions.
This class represents a property in a property form.
This class represents a selection list property in a property form.

◆ getPreconditionValueOutput()

SurveyMultipleChoiceQuestion::getPreconditionValueOutput ( string  $value)

Returns the output for a precondition value.

Parameters
string$valueThe precondition value
Returns
string The output of the precondition value

Reimplemented from SurveyQuestion.

Definition at line 464 of file class.SurveyMultipleChoiceQuestion.php.

466 : string {
467 // #18136
468 $category = $this->categories->getCategoryForScale((int) $value + 1);
469
470 $scale = "";
471 $title = "";
472 if ($category) {
473 $scale = $category->scale;
474 $title = $category->title;
475 }
476
477 // #17895 - see getPreconditionOptions()
478 return $scale .
479 " - " .
480 ((strlen($title)) ? $title : $this->lng->txt('other_answer'));
481 }

◆ getQuestionDataArray()

SurveyMultipleChoiceQuestion::getQuestionDataArray ( int  $id)

Returns the question data.

Reimplemented from SurveyQuestion.

Definition at line 49 of file class.SurveyMultipleChoiceQuestion.php.

49 : array
50 {
52
53 $result = $ilDB->queryF(
54 "SELECT svy_question.*, " . $this->getAdditionalTableName() . ".* FROM svy_question, " . $this->getAdditionalTableName() . " WHERE svy_question.question_id = %s AND svy_question.question_id = " . $this->getAdditionalTableName() . ".question_fi",
55 array('integer'),
56 array($id)
57 );
58 if ($result->numRows() === 1) {
59 return $ilDB->fetchAssoc($result);
60 }
61
62 return array();
63 }

References SurveyQuestion\$db, SurveyQuestion\$id, $ilDB, and getAdditionalTableName().

+ Here is the call graph for this function:

◆ getQuestionType()

SurveyMultipleChoiceQuestion::getQuestionType ( )

Reimplemented from SurveyQuestion.

Definition at line 279 of file class.SurveyMultipleChoiceQuestion.php.

279 : string
280 {
281 return "SurveyMultipleChoiceQuestion";
282 }

◆ getWorkingDataFromUserInput()

SurveyMultipleChoiceQuestion::getWorkingDataFromUserInput ( array  $post_data)

Creates the user data of the svy_answer table from the POST data.

Returns
array User data according to the svy_answer table

Reimplemented from SurveyQuestion.

Definition at line 289 of file class.SurveyMultipleChoiceQuestion.php.

289 : array
290 {
291 $entered_value = $post_data[$this->getId() . "_value"] ?? [];
292 $entered_value = is_array($entered_value) ? $entered_value : [];
293 $data = array();
294 foreach ($entered_value as $value) {
295 $value = (string) $value;
296 $data[] = array("value" => $value,
297 "textanswer" => (string) ($post_data[$this->getId() . '_' . $value . '_other'] ?? "")
298 );
299 }
300 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
301 $cat = $this->categories->getCategory($i);
302 if ($cat->other) {
303 // #18212
304 if (!in_array((string) $i, array_map('strval', $entered_value), true)) {
305 if (strlen((string) ($post_data[$this->getId() . "_" . $i . "_other"] ?? ""))) {
306 $data[] = array("value" => $i,
307 "textanswer" => (string) ($post_data[$this->getId() . '_' . $i . '_other'] ?? ""),
308 "uncheck" => true
309 );
310 }
311 }
312 }
313 }
314 return $data;
315 }
$data
Definition: storeScorm.php:45

References $data, and ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ importAdditionalMetadata()

SurveyMultipleChoiceQuestion::importAdditionalMetadata ( array  $a_meta)

Import additional meta data from the question import file.

Usually the meta data section is used to store question elements which are not part of the standard XML schema.

Reimplemented from SurveyQuestion.

Definition at line 395 of file class.SurveyMultipleChoiceQuestion.php.

395 : void
396 {
397 foreach ($a_meta as $key => $value) {
398 switch ($value["label"]) {
399 case "orientation":
400 $this->setOrientation((int) $value["entry"]);
401 break;
402 case "use_min_answers":
403 $this->use_min_answers = (bool) filter_var($value["entry"], FILTER_VALIDATE_BOOLEAN);
404 break;
405 case "nr_min_answers":
406 $this->nr_min_answers = (string) $value["entry"];
407 break;
408 case "nr_max_answers":
409 $this->nr_max_answers = (string) $value["entry"];
410 break;
411 }
412 }
413 }
setOrientation(int $orientation=0)

◆ importResponses()

SurveyMultipleChoiceQuestion::importResponses ( array  $a_data)

Import response data from the question import file.

Reimplemented from SurveyQuestion.

Definition at line 415 of file class.SurveyMultipleChoiceQuestion.php.

415 : void
416 {
417 foreach ($a_data as $id => $data) {
418 $categorytext = "";
419 foreach ($data["material"] as $material) {
420 $categorytext .= $material["text"];
421 }
422 $this->categories->addCategory(
423 (string) $categorytext,
424 (int) ($data['other'] ?? 0),
425 (int) ($data['neutral'] ?? 0),
426 ($data['label'] ?? '') !== '' ? (string) $data['label'] : null,
427 ($data['scale'] ?? '') !== '' ? (int) $data['scale'] : null
428 );
429 }
430 }

References $data, and $id.

◆ insertXML()

SurveyMultipleChoiceQuestion::insertXML ( ilXmlWriter  $a_xml_writer,
bool  $a_include_header = true 
)

Adds the question XML to a given XMLWriter object.

Definition at line 192 of file class.SurveyMultipleChoiceQuestion.php.

195 : void {
196 $attrs = array(
197 "id" => $this->getId(),
198 "title" => $this->getTitle(),
199 "type" => $this->getQuestionType(),
200 "obligatory" => $this->getObligatory()
201 );
202 $a_xml_writer->xmlStartTag("question", $attrs);
203
204 $a_xml_writer->xmlElement("description", null, $this->getDescription());
205 $a_xml_writer->xmlElement("author", null, $this->getAuthor());
206 if (strlen($this->label ?? "")) {
207 $attrs = array(
208 "label" => $this->label,
209 );
210 } else {
211 $attrs = array();
212 }
213 $a_xml_writer->xmlStartTag("questiontext", $attrs);
214 $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
215 $a_xml_writer->xmlEndTag("questiontext");
216
217 $a_xml_writer->xmlStartTag("responses");
218
219 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
220 $attrs = array(
221 "id" => $i
222 );
223 if ($this->categories->getCategory($i)->other) {
224 $attrs['other'] = $this->categories->getCategory($i)->other;
225 }
226 if ($this->categories->getCategory($i)->neutral) {
227 $attrs['neutral'] = $this->categories->getCategory($i)->neutral;
228 }
229 if (strlen($this->categories->getCategory($i)->label ?? "")) {
230 $attrs['label'] = $this->categories->getCategory($i)->label;
231 }
232 if ($this->categories->getCategory($i)->scale) {
233 $attrs['scale'] = $this->categories->getCategory($i)->scale;
234 }
235 $a_xml_writer->xmlStartTag("response_multiple", $attrs);
236 $this->addMaterialTag($a_xml_writer, (string) $this->categories->getCategory($i)->title);
237 $a_xml_writer->xmlEndTag("response_multiple");
238 }
239
240 $a_xml_writer->xmlEndTag("responses");
241
242 if (count($this->material)) {
243 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", (string) $this->material["internal_link"], $matches)) {
244 $attrs = array(
245 "label" => $this->material["title"]
246 );
247 $a_xml_writer->xmlStartTag("material", $attrs);
248 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
249 if (strcmp($matches[1], "") !== 0) {
250 $intlink = $this->material["internal_link"];
251 }
252 $a_xml_writer->xmlElement("mattext", null, $intlink);
253 $a_xml_writer->xmlEndTag("material");
254 }
255 }
256
257 $a_xml_writer->xmlStartTag("metadata");
258 $a_xml_writer->xmlStartTag("metadatafield");
259 $a_xml_writer->xmlElement("fieldlabel", null, "orientation");
260 $a_xml_writer->xmlElement("fieldentry", null, $this->getOrientation());
261 $a_xml_writer->xmlEndTag("metadatafield");
262 $a_xml_writer->xmlStartTag("metadatafield");
263 $a_xml_writer->xmlElement("fieldlabel", null, "use_min_answers");
264 $a_xml_writer->xmlElement("fieldentry", null, (int) $this->use_min_answers);
265 $a_xml_writer->xmlEndTag("metadatafield");
266 $a_xml_writer->xmlStartTag("metadatafield");
267 $a_xml_writer->xmlElement("fieldlabel", null, "nr_min_answers");
268 $a_xml_writer->xmlElement("fieldentry", null, $this->nr_min_answers);
269 $a_xml_writer->xmlEndTag("metadatafield");
270 $a_xml_writer->xmlStartTag("metadatafield");
271 $a_xml_writer->xmlElement("fieldlabel", null, "nr_max_answers");
272 $a_xml_writer->xmlElement("fieldentry", null, $this->nr_max_answers);
273 $a_xml_writer->xmlEndTag("metadatafield");
274 $a_xml_writer->xmlEndTag("metadata");
275
276 $a_xml_writer->xmlEndTag("question");
277 }
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.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
const IL_INST_ID
Definition: constants.php:40

◆ isComplete()

SurveyMultipleChoiceQuestion::isComplete ( )

Reimplemented from SurveyQuestion.

Definition at line 113 of file class.SurveyMultipleChoiceQuestion.php.

113 : bool
114 {
115 return (
116 $this->getTitle() !== '' &&
117 $this->getAuthor() !== '' &&
118 $this->getQuestiontext() !== '' &&
119 $this->categories->getCategoryCount()
120 );
121 }

References SurveyQuestion\getAuthor(), SurveyQuestion\getQuestiontext(), and SurveyQuestion\getTitle().

+ Here is the call graph for this function:

◆ loadFromDb()

SurveyMultipleChoiceQuestion::loadFromDb ( int  $question_id)

load question data into object note: this base implementation only loads the material data

Reimplemented from SurveyQuestion.

Definition at line 65 of file class.SurveyMultipleChoiceQuestion.php.

65 : void
66 {
68
69 $result = $ilDB->queryF(
70 "SELECT svy_question.*, " . $this->getAdditionalTableName() . ".* FROM svy_question LEFT JOIN " . $this->getAdditionalTableName() . " ON " . $this->getAdditionalTableName() . ".question_fi = svy_question.question_id WHERE svy_question.question_id = %s",
71 array('integer'),
72 array($question_id)
73 );
74 if ($result->numRows() === 1) {
75 $data = $ilDB->fetchAssoc($result);
76 $this->setId((int) $data["question_id"]);
77 $this->setTitle((string) $data["title"]);
78 $this->label = (string) $data['label'];
79 $this->setDescription((string) $data["description"]);
80 $this->setObjId((int) $data["obj_fi"]);
81 $this->setAuthor((string) $data["author"]);
82 $this->setOwner((int) $data["owner_fi"]);
83 $this->setQuestiontext(ilRTE::_replaceMediaObjectImageSrc((string) $data["questiontext"], 1));
84 $this->setObligatory((bool) $data["obligatory"]);
85 $this->setComplete((bool) $data["complete"]);
86 $this->setOriginalId((int) $data["original_id"]);
87 $this->setOrientation((int) $data["orientation"]);
88 $this->use_min_answers = (bool) $data['use_min_answers'];
89 $this->nr_min_answers = (string) $data['nr_min_answers'];
90 $this->nr_max_answers = (string) $data['nr_max_answers'];
91
92 $this->categories->flushCategories();
93 $result = $ilDB->queryF(
94 "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",
95 array('integer'),
96 array($question_id)
97 );
98 if ($result->numRows() > 0) {
99 while ($data = $ilDB->fetchAssoc($result)) {
100 $this->categories->addCategory(
101 (string) $data["title"],
102 (int) $data["other"],
103 (int) $data["neutral"],
104 null,
105 (int) (($data['scale']) ?: ($data['sequence'] + 1))
106 );
107 }
108 }
109 }
110 parent::loadFromDb($question_id);
111 }
setTitle(string $title="")
setQuestiontext(string $questiontext="")
setDescription(string $description="")
setObjId(int $obj_id=0)
Set the reference(?) id of the container object.
setOwner(int $owner=0)
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...

References $data, SurveyQuestion\$db, $ilDB, ilRTE\_replaceMediaObjectImageSrc(), getAdditionalTableName(), ILIAS\Repository\int(), SurveyQuestion\setAuthor(), SurveyQuestion\setComplete(), SurveyQuestion\setDescription(), SurveyQuestion\setId(), SurveyQuestion\setObjId(), SurveyQuestion\setObligatory(), SurveyQuestion\setOrientation(), SurveyQuestion\setOriginalId(), SurveyQuestion\setOwner(), SurveyQuestion\setQuestiontext(), and SurveyQuestion\setTitle().

+ Here is the call graph for this function:

◆ saveCategoriesToDb()

SurveyMultipleChoiceQuestion::saveCategoriesToDb ( )

Definition at line 151 of file class.SurveyMultipleChoiceQuestion.php.

151 : void
152 {
154
155 $affectedRows = $ilDB->manipulateF(
156 "DELETE FROM svy_variable WHERE question_fi = %s",
157 array('integer'),
158 array($this->getId())
159 );
160
161 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
162 $cat = $this->categories->getCategory($i);
163 $category_id = $this->saveCategoryToDb($cat->title, $cat->neutral);
164 $next_id = $ilDB->nextId('svy_variable');
165 $affectedRows = $ilDB->manipulateF(
166 "INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, other, sequence, scale, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
167 array('integer','integer','integer','float','integer','integer', 'integer','integer'),
168 array($next_id, $category_id, $this->getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
169 );
170 }
171 $this->saveCompletionStatus();
172 }
saveCategoryToDb(string $categorytext, int $neutral=0)
Saves a category to the database.
saveCompletionStatus(int $original_id=0)
Saves the complete flag to the database.

References SurveyQuestion\$db, $ilDB, SurveyQuestion\getId(), SurveyQuestion\saveCategoryToDb(), and SurveyQuestion\saveCompletionStatus().

Referenced by saveToDb().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveToDb()

SurveyMultipleChoiceQuestion::saveToDb ( int  $original_id = 0)

Saves a SurveyQuestion object to a database.

Reimplemented from SurveyQuestion.

Definition at line 123 of file class.SurveyMultipleChoiceQuestion.php.

123 : int
124 {
126
127 $affectedRows = parent::saveToDb($original_id);
128 if ($affectedRows === 1) {
129 $ilDB->manipulateF(
130 "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
131 array('integer'),
132 array($this->getId())
133 );
134 $ilDB->manipulateF(
135 "INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, orientation, use_min_answers, nr_min_answers, nr_max_answers) VALUES (%s, %s, %s, %s, %s)",
136 array('integer', 'text', 'integer', 'integer', 'integer'),
137 array(
138 $this->getId(),
139 $this->getOrientation(),
140 ($this->use_min_answers) ? 1 : 0,
141 ($this->nr_min_answers > 0) ? $this->nr_min_answers : null,
142 ($this->nr_max_answers > 0) ? $this->nr_max_answers : null
143 )
144 );
145
146 $this->saveCategoriesToDb();
147 }
148 return $affectedRows;
149 }

References SurveyQuestion\$db, $ilDB, SurveyQuestion\$original_id, getAdditionalTableName(), SurveyQuestion\getId(), SurveyQuestion\getOrientation(), and saveCategoriesToDb().

+ Here is the call graph for this function:

◆ saveUserInput()

SurveyMultipleChoiceQuestion::saveUserInput ( array  $post_data,
int  $active_id,
bool  $a_return = false 
)

Definition at line 356 of file class.SurveyMultipleChoiceQuestion.php.

360 : ?array {
362
363 if ($a_return) {
364 $return_data = array();
365 }
366 $entered_values = $post_data[$this->getId() . "_value"] ?? [];
367 foreach (is_array($entered_values) ? $entered_values : [] as $entered_value) {
368 $entered_value = (string) $entered_value;
369 if ($entered_value !== '') {
370 if (!$a_return) {
371 $next_id = $ilDB->nextId('svy_answer');
372
373 #20216
374 $fields = array();
375 $fields['answer_id'] = array("integer", $next_id);
376 $fields['question_fi'] = array("integer", $this->getId());
377 $fields['active_fi'] = array("integer", $active_id);
378 $fields['value'] = array("float", $entered_value);
379 $fields['textanswer'] = array("clob", isset($post_data[$this->getId() . "_" . $entered_value . "_other"]) ? $this->stripSlashesAddSpaceFallback((string) $post_data[$this->getId() . "_" . $entered_value . "_other"]) : null);
380 $fields['tstamp'] = array("integer", time());
381
382 $affectedRows = $ilDB->insert("svy_answer", $fields);
383 } else {
384 $return_data[] = array("value" => $entered_value,
385 "textanswer" => (string) ($post_data[$this->getId() . "_" . $entered_value . "_other"] ?? ""));
386 }
387 }
388 }
389 if ($a_return) {
390 return $return_data;
391 }
392 return null;
393 }
stripSlashesAddSpaceFallback(string $a_str)
Strip slashes with add space fallback, see https://mantis.ilias.de/view.php?id=19727 and https://mant...

◆ toXML()

SurveyMultipleChoiceQuestion::toXML ( bool  $a_include_header = true,
bool  $obligatory_state = false 
)

Definition at line 174 of file class.SurveyMultipleChoiceQuestion.php.

177 : string {
178 $a_xml_writer = new ilXmlWriter();
179 $a_xml_writer->xmlHeader();
180 $this->insertXML($a_xml_writer, $a_include_header);
181 $xml = $a_xml_writer->xmlDumpMem(false);
182 if (!$a_include_header) {
183 $pos = strpos($xml, "?>");
184 $xml = substr($xml, $pos + 2);
185 }
186 return $xml;
187 }
insertXML(ilXmlWriter $a_xml_writer, bool $a_include_header=true)
Adds the question XML to a given XMLWriter object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ usableForPrecondition()

SurveyMultipleChoiceQuestion::usableForPrecondition ( )

Returns if the question is usable for preconditions.

Reimplemented from SurveyQuestion.

Definition at line 432 of file class.SurveyMultipleChoiceQuestion.php.

432 : bool
433 {
434 return true;
435 }

Field Documentation

◆ $categories

SurveyCategories SurveyMultipleChoiceQuestion::$categories

Definition at line 29 of file class.SurveyMultipleChoiceQuestion.php.


The documentation for this class was generated from the following file: