ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
SurveySingleChoiceQuestion Class Reference

SingleChoice survey question. More...

+ Inheritance diagram for SurveySingleChoiceQuestion:
+ Collaboration diagram for SurveySingleChoiceQuestion:

Public Member Functions

 __construct ($title="", $description="", $author="", $questiontext="", $owner=-1, $orientation=1)
 SurveySingleChoiceQuestion constructor. More...
 
getCategoriesForPhrase ($phrase_id)
 Gets the available categories for a given phrase. More...
 
 addPhrase ($phrase_id)
 Adds a phrase to the question. More...
 
 getQuestionDataArray ($id)
 Returns the question data fields from the database. More...
 
 loadFromDb ($id)
 Loads a SurveySingleChoiceQuestion object from the database. More...
 
 isComplete ()
 Returns true if the question is complete for use. More...
 
 saveToDb ($original_id="")
 Saves a SurveySingleChoiceQuestion 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...
 
 importAdditionalMetadata ($a_meta)
 Import additional meta data from the question import file. More...
 
 addStandardNumbers ($lower_limit, $upper_limit)
 Adds standard numbers as categories. More...
 
 savePhrase ($title)
 Saves a set of categories to a default phrase. 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)
 
 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
 

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...
 
- Protected Attributes inherited from SurveyQuestion
 $user
 
 $db
 
 $cumulated
 An array containing the cumulated results of the question for a given survey. More...
 
 $log
 

Detailed Description

SingleChoice survey question.

The SurveySingleChoiceQuestion class defines and encapsulates basic methods and attributes for single 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 13 of file class.SurveySingleChoiceQuestion.php.

Constructor & Destructor Documentation

◆ __construct()

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

SurveySingleChoiceQuestion constructor.

The constructor takes possible arguments an creates an instance of the SurveySingleChoiceQuestion 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 public

Definition at line 33 of file class.SurveySingleChoiceQuestion.php.

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

34  {
35  global $DIC;
36 
37  $this->db = $DIC->database();
38  $this->user = $DIC->user();
39  $this->lng = $DIC->language();
41 
42  $this->orientation = $orientation;
43  $this->categories = new SurveyCategories();
44  }
user()
Definition: user.php:4
Class SurveyCategories.
__construct(Container $dic, ilPlugin $plugin)
$DIC
Definition: xapitoken.php:46
+ Here is the call graph for this function:

Member Function Documentation

◆ addPhrase()

SurveySingleChoiceQuestion::addPhrase (   $phrase_id)

Adds a phrase to the question.

Parameters
integer$phrase_idThe database id of the given phrase public

Definition at line 78 of file class.SurveySingleChoiceQuestion.php.

References SurveyQuestion\$db, $ilDB, $ilUser, $result, and SurveyQuestion\$user.

79  {
81  $ilDB = $this->db;
82 
83  $result = $ilDB->queryF(
84  "SELECT svy_category.* FROM svy_category, svy_phrase_cat WHERE svy_phrase_cat.category_fi = svy_category.category_id AND svy_phrase_cat.phrase_fi = %s AND (svy_category.owner_fi = 0 OR svy_category.owner_fi = %s) ORDER BY svy_phrase_cat.sequence",
85  array('integer', 'integer'),
86  array($phrase_id, $ilUser->getId())
87  );
88  while ($row = $ilDB->fetchAssoc($result)) {
89  $neutral = $row["neutral"];
90  if (($row["defaultvalue"] == 1) and ($row["owner_fi"] == 0)) {
91  $this->categories->addCategory($this->lng->txt($row["title"]), 0, $neutral);
92  } else {
93  $this->categories->addCategory($row["title"], 0, $neutral);
94  }
95  }
96  }
$result
$ilUser
Definition: imgupload.php:18
global $ilDB

◆ addStandardNumbers()

SurveySingleChoiceQuestion::addStandardNumbers (   $lower_limit,
  $upper_limit 
)

