ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
SurveySingleChoiceQuestion 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 SurveySingleChoiceQuestion:
+ Collaboration diagram for SurveySingleChoiceQuestion:

Public Member Functions

 __construct (string $title="", string $description="", string $author="", string $questiontext="", int $owner=-1, int $orientation=1)
 
 getCategoriesForPhrase (int $phrase_id)
 Gets the available categories for a given phrase. More...
 
 addPhrase (int $phrase_id)
 Adds a phrase to the question. More...
 
 getQuestionDataArray (int $id)
 
 loadFromDb (int $question_id)
 
 isComplete ()
 
 saveToDb (int $original_id=0)
 
 saveCategoriesToDb ()
 
 toXML (bool $a_include_header=true, bool $obligatory_state=false)
 
 insertXML (ilXmlWriter $a_xml_writer, bool $a_include_header=true)
 
 importAdditionalMetadata (array $a_meta)
 
 addStandardNumbers (int $lower_limit, int $upper_limit)
 Adds standard numbers as categories. More...
 
 savePhrase (string $title)
 Saves a set of categories to a default phrase note: data comes from session. More...
 
 getQuestionType ()
 
 getAdditionalTableName ()
 
 getWorkingDataFromUserInput (array $post_data)
 
 checkUserInput (array $post_data, int $survey_id)
 Checks the input of the active user for obligatory status and entered values. More...
 
 saveUserInput (array $post_data, int $active_id, bool $a_return=false)
 
 importResponses (array $a_data)
 
 usableForPrecondition ()
 
 getAvailableRelations ()
 
 getPreconditionOptions ()
 
 getPreconditionSelectValue (string $default, string $title, string $variable)
 
 getPreconditionValueOutput (string $value)
 
 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...
 
 saveMaterial ()
 
 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 ()
 
 getPhrase (int $phrase_id)
 Returns a phrase title for phrase id. More...
 
 phraseExists (string $title)
 Returns true if the phrase title already exists for the current user(!) More...
 
 deleteMaterials (array $a_array)
 
 duplicateMaterials (int $question_id)
 Duplicates the materials of a question. More...
 
 addMaterial (ilSurveyMaterial $obj_material)
 
 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, string $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)
 
static getCompressCompareString (SurveySingleChoiceQuestion $q)
 
- 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
 

Protected Member Functions

 isSumScoreValid (int $nr_answer_records)
 

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 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 27 of file class.SurveySingleChoiceQuestion.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

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

38  {
39  global $DIC;
40 
41  $this->db = $DIC->database();
42  $this->user = $DIC->user();
43  $this->lng = $DIC->language();
45 
46  $this->orientation = $orientation;
47  $this->categories = new SurveyCategories();
48  }
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ addPhrase()

SurveySingleChoiceQuestion::addPhrase ( int  $phrase_id)

Adds a phrase to the question.

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

References SurveyQuestion\$db, $ilDB, $ilUser, SurveyQuestion\$user, ILIAS\Repository\int(), and ILIAS\Repository\lng().

75  : void
76  {
78  $ilDB = $this->db;
79 
80  $result = $ilDB->queryF(
81  "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",
82  array('integer', 'integer'),
83  array($phrase_id, $ilUser->getId())
84  );
85  while ($row = $ilDB->fetchAssoc($result)) {
86  $neutral = $row["neutral"];
87  if ((int) $row["defaultvalue"] === 1 && (int) $row["owner_fi"] === 0) {
88  $this->categories->addCategory($this->lng->txt($row["title"]), 0, $neutral);
89  } else {
90  $this->categories->addCategory($row["title"], 0, $neutral);
91  }
92  }
93  }
$ilUser
Definition: imgupload.php:34
+ Here is the call graph for this function:

◆ addStandardNumbers()

SurveySingleChoiceQuestion::addStandardNumbers ( int  $lower_limit,
int  $upper_limit 
)

Adds standard numbers as categories.

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

References $i.

326  : void {
327  for ($i = $lower_limit; $i <= $upper_limit; $i++) {
328  $this->categories->addCategory($i);
329  }
330  }
$i
Definition: metadata.php:41

◆ checkUserInput()

SurveySingleChoiceQuestion::checkUserInput ( array  $post_data,
int  $survey_id 
)

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

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

