ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SurveyMultipleChoiceQuestion Class Reference

MultipleChoice survey question. More...

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

Public Member Functions

 __construct ($title="", $description="", $author="", $questiontext="", $owner=-1, $orientation=0)
 The constructor takes possible arguments an creates an instance of the SurveyMultipleChoiceQuestion object. More...
 
 getQuestionDataArray ($id)
 Returns the question data fields from the database. More...
 
 loadFromDb ($id)
 Loads a SurveyMultipleChoiceQuestion object from the database. More...
 
 isComplete ()
 Returns true if the question is complete for use. More...
 
 saveToDb ($original_id="")
 Saves a SurveyMultipleChoiceQuestion object to a database. More...
 
 saveCategoriesToDb ()
 
 toXML ($a_include_header=true, $obligatory_state="")
 Returns an xml representation of the question. More...
 
 insertXML (&$a_xml_writer, $a_include_header=true)
 Adds the question XML to a given XMLWriter object. More...
 
 getQuestionType ()
 Returns the question type of the question. More...
 
 getAdditionalTableName ()
 Returns the name of the additional question data table in the database. More...
 
getWorkingDataFromUserInput ($post_data)
 Creates the user data of the svy_answer table from the POST data. More...
 
 checkUserInput ($post_data, $survey_id)
 Checks the input of the active user for obligatory status and entered values. More...
 
 saveUserInput ($post_data, $active_id, $a_return=false)
 
 importAdditionalMetadata ($a_meta)
 Import additional meta data from the question import file. More...
 
 importResponses ($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 ($default="", $title, $variable)
 Creates a form property for the precondition value. More...
 
 getPreconditionValueOutput ($value)
 Returns the output for a precondition value. More...
 
 getCategories ()
 
- Public Member Functions inherited from SurveyQuestion
 __construct ($title="", $description="", $author="", $questiontext="", $owner=-1)
 SurveyQuestion constructor The constructor takes possible arguments an creates an instance of the SurveyQuestion object. More...
 
 setComplete ($a_complete)
 Sets the complete state of the question. More...
 
 isComplete ()
 Returns 1, if a question is complete for use. More...
 
 questionTitleExists ($title, $questionpool_object="")
 Returns TRUE if the question title exists in the database. More...
 
 setTitle ($title="")
 Sets the title string of the SurveyQuestion object. More...
 
 setObligatory ($obligatory=1)
 Sets the obligatory state of the question. More...
 
 setOrientation ($orientation=0)
 Sets the orientation of the question output. More...
 
 setId ($id=-1)
 Sets the id of the SurveyQuestion object. More...
 
 setSurveyId ($id=-1)
 Sets the survey id of the SurveyQuestion object. More...
 
 setDescription ($description="")
 Sets the description string of the SurveyQuestion object. More...
 
 addMaterials ($materials_file, $materials_name="")
 Sets the materials uri. More...
 
 setMaterialsfile ($materials_filename, $materials_tempfilename="", $materials_name="")
 Sets and uploads the materials uri. More...
 
 deleteMaterial ($materials_name="")
 Deletes a materials uri with a given name. More...
 
 flushMaterials ()
 Deletes all materials uris. More...
 
 setAuthor ($author="")
 Sets the authors name of the SurveyQuestion object. More...
 
 setQuestiontext ($questiontext="")
 Sets the questiontext of the SurveyQuestion object. More...
 
 setOwner ($owner="")
 Sets the creator/owner ID of the SurveyQuestion object. More...
 
 getTitle ()
 Gets the title string of the SurveyQuestion object. More...
 
 getLabel ()
 
 getId ()
 Gets the id of the SurveyQuestion object. More...
 
 getObligatory ($survey_id="")
 Gets the obligatory state of the question. More...
 
 getSurveyId ()
 Gets the survey id of the SurveyQuestion object. More...
 
 getOrientation ()
 Gets the orientation of the question output. More...
 
 getDescription ()
 Gets the description string of the SurveyQuestion object. More...
 
 getAuthor ()
 Gets the authors name of the SurveyQuestion object. More...
 
 getOwner ()
 Gets the creator/owner ID of the SurveyQuestion object. More...
 
 getQuestiontext ()
 Gets the questiontext of the SurveyQuestion object. More...
 
 getObjId ()
 Get the reference id of the container object. More...
 
 setObjId ($obj_id=0)
 Set the reference id of the container object. More...
 
 duplicate ($for_survey=true, $title="", $author="", $owner="", $a_survey_id=0)
 Duplicates a survey question. More...
 
 copyObject ($target_questionpool, $title="")
 Copies an assOrderingQuestion object. More...
 
 copyXHTMLMediaObjectsOfQuestion ($a_q_id)
 Increases the media object usage counter when a question is duplicated. More...
 
 loadFromDb ($question_id)
 Loads a SurveyQuestion object from the database. More...
 
 saveCompletionStatus ($original_id="")
 Saves the complete flag to the database. More...
 
 saveToDb ($original_id="")
 Saves a SurveyQuestion object to a database. More...
 
 saveMaterial ()
 save material to db 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...
 
 saveWorkingData ($limit_to=LIMIT_NO_LIMIT)
 Saves the learners input of the question to the database. More...
 
 getImagePath ()
 Returns the image path for web accessable images of a question. More...
 
 getMaterialsPath ()
 Returns the materials path for web accessable materials of a question. More...
 
 getImagePathWeb ()
 Returns the web image path for web accessable images of a question. More...
 
 getMaterialsPathWeb ()
 Returns the web image path for web accessable images of a question. More...
 
 saveCategoryToDb ($categorytext, $neutral=0)
 Saves a category to the database. More...
 
 deleteAdditionalTableData ($question_id)
 Deletes datasets from the additional question table in the database. More...
 
 delete ($question_id)
 Deletes a question and all materials from the database. More...
 
 syncWithOriginal ()
 
 getPhrase ($phrase_id)
 Returns a phrase for a given database id. More...
 
 phraseExists ($title)
 Returns true if the phrase title already exists for the current user. More...
 
 addInternalLink ($material_id, $title="")
 
 deleteMaterials ($a_array)
 Deletes materials. More...
 
 duplicateMaterials ($question_id)
 Duplicates the materials of a question. More...
 
 addMaterial ($obj_material)
 
 setMaterial ($material_id="", $is_import=false, $material_title="")
 Sets a material link for the question. More...
 
 getQuestionTypeID ()
 Returns the question type ID of the question. More...
 
 getQuestionType ()
 Returns the question type of the question. More...
 
 isHTML ($a_text)
 Checks if a given string contains HTML or not. More...
 
 QTIMaterialToString ($a_material)
 Reads an QTI material tag an creates a text string. More...
 
 addMaterialTag (&$a_xml_writer, $a_material, $close_material_tag=true, $add_mobs=true, $a_attrs=null)
 Creates an XML material tag from a plain text or xhtml text. More...
 
 prepareTextareaOutput ($txt_output, $prepare_for_latex_output=false)
 Prepares a string for a text area output in surveys. More...
 
 getQuestionDataArray ($id)
 Returns the question data fields from the database. More...
 
getWorkingDataFromUserInput ($post_data)
 Creates the user data of the svy_answer table from the POST data. More...
 
 importAdditionalMetadata ($a_meta)
 Import additional meta data from the question import file. More...
 
 importResponses ($a_data)
 Import response data from the question import file. More...
 
 importAdjectives ($a_data)
 Import bipolar adjectives from the question import file. More...
 
 importMatrix ($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 ($value)
 Returns the output for a precondition value. More...
 
 getPreconditionSelectValue ($default="", $title, $variable)
 Creates a form property for the precondition value. More...
 
 setOriginalId ($original_id)
 
 getOriginalId ()
 
 getMaterial ()
 
 setSubtype ($a_subtype)
 
 getSubtype ()
 
 __get ($value)
 Object getter. More...
 
 __set ($key, $value)
 Object setter. More...
 
 getCopyIds ($a_group_by_survey=false)
 
 hasCopies ()
 
 stripSlashesAddSpaceFallback ($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...
 

Data Fields

 $categories
 
- Data Fields inherited from SurveyQuestion
 $id
 
 $title
 
 $description
 
 $owner
 
 $author
 
 $materials
 
 $survey_id
 
 $obj_id
 
 $questiontext
 
 $obligatory
 
 $lng
 
 $orientation
 
 $material
 
 $complete
 

Protected Attributes

 $db
 
- Protected Attributes inherited from SurveyQuestion
 $user
 
 $db
 
 $cumulated
 An array containing the cumulated results of the question for a given survey. More...
 
 $log
 

Additional Inherited Members

- Static Public Member Functions inherited from SurveyQuestion
static _isComplete ($question_id)
 Checks whether the question is complete or not. More...
 
static _getQuestionType ($question_id)
 Returns the question type of a question with a given id. More...
 
static _getTitle ($question_id)
 Returns the question title of a question with a given id. More...
 
static _getOriginalId ($question_id, $a_return_question_id_if_no_original=true)
 Returns the original id of a question. More...
 
static _questionExists ($question_id)
 Returns true if the question already exists in the database. More...
 
static _resolveInternalLink ($internal_link)
 
static _resolveIntLinks ($question_id)
 
static _getInternalLinkHref ($target="", $a_parent_ref_id=null)
 
static _isWriteable ($question_id, $user_id)
 Returns true if the question is writeable by a certain user. More...
 
static _includeClass ($question_type, $gui=0)
 Include the php class file for a given question type. More...
 
static _getQuestionTypeName ($type_tag)
 Return the translation for a given question type tag. More...
 
static _instanciateQuestion ($question_id)
 Creates an instance of a question with a given question id. More...
 
static _instanciateQuestionGUI ($question_id)
 Creates an instance of a question GUI with a given question id. More...
 
static _instanciateQuestionEvaluation ($question_id, array $a_finished_ids=null)
 Creates an instance of a question evaluation with a given question id. More...
 
static _changeOriginalId ($a_question_id, $a_original_id, $a_object_id)
 Change original id of existing question in db. More...
 
static _lookupSurveyObjId ($a_question_id)
 
static lookupObjFi ($a_qid)
 Lookip obj fi. More...
 

Detailed Description

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
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

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

The constructor takes possible arguments an creates an instance of the SurveyMultipleChoiceQuestion object.

Parameters
string$titleA title string to describe the question
string$descriptionA description string to describe the question
string$authorA string containing the name of the questions author
integer$ownerA numerical ID to identify the owner/creator @access public

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

61 {
62 global $DIC;
63
64 $this->db = $DIC->database();
65 $this->lng = $DIC->language();
66 parent::__construct($title, $description, $author, $questiontext, $owner);
67
68 $this->orientation = $orientation;
69 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
70 $this->categories = new SurveyCategories();
71 }
Class SurveyCategories.
global $DIC
Definition: saml.php:7

References SurveyQuestion\$author, SurveyQuestion\$description, $DIC, SurveyQuestion\$orientation, SurveyQuestion\$owner, SurveyQuestion\$questiontext, and SurveyQuestion\$title.

Member Function Documentation

◆ checkUserInput()

SurveyMultipleChoiceQuestion::checkUserInput (   $post_data,
  $survey_id 
)

Checks the input of the active user for obligatory status and entered values.

Parameters
array$post_dataThe contents of the $_POST array
integer$survey_idThe database ID of the active survey
Returns
string Empty string if the input is ok, an error message otherwise @access public

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

395 {
396 $entered_value = (array) $post_data[$this->getId() . "_value"];
397 if (!$this->getObligatory($survey_id) && (!is_array($entered_value) || count($entered_value) == 0)) {
398 return "";
399 }
400 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) != $this->nr_max_answers) {
401 return sprintf($this->lng->txt("err_no_exact_answers"), $this->nr_min_answers);
402 }
403 if ($this->use_min_answers && $this->nr_min_answers > 0 && count($entered_value) < $this->nr_min_answers) {
404 return sprintf($this->lng->txt("err_no_min_answers"), $this->nr_min_answers);
405 }
406 if ($this->use_min_answers && $this->nr_max_answers > 0 && count($entered_value) > $this->nr_max_answers) {
407 return sprintf($this->lng->txt("err_no_max_answers"), $this->nr_max_answers);
408 }
409 if (count($entered_value) == 0) {
410 return $this->lng->txt("question_mr_not_checked");
411 }
412 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
413 $cat = $this->categories->getCategory($i);
414 if ($cat->other) {
415 if (in_array($i, $entered_value)) {
416 if (array_key_exists($this->getId() . "_" . $i . "_other", $post_data) && !strlen($post_data[$this->getId() . "_" . $i . "_other"])) {
417 return $this->lng->txt("question_mr_no_other_answer");
418 }
419 } else {
420 if (strlen($post_data[$this->getId() . "_" . $i . "_other"])) {
421 return $this->lng->txt("question_mr_no_other_answer_checked");
422 }
423 }
424 }
425 }
426 return "";
427 }
getId()
Gets the id of the SurveyQuestion object.
getObligatory($survey_id="")
Gets the obligatory state of the question.
$i
Definition: disco.tpl.php:19