Adds standard numbers as categories.

Parameters
integer$lower_limitThe lower limit
integer$upper_limitThe upper limit public

Definition at line 370 of file class.SurveySingleChoiceQuestion.php.

References $i.

371  {
372  for ($i = $lower_limit; $i <= $upper_limit; $i++) {
373  $this->categories->addCategory($i);
374  }
375  }
$i
Definition: metadata.php:24

◆ checkUserInput()

SurveySingleChoiceQuestion::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 public

Definition at line 473 of file class.SurveySingleChoiceQuestion.php.

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

474  {
475  $entered_value = $post_data[$this->getId() . "_value"];
476 
477  $this->log->debug("Entered value = " . $entered_value);
478 
479  if ((!$this->getObligatory($survey_id)) && (strlen($entered_value) == 0)) {
480  return "";
481  }
482 
483  if (strlen($entered_value) == 0) {
484  return $this->lng->txt("question_not_checked");
485  }
486 
487  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
488  $cat = $this->categories->getCategory($i);
489  if ($cat->other) {
490  if ($i == $entered_value) {
491  if (array_key_exists($this->getId() . "_" . $entered_value . "_other", $post_data) && !strlen($post_data[$this->getId() . "_" . $entered_value . "_other"])) {
492  return $this->lng->txt("question_mr_no_other_answer");
493  }
494  } else {
495  if (strlen($post_data[$this->getId() . "_" . $i . "_other"])) {
496  return $this->lng->txt("question_sr_no_other_answer_checked");
497  }
498  }
499  }
500  }
501 
502  return "";
503  }
getObligatory($survey_id="")
Gets the obligatory state of the question.
getId()
Gets the id of the SurveyQuestion object.
$i
Definition: metadata.php:24
+ Here is the call graph for this function:

◆ getAdditionalTableName()

SurveySingleChoiceQuestion::getAdditionalTableName ( )

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

Returns
string The additional table name public

Definition at line 433 of file class.SurveySingleChoiceQuestion.php.

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

434  {
435  return "svy_qst_sc";
436  }
+ Here is the caller graph for this function:

◆ getAvailableRelations()

SurveySingleChoiceQuestion::getAvailableRelations ( )

Returns the available relations for the question.

Returns
array An array containing the available relations public

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

578  {
579  return array("<", "<=", "=", "<>", ">=", ">");
580  }

◆ getCategories()

SurveySingleChoiceQuestion::getCategories ( )

Definition at line 632 of file class.SurveySingleChoiceQuestion.php.

References $categories.

◆ getCategoriesForPhrase()

& SurveySingleChoiceQuestion::getCategoriesForPhrase (   $phrase_id)

Gets the available categories for a given phrase.

Parameters
integer$phrase_idThe database id of the given phrase
Returns
array All available categories public

Definition at line 53 of file class.SurveySingleChoiceQuestion.php.

References $categories, SurveyQuestion\$db, $ilDB, and $result.

54  {
55  $ilDB = $this->db;
56  $categories = array();
57  $result = $ilDB->queryF(
58  "SELECT svy_category.* FROM svy_category, svy_phrase_cat WHERE svy_phrase_cat.category_fi = svy_category.category_id AND svy_phrase_cat.phrase_fi = %s ORDER BY svy_phrase_cat.sequence",
59  array('integer'),
60  array($phrase_id)
61  );
62  while ($row = $ilDB->fetchAssoc($result)) {
63  if (($row["defaultvalue"] == 1) and ($row["owner_fi"] == 0)) {
64  $categories[$row["category_id"]] = $this->lng->txt($row["title"]);
65  } else {
66  $categories[$row["category_id"]] = $row["title"];
67  }
68  }
69  return $categories;
70  }
$result
global $ilDB

◆ getPreconditionOptions()

SurveySingleChoiceQuestion::getPreconditionOptions ( )

Returns the options for preconditions.

Returns
array