References $i, SurveyQuestion\getId(), SurveyQuestion\getObligatory(), and ILIAS\Repository\lng().

412  : string {
413  $entered_value = $post_data[$this->getId() . "_value"] ?? "";
414 
415  $this->log->debug("Entered value = " . $entered_value);
416 
417  if ((!$this->getObligatory()) && (strlen($entered_value) == 0)) {
418  return "";
419  }
420 
421  if (strlen($entered_value) == 0) {
422  return $this->lng->txt("question_not_checked");
423  }
424 
425  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
426  $cat = $this->categories->getCategory($i);
427  if ($cat->other) {
428  if ($i == $entered_value) {
429  if (array_key_exists($this->getId() . "_" . $entered_value . "_other", $post_data) && !strlen($post_data[$this->getId() . "_" . $entered_value . "_other"])) {
430  return $this->lng->txt("question_mr_no_other_answer");
431  }
432  } elseif (strlen($post_data[$this->getId() . "_" . $i . "_other"] ?? "")) {
433  return $this->lng->txt("question_sr_no_other_answer_checked");
434  }
435  }
436  }
437 
438  return "";
439  }
$i
Definition: metadata.php:41
+ Here is the call graph for this function:

◆ getAdditionalTableName()

SurveySingleChoiceQuestion::getAdditionalTableName ( )

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

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

374  : string
375  {
376  return "svy_qst_sc";
377  }
+ Here is the caller graph for this function:

◆ getAvailableRelations()

SurveySingleChoiceQuestion::getAvailableRelations ( )

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

499  : array
500  {
501  return array("<", "<=", "=", "<>", ">=", ">");
502  }

◆ getCategories()

SurveySingleChoiceQuestion::getCategories ( )

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

References $categories.

546  {
547  return $this->categories;
548  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ getCategoriesForPhrase()

SurveySingleChoiceQuestion::getCategoriesForPhrase ( int  $phrase_id)

Gets the available categories for a given phrase.

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

References $categories, SurveyQuestion\$db, $ilDB, ILIAS\Repository\int(), and ILIAS\Repository\lng().

53  : array
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 ((int) $row["defaultvalue"] === 1 && (int) $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  }
+ Here is the call graph for this function:

◆ getCompressCompareString()

static SurveySingleChoiceQuestion::getCompressCompareString ( SurveySingleChoiceQuestion  $q)
static

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

References $i.

596  : string {
597  $str = "";
598  for ($i = 0; $i < $q->categories->getCategoryCount(); $i++) {
599  $cat = $q->categories->getCategory($i);
600  $str .= ":" . $cat->scale . ":" . $cat->title;
601  }
602  return $str;
603  }
$i
Definition: metadata.php:41

◆ getMaxSumScore()

static SurveySingleChoiceQuestion::getMaxSumScore ( int  $survey_id)
static

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

References SurveyQuestion\$db, $DIC, ilDBInterface\fetchAssoc(), and ilDBInterface\queryF().

550  : int
551  {
552  global $DIC;
553 
554  // we need max scale values of single choice questions (type 2)
555  $db = $DIC->database();
556  $set = $db->queryF(
557  "SELECT SUM(max_sum_score) sum_sum_score FROM (SELECT MAX(scale) max_sum_score FROM svy_svy_qst sq " .
558  "JOIN svy_question q ON (sq.question_fi = q.question_id) " .
559  "JOIN svy_variable v ON (v.question_fi = q.question_id) " .
560  "WHERE sq.survey_fi = %s AND q.questiontype_fi = %s " .
561  "GROUP BY (q.question_id)) x",
562  ["integer", "integer"],
563  [$survey_id, 2]
564  );
565  $rec = $db->fetchAssoc($set);
566  return (int) $rec["sum_sum_score"];
567  }
fetchAssoc(ilDBStatement $statement)
global $DIC
Definition: feed.php:28
queryF(string $query, array $types, array $values)
+ Here is the call graph for this function:

◆ getPreconditionOptions()

SurveySingleChoiceQuestion::getPreconditionOptions ( )

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

References $i.

Referenced by getPreconditionSelectValue().

504  : array
505  {
506  $options = array();
507  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
508  $category = $this->categories->getCategory($i);
509  $options[$category->scale - 1] = $category->scale . " - " . $category->title;
510  }
511  return $options;
512  }
$i
Definition: metadata.php:41
+ Here is the caller graph for this function:

◆ getPreconditionSelectValue()

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

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

References getPreconditionOptions().

518  : ?ilFormPropertyGUI {
519  $step3 = new ilSelectInputGUI($title, $variable);
520  $options = $this->getPreconditionOptions();
521  $step3->setOptions($options);
522  $step3->setValue($default);
523  return $step3;
524  }
This class represents a property in a property form.
+ Here is the call graph for this function:

◆ getPreconditionValueOutput()

SurveySingleChoiceQuestion::getPreconditionValueOutput ( string  $value)

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

References SurveyQuestion\$title, and ILIAS\Repository\lng().

528  : string {
529  // #18136
530  $category = $this->categories->getCategoryForScale((int) $value + 1);
531 
532  $scale = "";
533  $title = "";
534  if ($category) {
535  $scale = $category->scale;
536  $title = $category->title;
537  }
538 
539  // #17895 - see getPreconditionOptions()
540  return $scale .
541  " - " .
542  ((strlen($title)) ? $title : $this->lng->txt('other_answer'));
543  }
+ Here is the call graph for this function:

◆ getQuestionDataArray()

SurveySingleChoiceQuestion::getQuestionDataArray ( int  $id)

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

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

95  : array
96  {
97  $ilDB = $this->db;
98 
99  $result = $ilDB->queryF(
100  "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",
101  array('integer'),
102  array($id)
103  );
104  if ($result->numRows() === 1) {
105  return $ilDB->fetchAssoc($result);
106  } else {
107  return array();
108  }
109  }
+ Here is the call graph for this function:

◆ getQuestionType()

SurveySingleChoiceQuestion::getQuestionType ( )

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

Referenced by insertXML().

369  : string
370  {
371  return "SurveySingleChoiceQuestion";
372  }
+ Here is the caller graph for this function:

◆ getWorkingDataFromUserInput()

SurveySingleChoiceQuestion::getWorkingDataFromUserInput ( array  $post_data)

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

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

381  : array {
382  $entered_value = $post_data[$this->getId() . "_value"] ?? "";
383  $data = array();
384  if (strlen($entered_value)) {
385  $data[] = array("value" => $entered_value,
386  "textanswer" => $post_data[$this->getId() . '_' . $entered_value . '_other'] ?? ""
387  );
388  }
389  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
390  $cat = $this->categories->getCategory($i);
391  if ($cat->other) {
392  if ($i != $entered_value) {
393  if (strlen($post_data[$this->getId() . "_" . $i . "_other"] ?? "")) {
394  $data[] = array("value" => $i,
395  "textanswer" => $post_data[$this->getId() . '_' . $i . '_other'] ?? "",
396  "uncheck" => true
397  );
398  }
399  }
400  }
401  }
402  return $data;
403  }
$i
Definition: metadata.php:41
+ Here is the call graph for this function:

◆ importAdditionalMetadata()

SurveySingleChoiceQuestion::importAdditionalMetadata ( array  $a_meta)

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

References ILIAS\LTI\ToolProvider\$key, and SurveyQuestion\setOrientation().

309  : void
310  {
311  foreach ($a_meta as $key => $value) {
312  switch ($value["label"]) {
313  case "orientation":
314  $this->setOrientation($value["entry"]);
315  break;
316  }
317  }
318  }
setOrientation(int $orientation=0)
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:

◆ importResponses()

SurveySingleChoiceQuestion::importResponses ( array  $a_data)

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

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

477  : void
478  {
479  foreach ($a_data as $id => $data) {
480  $categorytext = "";
481  foreach ($data["material"] as $material) {
482  $categorytext .= $material["text"];
483  }
484  $this->categories->addCategory(
485  $categorytext,
486  strlen($data['other']) ? $data['other'] : 0,
487  strlen($data['neutral']) ? $data['neutral'] : 0,
488  strlen($data['label']) ? $data['label'] : null,
489  strlen($data['scale']) ? $data['scale'] : null
490  );
491  }
492  }

◆ insertXML()

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

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