References $i, SurveyQuestion\$survey_id, SurveyQuestion\getId(), and SurveyQuestion\getObligatory().

+ Here is the call graph for this function:

◆ getAdditionalTableName()

SurveyMultipleChoiceQuestion::getAdditionalTableName ( )

Returns the name of the additional question data table in the database.

Returns
string The additional table name @access public

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

352 {
353 return "svy_qst_mc";
354 }

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

+ Here is the caller graph for this function:

◆ getAvailableRelations()

SurveyMultipleChoiceQuestion::getAvailableRelations ( )

Returns the available relations for the question.

Returns
array An array containing the available relations @access public

Reimplemented from SurveyQuestion.

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

533 {
534 return array("=", "<>");
535 }

◆ getCategories()

SurveyMultipleChoiceQuestion::getCategories ( )

◆ getPreconditionOptions()

SurveyMultipleChoiceQuestion::getPreconditionOptions ( )

Returns the options for preconditions.

Returns
array

Reimplemented from SurveyQuestion.

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

543 {
545
546 $options = array();
547 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
548 $category = $this->categories->getCategory($i);
549 $options[$category->scale - 1] = $category->scale . " - " . $category->title;
550 }
551 return $options;
552 }

References $i, SurveyQuestion\$lng, and PHPMailer\PHPMailer\$options.