Definition at line 587 of file class.SurveySingleChoiceQuestion.php.

References $i, and SurveyQuestion\$lng.

Referenced by getPreconditionSelectValue().

588  {
589  $lng = $this->lng;
590 
591  $options = array();
592  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
593  $category = $this->categories->getCategory($i);
594  $options[$category->scale - 1] = $category->scale . " - " . $category->title;
595  }
596  return $options;
597  }
$i
Definition: metadata.php:24
+ Here is the caller graph for this function:

◆ getPreconditionSelectValue()

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

Creates a form property for the precondition value.

Returns
The ILIAS form element public

Definition at line 605 of file class.SurveySingleChoiceQuestion.php.

References SurveyQuestion\$title, and getPreconditionOptions().

606  {
607  $step3 = new ilSelectInputGUI($title, $variable);
608  $options = $this->getPreconditionOptions();
609  $step3->setOptions($options);
610  $step3->setValue($default);
611  return $step3;
612  }
getPreconditionOptions()
Returns the options for preconditions.
+ Here is the call graph for this function:

◆ getPreconditionValueOutput()

SurveySingleChoiceQuestion::getPreconditionValueOutput (   $value)

Returns the output for a precondition value.

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

Definition at line 621 of file class.SurveySingleChoiceQuestion.php.

622  {
623  // #18136
624  $category = $this->categories->getCategoryForScale($value + 1);
625 
626  // #17895 - see getPreconditionOptions()
627  return $category->scale .
628  " - " .
629  ((strlen($category->title)) ? $category->title : $this->lng->txt('other_answer'));
630  }

◆ getQuestionDataArray()

SurveySingleChoiceQuestion::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 public

Definition at line 105 of file class.SurveySingleChoiceQuestion.php.

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

106  {
107  $ilDB = $this->db;
108 
109  $result = $ilDB->queryF(
110  "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",
111  array('integer'),
112  array($id)
113  );
114  if ($result->numRows() == 1) {
115  return $ilDB->fetchAssoc($result);
116  } else {
117  return array();
118  }
119  }
$result
getAdditionalTableName()
Returns the name of the additional question data table in the database.
global $ilDB
+ Here is the call graph for this function:

◆ getQuestionType()

SurveySingleChoiceQuestion::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question public

Definition at line 422 of file class.SurveySingleChoiceQuestion.php.

423  {
424  return "SurveySingleChoiceQuestion";
425  }

◆ getWorkingDataFromUserInput()

& SurveySingleChoiceQuestion::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 public

Definition at line 444 of file class.SurveySingleChoiceQuestion.php.

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

445  {
446  $entered_value = $post_data[$this->getId() . "_value"];
447  $data = array();
448  if (strlen($entered_value)) {
449  array_push($data, array("value" => $entered_value, "textanswer" => $post_data[$this->getId() . '_' . $entered_value . '_other']));
450  }
451  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
452  $cat = $this->categories->getCategory($i);
453  if ($cat->other) {
454  if ($i != $entered_value) {
455  if (strlen($post_data[$this->getId() . "_" . $i . "_other"])) {
456  array_push($data, array("value" => $i, "textanswer" => $post_data[$this->getId() . '_' . $i . '_other'], "uncheck" => true));
457  }
458  }
459  }
460  }
461  return $data;
462  }
$data
Definition: storeScorm.php:23
getId()
Gets the id of the SurveyQuestion object.
$i
Definition: metadata.php:24
+ Here is the call graph for this function:

◆ importAdditionalMetadata()

SurveySingleChoiceQuestion::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 public

Definition at line 352 of file class.SurveySingleChoiceQuestion.php.

References SurveyQuestion\setOrientation().

353  {
354  foreach ($a_meta as $key => $value) {
355  switch ($value["label"]) {
356  case "orientation":
357  $this->setOrientation($value["entry"]);
358  break;
359  }
360  }
361  }
setOrientation($orientation=0)
Sets the orientation of the question output.
+ Here is the call graph for this function:

◆ importResponses()

SurveySingleChoiceQuestion::importResponses (   $a_data)

Import response data from the question import file.

Returns
array $a_data Array containing the response data public

Definition at line 543 of file class.SurveySingleChoiceQuestion.php.

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

544  {
545  foreach ($a_data as $id => $data) {
546  $categorytext = "";
547  foreach ($data["material"] as $material) {
548  $categorytext .= $material["text"];
549  }
550  $this->categories->addCategory(
551  $categorytext,
552  strlen($data['other']) ? $data['other'] : 0,
553  strlen($data['neutral']) ? $data['neutral'] : 0,
554  strlen($data['label']) ? $data['label'] : null,
555  strlen($data['scale']) ? $data['scale'] : null
556  );
557  }
558  }
$data
Definition: storeScorm.php:23

◆ insertXML()

SurveySingleChoiceQuestion::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 public

Definition at line 271 of file class.SurveySingleChoiceQuestion.php.

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

Referenced by toXML().

272  {
273  $attrs = array(
274  "id" => $this->getId(),
275  "title" => $this->getTitle(),
276  "type" => $this->getQuestiontype(),
277  "obligatory" => $this->getObligatory()
278  );
279  $a_xml_writer->xmlStartTag("question", $attrs);
280 
281  $a_xml_writer->xmlElement("description", null, $this->getDescription());
282  $a_xml_writer->xmlElement("author", null, $this->getAuthor());
283  if (strlen($this->label)) {
284  $attrs = array(
285  "label" => $this->label,
286  );
287  } else {
288  $attrs = array();
289  }
290  $a_xml_writer->xmlStartTag("questiontext", $attrs);
291  $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
292  $a_xml_writer->xmlEndTag("questiontext");
293 
294  $a_xml_writer->xmlStartTag("responses");
295 
296  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
297  $attrs = array(
298  "id" => $i
299  );
300  if (strlen($this->categories->getCategory($i)->other)) {
301  $attrs['other'] = $this->categories->getCategory($i)->other;
302  }
303  if (strlen($this->categories->getCategory($i)->neutral)) {
304  $attrs['neutral'] = $this->categories->getCategory($i)->neutral;
305  }
306  if (strlen($this->categories->getCategory($i)->label)) {
307  $attrs['label'] = $this->categories->getCategory($i)->label;
308  }
309  if (strlen($this->categories->getCategory($i)->scale)) {
310  $attrs['scale'] = $this->categories->getCategory($i)->scale;
311  }
312  $a_xml_writer->xmlStartTag("response_single", $attrs);
313  $this->addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
314  $a_xml_writer->xmlEndTag("response_single");
315  }
316 
317  $a_xml_writer->xmlEndTag("responses");
318 
319  if (count($this->material)) {
320  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches)) {
321  $attrs = array(
322  "label" => $this->material["title"]
323  );
324  $a_xml_writer->xmlStartTag("material", $attrs);
325  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
326  if (strcmp($matches[1], "") != 0) {
327  $intlink = $this->material["internal_link"];
328  }
329  $a_xml_writer->xmlElement("mattext", null, $intlink);
330  $a_xml_writer->xmlEndTag("material");
331  }
332  }
333 
334  $a_xml_writer->xmlStartTag("metadata");
335  $a_xml_writer->xmlStartTag("metadatafield");
336  $a_xml_writer->xmlElement("fieldlabel", null, "orientation");
337  $a_xml_writer->xmlElement("fieldentry", null, $this->getOrientation());
338  $a_xml_writer->xmlEndTag("metadatafield");
339  $a_xml_writer->xmlEndTag("metadata");
340 
341  $a_xml_writer->xmlEndTag("question");
342  }
getAuthor()
Gets the authors name of the SurveyQuestion object.
getTitle()
Gets the title string of the SurveyQuestion object.
getObligatory($survey_id="")
Gets the obligatory state of the question.
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getOrientation()
Gets the orientation of the question output.
getId()
Gets the id of the SurveyQuestion object.
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.
getDescription()
Gets the description string of the SurveyQuestion object.
$i
Definition: metadata.php:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isComplete()