References $i, SurveyQuestion\addMaterialTag(), SurveyQuestion\getAuthor(), SurveyQuestion\getDescription(), SurveyQuestion\getId(), SurveyQuestion\getObligatory(), SurveyQuestion\getOrientation(), SurveyQuestion\getQuestiontext(), getQuestionType(), SurveyQuestion\getTitle(), IL_INST_ID, ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by toXML().

237  : void {
238  $attrs = array(
239  "id" => $this->getId(),
240  "title" => $this->getTitle(),
241  "type" => $this->getQuestionType(),
242  "obligatory" => $this->getObligatory()
243  );
244  $a_xml_writer->xmlStartTag("question", $attrs);
245 
246  $a_xml_writer->xmlElement("description", null, $this->getDescription());
247  $a_xml_writer->xmlElement("author", null, $this->getAuthor());
248  if (strlen($this->label)) {
249  $attrs = array(
250  "label" => $this->label,
251  );
252  } else {
253  $attrs = array();
254  }
255  $a_xml_writer->xmlStartTag("questiontext", $attrs);
256  $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
257  $a_xml_writer->xmlEndTag("questiontext");
258 
259  $a_xml_writer->xmlStartTag("responses");
260 
261  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
262  $attrs = array(
263  "id" => $i
264  );
265  if (strlen($this->categories->getCategory($i)->other)) {
266  $attrs['other'] = $this->categories->getCategory($i)->other;
267  }
268  if (strlen($this->categories->getCategory($i)->neutral)) {
269  $attrs['neutral'] = $this->categories->getCategory($i)->neutral;
270  }
271  if (strlen($this->categories->getCategory($i)->label)) {
272  $attrs['label'] = $this->categories->getCategory($i)->label;
273  }
274  if (strlen($this->categories->getCategory($i)->scale)) {
275  $attrs['scale'] = $this->categories->getCategory($i)->scale;
276  }
277  $a_xml_writer->xmlStartTag("response_single", $attrs);
278  $this->addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
279  $a_xml_writer->xmlEndTag("response_single");
280  }
281 
282  $a_xml_writer->xmlEndTag("responses");
283 
284  if (count($this->material)) {
285  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"] ?? "", $matches)) {
286  $attrs = array(
287  "label" => $this->material["title"]
288  );
289  $a_xml_writer->xmlStartTag("material", $attrs);
290  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
291  if (strcmp($matches[1], "") != 0) {
292  $intlink = $this->material["internal_link"];
293  }
294  $a_xml_writer->xmlElement("mattext", null, $intlink);
295  $a_xml_writer->xmlEndTag("material");
296  }
297  }
298 
299  $a_xml_writer->xmlStartTag("metadata");
300  $a_xml_writer->xmlStartTag("metadatafield");
301  $a_xml_writer->xmlElement("fieldlabel", null, "orientation");
302  $a_xml_writer->xmlElement("fieldentry", null, $this->getOrientation());
303  $a_xml_writer->xmlEndTag("metadatafield");
304  $a_xml_writer->xmlEndTag("metadata");
305 
306  $a_xml_writer->xmlEndTag("question");
307  }
const IL_INST_ID
Definition: constants.php:40
xmlEndTag(string $tag)
Writes an endtag.
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.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
$i
Definition: metadata.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isComplete()

SurveySingleChoiceQuestion::isComplete ( )

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

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

150  : bool
151  {
152  if (
153  $this->getTitle() !== '' &&
154  $this->getAuthor() !== '' &&
155  $this->getQuestiontext() !== '' &&
156  $this->categories->getCategoryCount()
157  ) {
158  return true;
159  } else {
160  return false;
161  }
162  }
+ Here is the call graph for this function:

◆ isSumScoreValid()

SurveySingleChoiceQuestion::isSumScoreValid ( int  $nr_answer_records)
protected

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

References SurveyQuestion\_instanciateQuestion().

569  : bool
570  {
571  if ($nr_answer_records == 1) {
572  return true;
573  }
574  return false;
575  }
+ Here is the call graph for this function:

◆ loadFromDb()

SurveySingleChoiceQuestion::loadFromDb ( int  $question_id)

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

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