Referenced by getPreconditionSelectValue().

+ Here is the caller graph for this function:

◆ getPreconditionSelectValue()

SurveyMultipleChoiceQuestion::getPreconditionSelectValue (   $default = "",
  $title,
  $variable 
)

Creates a form property for the precondition value.

Returns
The ILIAS form element @access public

Reimplemented from SurveyQuestion.

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

561 {
562 include_once "./Services/Form/classes/class.ilSelectInputGUI.php";
563 $step3 = new ilSelectInputGUI($title, $variable);
565 $step3->setOptions($options);
566 $step3->setValue($default);
567 return $step3;
568 }
$default
Definition: build.php:20
getPreconditionOptions()
Returns the options for preconditions.
This class represents a selection list property in a property form.

References $default, PHPMailer\PHPMailer\$options, SurveyQuestion\$title, and getPreconditionOptions().

+ Here is the call graph for this function:

◆ getPreconditionValueOutput()

SurveyMultipleChoiceQuestion::getPreconditionValueOutput (   $value)

Returns the output for a precondition value.

Parameters
string$valueThe precondition value
Returns
string The output of the precondition value @access public

Reimplemented from SurveyQuestion.

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

578 {
579 // #18136
580 $category = $this->categories->getCategoryForScale($value + 1);
581
582 // #17895 - see getPreconditionOptions()
583 return $category->scale .
584 " - " .
585 ((strlen($category->title)) ? $category->title : $this->lng->txt('other_answer'));
586 }