SurveySingleChoiceQuestion::isComplete ( )

Returns true if the question is complete for use.

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

Definition at line 172 of file class.SurveySingleChoiceQuestion.php.

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

173  {
174  if (
175  strlen($this->getTitle()) &&
176  strlen($this->getAuthor()) &&
177  strlen($this->getQuestiontext()) &&
178  $this->categories->getCategoryCount()
179  ) {
180  return 1;
181  } else {
182  return 0;
183  }
184  }
getAuthor()
Gets the authors name of the SurveyQuestion object.
getTitle()
Gets the title string of the SurveyQuestion object.
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
+ Here is the call graph for this function:

◆ loadFromDb()

SurveySingleChoiceQuestion::loadFromDb (   $id)

Loads a SurveySingleChoiceQuestion object from the database.

Parameters
integer$idThe database id of the single choice survey question public

Definition at line 127 of file class.SurveySingleChoiceQuestion.php.

References $data, SurveyQuestion\$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().

128  {
129  $ilDB = $this->db;
130 
131  $result = $ilDB->queryF(
132  "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",
133  array('integer'),
134  array($id)
135  );
136  if ($result->numRows() == 1) {
137  $data = $ilDB->fetchAssoc($result);
138  $this->setId($data["question_id"]);
139  $this->setTitle($data["title"]);
140  $this->label = $data['label'];
141  $this->setDescription($data["description"]);
142  $this->setObjId($data["obj_fi"]);
143  $this->setAuthor($data["author"]);
144  $this->setOwner($data["owner_fi"]);
145  $this->setQuestiontext(ilRTE::_replaceMediaObjectImageSrc($data["questiontext"], 1));
146  $this->setObligatory($data["obligatory"]);
147  $this->setComplete($data["complete"]);
148  $this->setOriginalId($data["original_id"]);
149  $this->setOrientation($data["orientation"]);
150 
151  $this->categories->flushCategories();
152  $result = $ilDB->queryF(
153  "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",
154  array('integer'),
155  array($id)
156  );
157  if ($result->numRows() > 0) {
158  while ($data = $ilDB->fetchAssoc($result)) {
159  $this->categories->addCategory($data["title"], $data["other"], $data["neutral"], null, ($data['scale']) ? $data['scale'] : ($data['sequence'] + 1));
160  }
161  }
162  }
163  parent::loadFromDb($id);
164  }
$data
Definition: storeScorm.php:23
$result
setObligatory($obligatory=1)
Sets the obligatory state of the question.
setOrientation($orientation=0)
Sets the orientation of the question output.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setId($id=-1)
Sets the id of the SurveyQuestion object.
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...
setOwner($owner="")
Sets the creator/owner ID of the SurveyQuestion object.
setComplete($a_complete)
Sets the complete state of the question.
setOriginalId($original_id)
setQuestiontext($questiontext="")
Sets the questiontext of the SurveyQuestion object.
setAuthor($author="")
Sets the authors name of the SurveyQuestion object.
setDescription($description="")
Sets the description string of the SurveyQuestion object.
global $ilDB
setObjId($obj_id=0)
Set the reference id of the container object.
setTitle($title="")
Sets the title string of the SurveyQuestion object.
+ Here is the call graph for this function:

◆ saveCategoriesToDb()

SurveySingleChoiceQuestion::saveCategoriesToDb ( )

Definition at line 217 of file class.SurveySingleChoiceQuestion.php.

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

Referenced by saveToDb().