111  : void
112  {
113  $ilDB = $this->db;
114 
115  $result = $ilDB->queryF(
116  "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",
117  array('integer'),
118  array($question_id)
119  );
120  if ($result->numRows() === 1) {
121  $data = $ilDB->fetchAssoc($result);
122  $this->setId((int) $data["question_id"]);
123  $this->setTitle((string) $data["title"]);
124  $this->label = (string) $data['label'];
125  $this->setDescription((string) $data["description"]);
126  $this->setObjId((int) $data["obj_fi"]);
127  $this->setAuthor((string) $data["author"]);
128  $this->setOwner((int) $data["owner_fi"]);
129  $this->setQuestiontext(ilRTE::_replaceMediaObjectImageSrc((string) $data["questiontext"], 1));
130  $this->setObligatory((bool) $data["obligatory"]);
131  $this->setComplete((bool) $data["complete"]);
132  $this->setOriginalId((int) $data["original_id"]);
133  $this->setOrientation((int) $data["orientation"]);
134 
135  $this->categories->flushCategories();
136  $result = $ilDB->queryF(
137  "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",
138  array('integer'),
139  array($question_id)
140  );
141  if ($result->numRows() > 0) {
142  while ($data = $ilDB->fetchAssoc($result)) {
143  $this->categories->addCategory((string) $data["title"], (int) $data["other"], (int) $data["neutral"], null, ($data['scale']) ?: ($data['sequence'] + 1));
144  }
145  }
146  }
147  parent::loadFromDb($question_id);
148  }
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
setQuestiontext(string $questiontext="")
setObligatory(bool $obligatory=true)
setOriginalId(?int $original_id)
setComplete(bool $a_complete)
setOrientation(int $orientation=0)
setAuthor(string $author="")
setTitle(string $title="")
setOwner(int $owner=0)
setDescription(string $description="")
setObjId(int $obj_id=0)
Set the reference(?) id of the container object.
+ Here is the call graph for this function:

◆ saveCategoriesToDb()

SurveySingleChoiceQuestion::saveCategoriesToDb ( )

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

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

Referenced by saveToDb().

191  : void
192  {
193  $ilDB = $this->db;
194 
195  $this->log->debug("DELETE from svy_variable before the INSERT into svy_variable. if scale > 0 we get scale value else we get null");
196 
197  $affectedRows = $ilDB->manipulateF(
198  "DELETE FROM svy_variable WHERE question_fi = %s",
199  array('integer'),
200  array($this->getId())
201  );
202 
203  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
204  $cat = $this->categories->getCategory($i);
205  $category_id = $this->saveCategoryToDb($cat->title, $cat->neutral);
206  $next_id = $ilDB->nextId('svy_variable');
207  $affectedRows = $ilDB->manipulateF(
208  "INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, other, sequence, scale, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
209  array('integer','integer','integer','float','integer','integer', 'integer','integer'),
210  array($next_id, $category_id, $this->getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
211  );
212 
213  $debug_scale = ($cat->scale > 0) ? $cat->scale : null;
214  $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);
215  }
216  $this->saveCompletionStatus();
217  }
saveCompletionStatus(int $original_id=0)
Saves the complete flag to the database.
saveCategoryToDb(string $categorytext, int $neutral=0)
Saves a category to the database.
$i
Definition: metadata.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ savePhrase()

SurveySingleChoiceQuestion::savePhrase ( string  $title)

Saves a set of categories to a default phrase note: data comes from session.

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

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

336  : void
337  {
339  $ilDB = $this->db;
340 
341  $next_id = $ilDB->nextId('svy_phrase');
342  $affectedRows = $ilDB->manipulateF(
343  "INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
344  array('integer','text','text','integer','integer'),
345  array($next_id, $title, 1, $ilUser->getId(), time())
346  );
347  $phrase_id = $next_id;
348 
349  $counter = 1;
350  $phrase_data = $this->edit_manager->getPhraseData();
351  foreach ($phrase_data as $data) {
352  $next_id = $ilDB->nextId('svy_category');
353  $affectedRows = $ilDB->manipulateF(
354  "INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
355  array('integer','text','text','integer','integer','text'),
356  array($next_id, $data['answer'], 1, $ilUser->getId(), time(), $data['neutral'])
357  );
358  $category_id = $next_id;
359  $next_id = $ilDB->nextId('svy_phrase_cat');
360  $affectedRows = $ilDB->manipulateF(
361  "INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence, other, scale) VALUES (%s, %s, %s, %s, %s, %s)",
362  array('integer', 'integer', 'integer','integer', 'integer', 'integer'),
363  array($next_id, $phrase_id, $category_id, $counter, ($data['other']) ? 1 : 0, $data['scale'])
364  );
365  $counter++;
366  }
367  }
$ilUser
Definition: imgupload.php:34