◆ getQuestionDataArray()

SurveyMultipleChoiceQuestion::getQuestionDataArray (   $id)

Returns the question data fields from the database.

Parameters
integer$idThe question ID from the database
Returns
array Array containing the question fields and data from the database @access public

Reimplemented from SurveyQuestion.

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

81 {
83
84 $result = $ilDB->queryF(
85 "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",
86 array('integer'),
87 array($id)
88 );
89 if ($result->numRows() == 1) {
90 return $ilDB->fetchAssoc($result);
91 } else {
92 return array();
93 }
94 }
$result
getAdditionalTableName()
Returns the name of the additional question data table in the database.
global $ilDB

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

+ Here is the call graph for this function:

◆ getQuestionType()

SurveyMultipleChoiceQuestion::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question @access public

Reimplemented from SurveyQuestion.

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

341 {
342 return "SurveyMultipleChoiceQuestion";
343 }

◆ getWorkingDataFromUserInput()

& SurveyMultipleChoiceQuestion::getWorkingDataFromUserInput (   $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 @access public

Reimplemented from SurveyQuestion.

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

363 {
364 $entered_value = $post_data[$this->getId() . "_value"];
365 $data = array();
366 if (is_array($entered_value)) {
367 foreach ($entered_value as $idx => $value) {
368 array_push($data, array("value" => $value, "textanswer" => $post_data[$this->getId() . '_' . $value . '_other']));
369 }
370 }
371 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
372 $cat = $this->categories->getCategory($i);
373 if ($cat->other) {
374 // #18212
375 if (!is_array($entered_value) || !in_array($i, $entered_value)) {
376 if (strlen($post_data[$this->getId() . "_" . $i . "_other"])) {
377 array_push($data, array("value" => $i, "textanswer" => $post_data[$this->getId() . '_' . $i . '_other'], "uncheck" => true));
378 }
379 }
380 }
381 }
382 return $data;
383 }
$data
Definition: bench.php:6