218  {
219  $ilDB = $this->db;
220 
221  $this->log->debug("DELETE from svy_variable before the INSERT into svy_variable. if scale > 0 we get scale value else we get null");
222 
223  $affectedRows = $ilDB->manipulateF(
224  "DELETE FROM svy_variable WHERE question_fi = %s",
225  array('integer'),
226  array($this->getId())
227  );
228 
229  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
230  $cat = $this->categories->getCategory($i);
231  $category_id = $this->saveCategoryToDb($cat->title, $cat->neutral);
232  $next_id = $ilDB->nextId('svy_variable');
233  $affectedRows = $ilDB->manipulateF(
234  "INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, other, sequence, scale, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
235  array('integer','integer','integer','float','integer','integer', 'integer','integer'),
236  array($next_id, $category_id, $this->getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
237  );
238 
239  $debug_scale = ($cat->scale > 0) ? $cat->scale : null;
240  $this->log->debug("INSERT INTO svy_variable category_fi= " . $category_id . " question_fi= " . $this->getId() . " value1= " . ($i + 1) . " other= " . $cat->other . " sequence= " . $i . " scale =" . $debug_scale);
241  }
242  $this->saveCompletionStatus();
243  }
saveCategoryToDb($categorytext, $neutral=0)
Saves a category to the database.
saveCompletionStatus($original_id="")
Saves the complete flag to the database.
getId()
Gets the id of the SurveyQuestion object.
global $ilDB
$i
Definition: metadata.php:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ savePhrase()

SurveySingleChoiceQuestion::savePhrase (   $title)

Saves a set of categories to a default phrase.

Parameters
array$phrasesThe database ids of the seleted phrases
string$titleThe title of the default phrase public

Definition at line 384 of file class.SurveySingleChoiceQuestion.php.

References $_SESSION, $data, SurveyQuestion\$db, $ilDB, $ilUser, SurveyQuestion\$title, and SurveyQuestion\$user.

385  {
387  $ilDB = $this->db;
388 
389  $next_id = $ilDB->nextId('svy_phrase');
390  $affectedRows = $ilDB->manipulateF(
391  "INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
392  array('integer','text','text','integer','integer'),
393  array($next_id, $title, 1, $ilUser->getId(), time())
394  );
395  $phrase_id = $next_id;
396 
397  $counter = 1;
398  foreach ($_SESSION['save_phrase_data'] as $data) {
399  $next_id = $ilDB->nextId('svy_category');
400  $affectedRows = $ilDB->manipulateF(
401  "INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
402  array('integer','text','text','integer','integer','text'),
403  array($next_id, $data['answer'], 1, $ilUser->getId(), time(), $data['neutral'])
404  );
405  $category_id = $next_id;
406  $next_id = $ilDB->nextId('svy_phrase_cat');
407  $affectedRows = $ilDB->manipulateF(
408  "INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence, other, scale) VALUES (%s, %s, %s, %s, %s, %s)",
409  array('integer', 'integer', 'integer','integer', 'integer', 'integer'),
410  array($next_id, $phrase_id, $category_id, $counter, ($data['other']) ? 1 : 0, $data['scale'])
411  );
412  $counter++;
413  }
414  }
$data
Definition: storeScorm.php:23
$_SESSION["AccountId"]
$ilUser
Definition: imgupload.php:18
global $ilDB

◆ saveToDb()

SurveySingleChoiceQuestion::saveToDb (   $original_id = "")

Saves a SurveySingleChoiceQuestion object to a database.

public

Definition at line 191 of file class.SurveySingleChoiceQuestion.php.

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