◆ saveToDb()

SurveySingleChoiceQuestion::saveToDb ( int  $original_id = 0)

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

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

164  : int
165  {
166  $ilDB = $this->db;
167 
168  $affectedRows = parent::saveToDb($original_id);
169  if ($affectedRows === 1) {
170  $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");
171  $ilDB->manipulateF(
172  "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
173  array('integer'),
174  array($this->getId())
175  );
176  $ilDB->manipulateF(
177  "INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, orientation) VALUES (%s, %s)",
178  array('integer', 'text'),
179  array(
180  $this->getId(),
181  $this->getOrientation()
182  )
183  );
184 
185  $this->saveMaterial();
186  $this->saveCategoriesToDb();
187  }
188  return $affectedRows;
189  }
+ Here is the call graph for this function:

◆ saveUserInput()

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

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

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

445  : ?array {
446  $ilDB = $this->db;
447 
448  $entered_value = $post_data[$this->getId() . "_value"] ?? "";
449 
450  if ($a_return) {
451  return array(array("value" => $entered_value,
452  "textanswer" => $post_data[$this->getId() . "_" . $entered_value . "_other"] ?? ""));
453  }
454  if (strlen($entered_value) == 0) {
455  return null;
456  }
457 
458  $next_id = $ilDB->nextId('svy_answer');
459  #20216
460  $fields = array();
461  $fields['answer_id'] = array("integer", $next_id);
462  $fields['question_fi'] = array("integer", $this->getId());
463  $fields['active_fi'] = array("integer", $active_id);
464  $fields['value'] = array("float", (strlen($entered_value)) ? $entered_value : null);
465  $fields['textanswer'] = array("clob", isset($post_data[$this->getId() . "_" . $entered_value . "_other"]) ?
466  $this->stripSlashesAddSpaceFallback($post_data[$this->getId() . "_" . $entered_value . "_other"]) : null);
467  $fields['tstamp'] = array("integer", time());
468 
469  $affectedRows = $ilDB->insert("svy_answer", $fields);
470 
471  $debug_value = (strlen($entered_value)) ? $entered_value : "NULL";
472  $debug_answer = $post_data[$this->getId() . "_" . $entered_value . "_other"] ?? "NULL";
473  $this->log->debug("INSERT svy_answer answer_id=" . $next_id . " question_fi=" . $this->getId() . " active_fi=" . $active_id . " value=" . $debug_value . " textanswer=" . $debug_answer);
474  return null;
475  }
stripSlashesAddSpaceFallback(string $a_str)
Strip slashes with add space fallback, see https://mantis.ilias.de/view.php?id=19727 and https://mant...
+ Here is the call graph for this function:

◆ toXML()

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

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

References $xml, and insertXML().

222  : string {
223  $a_xml_writer = new ilXmlWriter();
224  $a_xml_writer->xmlHeader();
225  $this->insertXML($a_xml_writer, $a_include_header);
226  $xml = $a_xml_writer->xmlDumpMem(false);
227  if (!$a_include_header) {
228  $pos = strpos($xml, "?>");
229  $xml = substr($xml, $pos + 2);
230  }
231  return $xml;
232  }
insertXML(ilXmlWriter $a_xml_writer, bool $a_include_header=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$xml
Definition: metadata.php:351
+ Here is the call graph for this function:

◆ usableForPrecondition()

SurveySingleChoiceQuestion::usableForPrecondition ( )

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

494  : bool
495  {
496  return true;
497  }

Field Documentation

◆ $categories

SurveyCategories SurveySingleChoiceQuestion::$categories

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

Referenced by getCategories(), and getCategoriesForPhrase().


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