References $data, $i, and SurveyQuestion\getId().

+ Here is the call graph for this function:

◆ importAdditionalMetadata()

SurveyMultipleChoiceQuestion::importAdditionalMetadata (   $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.

Returns
array $a_meta Array containing the additional meta data @access public

Reimplemented from SurveyQuestion.

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

473 {
474 foreach ($a_meta as $key => $value) {
475 switch ($value["label"]) {
476 case "orientation":
477 $this->setOrientation($value["entry"]);
478 break;
479 case "use_min_answers":
480 $this->use_min_answers = $value["entry"];
481 break;
482 case "nr_min_answers":
483 $this->nr_min_answers = $value["entry"];
484 break;
485 case "nr_max_answers":
486 $this->nr_max_answers = $value["entry"];
487 break;
488 }
489 }
490 }
setOrientation($orientation=0)
Sets the orientation of the question output.
$key
Definition: croninfo.php:18

References $key, and SurveyQuestion\setOrientation().

+ Here is the call graph for this function:

◆ importResponses()

SurveyMultipleChoiceQuestion::importResponses (   $a_data)

Import response data from the question import file.

Returns
array $a_data Array containing the response data @access public

Reimplemented from SurveyQuestion.

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

499 {
500 foreach ($a_data as $id => $data) {
501 $categorytext = "";
502 foreach ($data["material"] as $material) {
503 $categorytext .= $material["text"];
504 }
505 $this->categories->addCategory(
506 $categorytext,
507 strlen($data['other']) ? $data['other'] : 0,
508 strlen($data['neutral']) ? $data['neutral'] : 0,
509 strlen($data['label']) ? $data['label'] : null,
510 strlen($data['scale']) ? $data['scale'] : null
511 );
512 }
513 }

References $data, SurveyQuestion\$id, and SurveyQuestion\$material.

◆ insertXML()

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

Adds the question XML to a given XMLWriter object.

Parameters
object$a_xml_writerThe XMLWriter object
boolean$a_include_headerDetermines wheather or not the XML should be used @access public

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

250 {
251 $attrs = array(
252 "id" => $this->getId(),
253 "title" => $this->getTitle(),
254 "type" => $this->getQuestiontype(),
255 "obligatory" => $this->getObligatory()
256 );
257 $a_xml_writer->xmlStartTag("question", $attrs);
258
259 $a_xml_writer->xmlElement("description", null, $this->getDescription());
260 $a_xml_writer->xmlElement("author", null, $this->getAuthor());
261 if (strlen($this->label)) {
262 $attrs = array(
263 "label" => $this->label,
264 );
265 } else {
266 $attrs = array();
267 }
268 $a_xml_writer->xmlStartTag("questiontext", $attrs);
269 $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
270 $a_xml_writer->xmlEndTag("questiontext");
271
272 $a_xml_writer->xmlStartTag("responses");
273
274 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
275 $attrs = array(
276 "id" => $i
277 );
278 if (strlen($this->categories->getCategory($i)->other)) {
279 $attrs['other'] = $this->categories->getCategory($i)->other;
280 }
281 if (strlen($this->categories->getCategory($i)->neutral)) {
282 $attrs['neutral'] = $this->categories->getCategory($i)->neutral;
283 }
284 if (strlen($this->categories->getCategory($i)->label)) {
285 $attrs['label'] = $this->categories->getCategory($i)->label;
286 }
287 if (strlen($this->categories->getCategory($i)->scale)) {
288 $attrs['scale'] = $this->categories->getCategory($i)->scale;
289 }
290 $a_xml_writer->xmlStartTag("response_multiple", $attrs);
291 $this->addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
292 $a_xml_writer->xmlEndTag("response_multiple");
293 }
294
295 $a_xml_writer->xmlEndTag("responses");
296
297 if (count($this->material)) {
298 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches)) {
299 $attrs = array(
300 "label" => $this->material["title"]
301 );
302 $a_xml_writer->xmlStartTag("material", $attrs);
303 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
304 if (strcmp($matches[1], "") != 0) {
305 $intlink = $this->material["internal_link"];
306 }
307 $a_xml_writer->xmlElement("mattext", null, $intlink);
308 $a_xml_writer->xmlEndTag("material");
309 }
310 }
311
312 $a_xml_writer->xmlStartTag("metadata");
313 $a_xml_writer->xmlStartTag("metadatafield");
314 $a_xml_writer->xmlElement("fieldlabel", null, "orientation");
315 $a_xml_writer->xmlElement("fieldentry", null, $this->getOrientation());
316 $a_xml_writer->xmlEndTag("metadatafield");
317 $a_xml_writer->xmlStartTag("metadatafield");
318 $a_xml_writer->xmlElement("fieldlabel", null, "use_min_answers");
319 $a_xml_writer->xmlElement("fieldentry", null, $this->use_min_answers);
320 $a_xml_writer->xmlEndTag("metadatafield");
321 $a_xml_writer->xmlStartTag("metadatafield");
322 $a_xml_writer->xmlElement("fieldlabel", null, "nr_min_answers");
323 $a_xml_writer->xmlElement("fieldentry", null, $this->nr_min_answers);
324 $a_xml_writer->xmlEndTag("metadatafield");
325 $a_xml_writer->xmlStartTag("metadatafield");
326 $a_xml_writer->xmlElement("fieldlabel", null, "nr_max_answers");
327 $a_xml_writer->xmlElement("fieldentry", null, $this->nr_max_answers);
328 $a_xml_writer->xmlEndTag("metadatafield");
329 $a_xml_writer->xmlEndTag("metadata");
330
331 $a_xml_writer->xmlEndTag("question");
332 }
getDescription()
Gets the description string of the SurveyQuestion object.
getAuthor()
Gets the authors name of the SurveyQuestion object.
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getTitle()
Gets the title string of the SurveyQuestion object.
getOrientation()
Gets the orientation of the question output.
addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag=true, $add_mobs=true, $a_attrs=null)
Creates an XML material tag from a plain text or xhtml text.