192  {
193  $ilDB = $this->db;
194 
195  $affectedRows = parent::saveToDb($original_id);
196  if ($affectedRows == 1) {
197  $this->log->debug("Before save Category-> DELETE from svy_qst_sc WHERE question_fi = " . $this->getId() . " AND INSERT again the same id and orientation in svy_qst_sc");
198  $affectedRows = $ilDB->manipulateF(
199  "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
200  array('integer'),
201  array($this->getId())
202  );
203  $affectedRows = $ilDB->manipulateF(
204  "INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, orientation) VALUES (%s, %s)",
205  array('integer', 'text'),
206  array(
207  $this->getId(),
208  $this->getOrientation()
209  )
210  );
211 
212  $this->saveMaterial();
213  $this->saveCategoriesToDb();
214  }
215  }
getAdditionalTableName()
Returns the name of the additional question data table in the database.
getOrientation()
Gets the orientation of the question output.
getId()
Gets the id of the SurveyQuestion object.
saveMaterial()
save material to db
global $ilDB
+ Here is the call graph for this function:

◆ saveUserInput()

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

Definition at line 505 of file class.SurveySingleChoiceQuestion.php.

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

506  {
507  $ilDB = $this->db;
508 
509  $entered_value = $post_data[$this->getId() . "_value"];
510 
511  if ($a_return) {
512  return array(array("value" => $entered_value,
513  "textanswer" => $post_data[$this->getId() . "_" . $entered_value . "_other"]));
514  }
515  if (strlen($entered_value) == 0) {
516  return;
517  }
518 
519  $next_id = $ilDB->nextId('svy_answer');
520  #20216
521  $fields = array();
522  $fields['answer_id'] = array("integer", $next_id);
523  $fields['question_fi'] = array("integer", $this->getId());
524  $fields['active_fi'] = array("integer", $active_id);
525  $fields['value'] = array("float", (strlen($entered_value)) ? $entered_value : null);
526  $fields['textanswer'] = array("clob", ($post_data[$this->getId() . "_" . $entered_value . "_other"]) ?
527  $this->stripSlashesAddSpaceFallback($post_data[$this->getId() . "_" . $entered_value . "_other"]) : null);
528  $fields['tstamp'] = array("integer", time());
529 
530  $affectedRows = $ilDB->insert("svy_answer", $fields);
531 
532  $debug_value = (strlen($entered_value)) ? $entered_value : "NULL";
533  $debug_answer = ($post_data[$this->getId() . "_" . $entered_value . "_other"]) ? $post_data[$this->getId() . "_" . $entered_value . "_other"] : "NULL";
534  $this->log->debug("INSERT svy_answer answer_id=" . $next_id . " question_fi=" . $this->getId() . " active_fi=" . $active_id . " value=" . $debug_value . " textanswer=" . $debug_answer);
535  }
stripSlashesAddSpaceFallback($a_str)
Strip slashes with add space fallback, see https://mantis.ilias.de/view.php?id=19727 and https://mant...
getId()
Gets the id of the SurveyQuestion object.
global $ilDB
+ Here is the call graph for this function:

◆ toXML()

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

Returns an xml representation of the question.

Returns
string The xml representation of the question public

Definition at line 251 of file class.SurveySingleChoiceQuestion.php.

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

252  {
253  $a_xml_writer = new ilXmlWriter;
254  $a_xml_writer->xmlHeader();
255  $this->insertXML($a_xml_writer, $a_include_header, $obligatory_state);
256  $xml = $a_xml_writer->xmlDumpMem(false);
257  if (!$a_include_header) {
258  $pos = strpos($xml, "?>");
259  $xml = substr($xml, $pos + 2);
260  }
261  return $xml;
262  }
XML writer class.
insertXML(&$a_xml_writer, $a_include_header=true)
Adds the question XML to a given XMLWriter object.
xmlHeader()
Writes xml header public.
$xml
Definition: metadata.php:332
+ Here is the call graph for this function:

◆ usableForPrecondition()

SurveySingleChoiceQuestion::usableForPrecondition ( )

Returns if the question is usable for preconditions.

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

Definition at line 566 of file class.SurveySingleChoiceQuestion.php.

567  {
568  return true;
569  }

Field Documentation

◆ $categories

SurveySingleChoiceQuestion::$categories

Definition at line 20 of file class.SurveySingleChoiceQuestion.php.

Referenced by getCategories(), and getCategoriesForPhrase().


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