References $i, SurveyQuestion\addMaterialTag(), SurveyQuestion\getAuthor(), SurveyQuestion\getDescription(), SurveyQuestion\getId(), SurveyQuestion\getObligatory(), SurveyQuestion\getOrientation(), SurveyQuestion\getQuestiontext(), and SurveyQuestion\getTitle().

Referenced by toXML().

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

◆ isComplete()

SurveyMultipleChoiceQuestion::isComplete ( )

Returns true if the question is complete for use.

Returns
boolean True if the question is complete for use, otherwise false @access public

Reimplemented from SurveyQuestion.

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

152 {
153 if (
154 strlen($this->getTitle()) &&
155 strlen($this->getAuthor()) &&
156 strlen($this->getQuestiontext()) &&
157 $this->categories->getCategoryCount()
158 ) {
159 return 1;
160 } else {
161 return 0;
162 }
163 }

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

+ Here is the call graph for this function:

◆ loadFromDb()

SurveyMultipleChoiceQuestion::loadFromDb (   $id)

Loads a SurveyMultipleChoiceQuestion object from the database.

Parameters
integer$idThe database id of the multiple choice survey question @access public

Reimplemented from SurveyQuestion.

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

103 {
105
106 $result = $ilDB->queryF(
107 "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",
108 array('integer'),
109 array($id)
110 );
111 if ($result->numRows() == 1) {
112 $data = $ilDB->fetchAssoc($result);
113 $this->setId($data["question_id"]);
114 $this->setTitle($data["title"]);
115 $this->label = $data['label'];
116 $this->setDescription($data["description"]);
117 $this->setObjId($data["obj_fi"]);
118 $this->setAuthor($data["author"]);
119 $this->setOwner($data["owner_fi"]);
120 include_once("./Services/RTE/classes/class.ilRTE.php");
121 $this->setQuestiontext(ilRTE::_replaceMediaObjectImageSrc($data["questiontext"], 1));
122 $this->setObligatory($data["obligatory"]);
123 $this->setComplete($data["complete"]);
124 $this->setOriginalId($data["original_id"]);
125 $this->setOrientation($data["orientation"]);
126 $this->use_min_answers = ($data['use_min_answers']) ? true : false;
127 $this->nr_min_answers = $data['nr_min_answers'];
128 $this->nr_max_answers = $data['nr_max_answers'];
129
130 $this->categories->flushCategories();
131 $result = $ilDB->queryF(
132 "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",
133 array('integer'),
134 array($id)
135 );
136 if ($result->numRows() > 0) {
137 while ($data = $ilDB->fetchAssoc($result)) {
138 $this->categories->addCategory($data["title"], $data["other"], $data["neutral"], null, ($data['scale']) ? $data['scale'] : ($data['sequence'] + 1));
139 }
140 }
141 }
142 parent::loadFromDb($id);
143 }
setQuestiontext($questiontext="")
Sets the questiontext of the SurveyQuestion object.
setId($id=-1)
Sets the id of the SurveyQuestion object.
setAuthor($author="")
Sets the authors name of the SurveyQuestion object.
setDescription($description="")
Sets the description string of the SurveyQuestion object.
setObjId($obj_id=0)
Set the reference id of the container object.
setOriginalId($original_id)
setComplete($a_complete)
Sets the complete state of the question.
setOwner($owner="")
Sets the creator/owner ID of the SurveyQuestion object.
setTitle($title="")
Sets the title string of the SurveyQuestion object.
setObligatory($obligatory=1)
Sets the obligatory state of the question.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...

References $data, $db, SurveyQuestion\$id, $ilDB, $result, ilRTE\_replaceMediaObjectImageSrc(), getAdditionalTableName(), 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 199 of file class.SurveyMultipleChoiceQuestion.php.

200 {
202
203 $affectedRows = $ilDB->manipulateF(
204 "DELETE FROM svy_variable WHERE question_fi = %s",
205 array('integer'),
206 array($this->getId())
207 );
208
209 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
210 $cat = $this->categories->getCategory($i);
211 $category_id = $this->saveCategoryToDb($cat->title, $cat->neutral);
212 $next_id = $ilDB->nextId('svy_variable');
213 $affectedRows = $ilDB->manipulateF(
214 "INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, other, sequence, scale, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
215 array('integer','integer','integer','float','integer','integer', 'integer','integer'),
216 array($next_id, $category_id, $this->getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
217 );
218 }
219 $this->saveCompletionStatus();
220 }
saveCategoryToDb($categorytext, $neutral=0)
Saves a category to the database.
saveCompletionStatus($original_id="")
Saves the complete flag to the database.

References $db, $i, $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 (   $original_id = "")

Saves a SurveyMultipleChoiceQuestion object to a database.

@access public

Reimplemented from SurveyQuestion.

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

171 {
173
174 $affectedRows = parent::saveToDb($original_id);
175 if ($affectedRows == 1) {
176 $affectedRows = $ilDB->manipulateF(
177 "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
178 array('integer'),
179 array($this->getId())
180 );
181 $affectedRows = $ilDB->manipulateF(
182 "INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, orientation, use_min_answers, nr_min_answers, nr_max_answers) VALUES (%s, %s, %s, %s, %s)",
183 array('integer', 'text', 'integer', 'integer', 'integer'),
184 array(
185 $this->getId(),
186 $this->getOrientation(),
187 ($this->use_min_answers) ? 1 : 0,
188 ($this->nr_min_answers > 0) ? $this->nr_min_answers : null,
189 ($this->nr_max_answers > 0) ? $this->nr_max_answers : null
190 )
191 );
192
193 // saving material uris in the database
194 $this->saveMaterial();
195 $this->saveCategoriesToDb();
196 }
197 }
saveMaterial()
save material to db

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

+ Here is the call graph for this function:

◆ saveUserInput()

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

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

430 {
432
433 if ($a_return) {
434 $return_data = array();
435 }
436 if (is_array($post_data[$this->getId() . "_value"])) {
437 foreach ($post_data[$this->getId() . "_value"] as $entered_value) {
438 if (strlen($entered_value) > 0) {
439 if (!$a_return) {
440 $next_id = $ilDB->nextId('svy_answer');
441
442 #20216
443 $fields = array();
444 $fields['answer_id'] = array("integer", $next_id);
445 $fields['question_fi'] = array("integer", $this->getId());
446 $fields['active_fi'] = array("integer", $active_id);
447 $fields['value'] = array("float", (strlen($entered_value)) ? $entered_value : null);
448 $fields['textanswer'] = array("clob", ($post_data[$this->getId() . "_" . $entered_value . "_other"]) ? $this->stripSlashesAddSpaceFallback($post_data[$this->getId() . "_" . $entered_value . "_other"]) : null);
449 $fields['tstamp'] = array("integer", time());
450
451 $affectedRows = $ilDB->insert("svy_answer", $fields);
452 } else {
453 $return_data[] = array("value" => $entered_value,
454 "textanswer" => $post_data[$this->getId() . "_" . $entered_value . "_other"]);
455 }
456 }
457 }
458 }
459 if ($a_return) {
460 return $return_data;
461 }
462 }
stripSlashesAddSpaceFallback($a_str)
Strip slashes with add space fallback, see https://mantis.ilias.de/view.php?id=19727 and https://mant...

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

+ Here is the call graph for this function:

◆ toXML()

SurveyMultipleChoiceQuestion::toXML (   $a_include_header = true,
  $obligatory_state = "" 
)

Returns an xml representation of the question.

Returns
string The xml representation of the question @access public

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

229 {
230 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
231 $a_xml_writer = new ilXmlWriter;
232 $a_xml_writer->xmlHeader();
233 $this->insertXML($a_xml_writer, $a_include_header, $obligatory_state);
234 $xml = $a_xml_writer->xmlDumpMem(false);
235 if (!$a_include_header) {
236 $pos = strpos($xml, "?>");
237 $xml = substr($xml, $pos + 2);
238 }
239 return $xml;
240 }
insertXML(&$a_xml_writer, $a_include_header=true)
Adds the question XML to a given XMLWriter object.
XML writer class.
xmlHeader()
Writes xml header @access public.

References $xml, insertXML(), and ilXmlWriter\xmlHeader().

+ Here is the call graph for this function:

◆ usableForPrecondition()

SurveyMultipleChoiceQuestion::usableForPrecondition ( )

Returns if the question is usable for preconditions.

Returns
boolean TRUE if the question is usable for a precondition, FALSE otherwise @access public

Reimplemented from SurveyQuestion.

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

522 {
523 return true;
524 }

Field Documentation

◆ $categories

SurveyMultipleChoiceQuestion::$categories

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

Referenced by getCategories().

◆ $db

SurveyMultipleChoiceQuestion::$db
protected

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