ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
SurveyMultipleChoiceQuestion Class Reference

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

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

Public Member Functions

 __construct (string $title="", string $description="", string $author="", string $questiontext="", int $owner=-1, int $orientation=0)
 
 getQuestionDataArray (int $id)
 
 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)
 Adds the question XML to a given XMLWriter object. More...
 
 getQuestionType ()
 
 getAdditionalTableName ()
 
 getWorkingDataFromUserInput (array $post_data)
 
 checkUserInput (array $post_data, int $survey_id)
 
 saveUserInput (array $post_data, int $active_id, bool $a_return=false)
 
 importAdditionalMetadata (array $a_meta)
 
 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...
 
 createNewQuestion ()
 Creates a new question with a 0 timestamp when a new question is created This assures that an ID is given to the question if a file upload or something else occurs. More...
 
 getImagePath ()
 Returns the image path for web accessible images of a question. More...
 
 getMaterialsPath ()
 Returns the materials path for web accessible materials of a question. More...
 
 getImagePathWeb ()
 Returns the web image path for web accessible images of a question. More...
 
 getMaterialsPathWeb ()
 Returns the web image path for web accessable images of a question. More...
 
 saveCategoryToDb (string $categorytext, int $neutral=0)
 Saves a category to the database. More...
 
 deleteAdditionalTableData (int $question_id)
 Deletes datasets from the additional question table in the database. More...
 
 delete (int $question_id)
 Deletes a question and all materials from the database. More...
 
 syncWithOriginal ()
 
 getQuestionTypeID ()
 
 getQuestionType ()
 
 isHTML (string $a_text)
 
 QTIMaterialToString (ilQTIMaterial $a_material)
 Reads an QTI material tag an creates a text string. More...
 
 addMaterialTag (ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true, ?array $a_attrs=null)
 Creates an XML material tag from a plain text or xhtml text. More...
 
 prepareTextareaOutput (string $txt_output, bool $prepare_for_latex_output=false)
 Prepares string for a text area output in surveys. More...
 
 getQuestionDataArray (int $id)
 Returns the question data. More...
 
 getWorkingDataFromUserInput (array $post_data)
 Creates the user data of the svy_answer table from the POST data. More...
 
 importAdditionalMetadata (array $a_meta)
 Import additional meta data from the question import file. More...
 
 importResponses (array $a_data)
 Import response data from the question import file. More...
 
 importAdjectives (array $a_data)
 Import bipolar adjectives from the question import file. More...
 
 importMatrix (array $a_data)
 Import matrix rows from the question import file. More...
 
 usableForPrecondition ()
 Returns if the question is usable for preconditions. More...
 
 getAvailableRelations ()
 Returns the available relations for the question. More...
 
 getPreconditionOptions ()
 Returns the options for preconditions. More...
 
 getPreconditionValueOutput (string $value)
 Returns the output for a precondition value. More...
 
 getPreconditionSelectValue (string $default, string $title, string $variable)
 Creates a form property for the precondition value. More...
 
 setOriginalId (?int $original_id)
 
 getOriginalId ()
 
 getMaterial ()
 
 setSubtype (int $a_subtype)
 
 getSubtype ()
 
 __get (string $value)
 
 __set (string $key, 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 Public Member Functions inherited from SurveyQuestion
static _isComplete (int $question_id)
 Checks whether the question is complete or not. More...
 
static _getQuestionType (int $question_id)
 Returns the question type of a question with a given id. More...
 
static _getTitle (int $question_id)
 Returns the question title of a question with a given id. More...
 
static _getOriginalId (int $question_id, bool $a_return_question_id_if_no_original=true)
 Returns the original id of a question. More...
 
static _questionExists (int $question_id)
 
static _resolveInternalLink (string $internal_link)
 
static _resolveIntLinks (int $question_id)
 
static _getInternalLinkHref (string $target="", ?int $a_parent_ref_id=null)
 
static _isWriteable (int $question_id, int $user_id)
 is question writeable by a certain user More...
 
static _includeClass (string $question_type, int $gui=0)
 Include the php class file for a given question type. More...
 
static _getQuestionTypeName (string $type_tag)
 Return the translation for a given question type. More...
 
static _instanciateQuestion (int $question_id)
 Get question object. More...
 
static _instanciateQuestionGUI (int $question_id)
 Get question gui object. More...
 
static _instanciateQuestionEvaluation (int $question_id, ?array $a_finished_ids=null)
 
static _changeOriginalId (int $a_question_id, int $a_original_id, int $a_object_id)
 Change original id of existing question in db. More...
 
static _lookupSurveyObjId (int $a_question_id)
 
static lookupObjFi (int $a_qid)
 
static getMaxSumScore (int $survey_id)
 Get max sum score for specific survey (and this question type) More...
 

Data Fields

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

Additional Inherited Members

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

Detailed Description

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

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

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

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

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

Constructor & Destructor Documentation

◆ __construct()

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

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

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

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

Member Function Documentation

◆ checkUserInput()

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

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

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

315  : string {
316  $entered_value = (array) ($post_data[$this->getId() . "_value"] ?? []);
317  if (!$this->getObligatory() && (count($entered_value) === 0)) {
318  return "";
319  }
320 
321  if ($this->use_min_answers && $this->nr_min_answers > 0 && $this->nr_max_answers > 0 && $this->nr_min_answers == $this->nr_max_answers && count($entered_value) !== (int) $this->nr_max_answers) {
322  return sprintf($this->lng->txt("err_no_exact_answers"), $this->nr_min_answers);
323  }
324  if ($this->use_min_answers && $this->nr_min_answers > 0 && count($entered_value) < $this->nr_min_answers) {
325  return sprintf($this->lng->txt("err_no_min_answers"), $this->nr_min_answers);
326  }
327  if ($this->use_min_answers && $this->nr_max_answers > 0 && count($entered_value) > $this->nr_max_answers) {
328  return sprintf($this->lng->txt("err_no_max_answers"), $this->nr_max_answers);
329  }
330  if (count($entered_value) == 0) {
331  return $this->lng->txt("question_mr_not_checked");
332  }
333  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
334  $cat = $this->categories->getCategory($i);
335  if ($cat->other) {
336  if (in_array($i, $entered_value)) {
337  if (array_key_exists($this->getId() . "_" . $i . "_other", $post_data) && !strlen($post_data[$this->getId() . "_" . $i . "_other"] ?? "")) {
338  return $this->lng->txt("question_mr_no_other_answer");
339  }
340  } elseif (strlen($post_data[$this->getId() . "_" . $i . "_other"] ?? "")) {
341  return $this->lng->txt("question_mr_no_other_answer_checked");
342  }
343  }
344  }
345  return "";
346  }
+ Here is the call graph for this function:

◆ getAdditionalTableName()

SurveyMultipleChoiceQuestion::getAdditionalTableName ( )

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

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

276  : string
277  {
278  return "svy_qst_mc";
279  }
+ Here is the caller graph for this function:

◆ getAvailableRelations()

SurveyMultipleChoiceQuestion::getAvailableRelations ( )

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

429  : array
430  {
431  return array("=", "<>");
432  }

◆ getCategories()

SurveyMultipleChoiceQuestion::getCategories ( )

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

References $categories.

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

◆ getMaxSumScore()

static SurveyMultipleChoiceQuestion::getMaxSumScore ( int  $survey_id)
static

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

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

473  : int
474  {
475  global $DIC;
476 
477  // we need sum of scale values of multiple choice questions (type 1)
478  $db = $DIC->database();
479  $set = $db->queryF(
480  "SELECT SUM(scale) sum_sum_score FROM svy_svy_qst sq " .
481  "JOIN svy_question q ON (sq.question_fi = q.question_id) " .
482  "JOIN svy_variable v ON (v.question_fi = q.question_id) " .
483  "WHERE sq.survey_fi = %s AND q.questiontype_fi = %s ",
484  ["integer", "integer"],
485  [$survey_id, 1]
486  );
487  $rec = $db->fetchAssoc($set);
488  return (int) $rec["sum_sum_score"];
489  }
fetchAssoc(ilDBStatement $statement)
global $DIC
Definition: shib_login.php:22
queryF(string $query, array $types, array $values)
+ Here is the call graph for this function:

◆ getPreconditionOptions()

SurveyMultipleChoiceQuestion::getPreconditionOptions ( )

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

Referenced by getPreconditionSelectValue().

434  : array
435  {
436  $options = array();
437  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
438  $category = $this->categories->getCategory($i);
439  $options[$category->scale - 1] = $category->scale . " - " . $category->title;
440  }
441  return $options;
442  }
+ Here is the caller graph for this function:

◆ getPreconditionSelectValue()

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

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

References getPreconditionOptions().

448  : ?ilFormPropertyGUI {
449  $step3 = new ilSelectInputGUI($title, $variable);
450  $options = $this->getPreconditionOptions();
451  $step3->setOptions($options);
452  $step3->setValue($default);
453  return $step3;
454  }
This class represents a selection list property in a property form.
+ Here is the call graph for this function:

◆ getPreconditionValueOutput()

SurveyMultipleChoiceQuestion::getPreconditionValueOutput ( string  $value)

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

458  : string {
459  // #18136
460  $category = $this->categories->getCategoryForScale((int) $value + 1);
461 
462  // #17895 - see getPreconditionOptions()
463  return $category->scale .
464  " - " .
465  ((strlen($category->title ?? "")) ? $category->title : $this->lng->txt('other_answer'));
466  }

◆ getQuestionDataArray()

SurveyMultipleChoiceQuestion::getQuestionDataArray ( int  $id)

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

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

47  : array
48  {
49  $ilDB = $this->db;
50 
51  $result = $ilDB->queryF(
52  "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",
53  array('integer'),
54  array($id)
55  );
56  if ($result->numRows() === 1) {
57  return $ilDB->fetchAssoc($result);
58  }
59 
60  return array();
61  }
+ Here is the call graph for this function:

◆ getQuestionType()

SurveyMultipleChoiceQuestion::getQuestionType ( )

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

Referenced by insertXML().

271  : string
272  {
273  return "SurveyMultipleChoiceQuestion";
274  }
+ Here is the caller graph for this function:

◆ getWorkingDataFromUserInput()

SurveyMultipleChoiceQuestion::getWorkingDataFromUserInput ( array  $post_data)

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

References $data, and SurveyQuestion\getId().

281  : array
282  {
283  $entered_value = $post_data[$this->getId() . "_value"] ?? "";
284  $data = array();
285  if (is_array($entered_value)) {
286  foreach ($entered_value as $idx => $value) {
287  $data[] = array("value" => $value,
288  "textanswer" => $post_data[$this->getId() . '_' . $value . '_other'] ?? ""
289  );
290  }
291  }
292  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
293  $cat = $this->categories->getCategory($i);
294  if ($cat->other) {
295  // #18212
296  if (!is_array($entered_value) || !in_array($i, $entered_value)) {
297  if (strlen($post_data[$this->getId() . "_" . $i . "_other"] ?? "")) {
298  $data[] = array("value" => $i,
299  "textanswer" => $post_data[$this->getId() . '_' . $i . '_other'] ?? "",
300  "uncheck" => true
301  );
302  }
303  }
304  }
305  }
306  return $data;
307  }
+ Here is the call graph for this function:

◆ importAdditionalMetadata()

SurveyMultipleChoiceQuestion::importAdditionalMetadata ( array  $a_meta)

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

References SurveyQuestion\setOrientation().

387  : void
388  {
389  foreach ($a_meta as $key => $value) {
390  switch ($value["label"]) {
391  case "orientation":
392  $this->setOrientation($value["entry"]);
393  break;
394  case "use_min_answers":
395  $this->use_min_answers = $value["entry"];
396  break;
397  case "nr_min_answers":
398  $this->nr_min_answers = $value["entry"];
399  break;
400  case "nr_max_answers":
401  $this->nr_max_answers = $value["entry"];
402  break;
403  }
404  }
405  }
setOrientation(int $orientation=0)
+ Here is the call graph for this function:

◆ importResponses()

SurveyMultipleChoiceQuestion::importResponses ( array  $a_data)

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

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

407  : void
408  {
409  foreach ($a_data as $id => $data) {
410  $categorytext = "";
411  foreach ($data["material"] as $material) {
412  $categorytext .= $material["text"];
413  }
414  $this->categories->addCategory(
415  $categorytext,
416  strlen($data['other'] ?? "") ? $data['other'] : 0,
417  strlen($data['neutral'] ?? "") ? $data['neutral'] : 0,
418  strlen($data['label'] ?? "") ? $data['label'] : null,
419  strlen($data['scale'] ?? "") ? $data['scale'] : null
420  );
421  }
422  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ insertXML()

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

Adds the question XML to a given XMLWriter object.

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

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

Referenced by toXML().

187  : void {
188  $attrs = array(
189  "id" => $this->getId(),
190  "title" => $this->getTitle(),
191  "type" => $this->getQuestionType(),
192  "obligatory" => $this->getObligatory()
193  );
194  $a_xml_writer->xmlStartTag("question", $attrs);
195 
196  $a_xml_writer->xmlElement("description", null, $this->getDescription());
197  $a_xml_writer->xmlElement("author", null, $this->getAuthor());
198  if (strlen($this->label ?? "")) {
199  $attrs = array(
200  "label" => $this->label,
201  );
202  } else {
203  $attrs = array();
204  }
205  $a_xml_writer->xmlStartTag("questiontext", $attrs);
206  $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
207  $a_xml_writer->xmlEndTag("questiontext");
208 
209  $a_xml_writer->xmlStartTag("responses");
210 
211  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
212  $attrs = array(
213  "id" => $i
214  );
215  if (strlen($this->categories->getCategory($i)->other ?? "")) {
216  $attrs['other'] = $this->categories->getCategory($i)->other;
217  }
218  if (strlen($this->categories->getCategory($i)->neutral ?? "")) {
219  $attrs['neutral'] = $this->categories->getCategory($i)->neutral;
220  }
221  if (strlen($this->categories->getCategory($i)->label ?? "")) {
222  $attrs['label'] = $this->categories->getCategory($i)->label;
223  }
224  if (strlen($this->categories->getCategory($i)->scale ?? "")) {
225  $attrs['scale'] = $this->categories->getCategory($i)->scale;
226  }
227  $a_xml_writer->xmlStartTag("response_multiple", $attrs);
228  $this->addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
229  $a_xml_writer->xmlEndTag("response_multiple");
230  }
231 
232  $a_xml_writer->xmlEndTag("responses");
233 
234  if (count($this->material)) {
235  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches)) {
236  $attrs = array(
237  "label" => $this->material["title"]
238  );
239  $a_xml_writer->xmlStartTag("material", $attrs);
240  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
241  if (strcmp($matches[1], "") !== 0) {
242  $intlink = $this->material["internal_link"];
243  }
244  $a_xml_writer->xmlElement("mattext", null, $intlink);
245  $a_xml_writer->xmlEndTag("material");
246  }
247  }
248 
249  $a_xml_writer->xmlStartTag("metadata");
250  $a_xml_writer->xmlStartTag("metadatafield");
251  $a_xml_writer->xmlElement("fieldlabel", null, "orientation");
252  $a_xml_writer->xmlElement("fieldentry", null, $this->getOrientation());
253  $a_xml_writer->xmlEndTag("metadatafield");
254  $a_xml_writer->xmlStartTag("metadatafield");
255  $a_xml_writer->xmlElement("fieldlabel", null, "use_min_answers");
256  $a_xml_writer->xmlElement("fieldentry", null, $this->use_min_answers);
257  $a_xml_writer->xmlEndTag("metadatafield");
258  $a_xml_writer->xmlStartTag("metadatafield");
259  $a_xml_writer->xmlElement("fieldlabel", null, "nr_min_answers");
260  $a_xml_writer->xmlElement("fieldentry", null, $this->nr_min_answers);
261  $a_xml_writer->xmlEndTag("metadatafield");
262  $a_xml_writer->xmlStartTag("metadatafield");
263  $a_xml_writer->xmlElement("fieldlabel", null, "nr_max_answers");
264  $a_xml_writer->xmlElement("fieldentry", null, $this->nr_max_answers);
265  $a_xml_writer->xmlEndTag("metadatafield");
266  $a_xml_writer->xmlEndTag("metadata");
267 
268  $a_xml_writer->xmlEndTag("question");
269  }
const IL_INST_ID
Definition: constants.php:40
xmlEndTag(string $tag)
Writes an endtag.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isComplete()

SurveyMultipleChoiceQuestion::isComplete ( )

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

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

105  : bool
106  {
107  return (
108  $this->getTitle() !== '' &&
109  $this->getAuthor() !== '' &&
110  $this->getQuestiontext() !== '' &&
111  $this->categories->getCategoryCount()
112  );
113  }
+ Here is the call graph for this function:

◆ loadFromDb()

SurveyMultipleChoiceQuestion::loadFromDb ( int  $question_id)

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

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

63  : void
64  {
65  $ilDB = $this->db;
66 
67  $result = $ilDB->queryF(
68  "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",
69  array('integer'),
70  array($question_id)
71  );
72  if ($result->numRows() === 1) {
73  $data = $ilDB->fetchAssoc($result);
74  $this->setId($data["question_id"]);
75  $this->setTitle((string) $data["title"]);
76  $this->label = (string) $data['label'];
77  $this->setDescription((string) $data["description"]);
78  $this->setObjId((int) $data["obj_fi"]);
79  $this->setAuthor((string) $data["author"]);
80  $this->setOwner((int) $data["owner_fi"]);
81  $this->setQuestiontext(ilRTE::_replaceMediaObjectImageSrc((string) $data["questiontext"], 1));
82  $this->setObligatory((bool) $data["obligatory"]);
83  $this->setComplete((bool) $data["complete"]);
84  $this->setOriginalId((int) $data["original_id"]);
85  $this->setOrientation((int) $data["orientation"]);
86  $this->use_min_answers = (bool) $data['use_min_answers'];
87  $this->nr_min_answers = (string) $data['nr_min_answers'];
88  $this->nr_max_answers = (string) $data['nr_max_answers'];
89 
90  $this->categories->flushCategories();
91  $result = $ilDB->queryF(
92  "SELECT svy_variable.*, svy_category.title, svy_category.neutral FROM svy_variable, svy_category WHERE svy_variable.question_fi = %s AND svy_variable.category_fi = svy_category.category_id ORDER BY sequence ASC",
93  array('integer'),
94  array($question_id)
95  );
96  if ($result->numRows() > 0) {
97  while ($data = $ilDB->fetchAssoc($result)) {
98  $this->categories->addCategory($data["title"], $data["other"], $data["neutral"], null, ($data['scale']) ?: ($data['sequence'] + 1));
99  }
100  }
101  }
102  parent::loadFromDb($question_id);
103  }
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)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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()

SurveyMultipleChoiceQuestion::saveCategoriesToDb ( )

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

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

Referenced by saveToDb().

143  : void
144  {
145  $ilDB = $this->db;
146 
147  $affectedRows = $ilDB->manipulateF(
148  "DELETE FROM svy_variable WHERE question_fi = %s",
149  array('integer'),
150  array($this->getId())
151  );
152 
153  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
154  $cat = $this->categories->getCategory($i);
155  $category_id = $this->saveCategoryToDb($cat->title, $cat->neutral);
156  $next_id = $ilDB->nextId('svy_variable');
157  $affectedRows = $ilDB->manipulateF(
158  "INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, other, sequence, scale, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
159  array('integer','integer','integer','float','integer','integer', 'integer','integer'),
160  array($next_id, $category_id, $this->getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
161  );
162  }
163  $this->saveCompletionStatus();
164  }
saveCompletionStatus(int $original_id=0)
Saves the complete flag to the database.
saveCategoryToDb(string $categorytext, int $neutral=0)
Saves a category to the database.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveToDb()

SurveyMultipleChoiceQuestion::saveToDb ( int  $original_id = 0)

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

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

115  : int
116  {
117  $ilDB = $this->db;
118 
119  $affectedRows = parent::saveToDb($original_id);
120  if ($affectedRows === 1) {
121  $ilDB->manipulateF(
122  "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
123  array('integer'),
124  array($this->getId())
125  );
126  $ilDB->manipulateF(
127  "INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, orientation, use_min_answers, nr_min_answers, nr_max_answers) VALUES (%s, %s, %s, %s, %s)",
128  array('integer', 'text', 'integer', 'integer', 'integer'),
129  array(
130  $this->getId(),
131  $this->getOrientation(),
132  ($this->use_min_answers) ? 1 : 0,
133  ($this->nr_min_answers > 0) ? $this->nr_min_answers : null,
134  ($this->nr_max_answers > 0) ? $this->nr_max_answers : null
135  )
136  );
137 
138  $this->saveCategoriesToDb();
139  }
140  return $affectedRows;
141  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:

◆ saveUserInput()

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

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

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

352  : ?array {
353  $ilDB = $this->db;
354 
355  if ($a_return) {
356  $return_data = array();
357  }
358  if (is_array($post_data[$this->getId() . "_value"] ?? null)) {
359  foreach ($post_data[$this->getId() . "_value"] as $entered_value) {
360  if (strlen($entered_value ?? "") > 0) {
361  if (!$a_return) {
362  $next_id = $ilDB->nextId('svy_answer');
363 
364  #20216
365  $fields = array();
366  $fields['answer_id'] = array("integer", $next_id);
367  $fields['question_fi'] = array("integer", $this->getId());
368  $fields['active_fi'] = array("integer", $active_id);
369  $fields['value'] = array("float", (strlen($entered_value ?? "")) ? $entered_value : null);
370  $fields['textanswer'] = array("clob", isset($post_data[$this->getId() . "_" . $entered_value . "_other"]) ? $this->stripSlashesAddSpaceFallback($post_data[$this->getId() . "_" . $entered_value . "_other"]) : null);
371  $fields['tstamp'] = array("integer", time());
372 
373  $affectedRows = $ilDB->insert("svy_answer", $fields);
374  } else {
375  $return_data[] = array("value" => $entered_value,
376  "textanswer" => $post_data[$this->getId() . "_" . $entered_value . "_other"] ?? "");
377  }
378  }
379  }
380  }
381  if ($a_return) {
382  return $return_data;
383  }
384  return null;
385  }
stripSlashesAddSpaceFallback(string $a_str)
Strip slashes with add space fallback, see https://mantis.ilias.de/view.php?id=19727 and https://mant...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:

◆ toXML()

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

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

References insertXML().

169  : string {
170  $a_xml_writer = new ilXmlWriter();
171  $a_xml_writer->xmlHeader();
172  $this->insertXML($a_xml_writer, $a_include_header);
173  $xml = $a_xml_writer->xmlDumpMem(false);
174  if (!$a_include_header) {
175  $pos = strpos($xml, "?>");
176  $xml = substr($xml, $pos + 2);
177  }
178  return $xml;
179  }
insertXML(ilXmlWriter $a_xml_writer, bool $a_include_header=true)
Adds the question XML to a given XMLWriter object.
+ Here is the call graph for this function:

◆ usableForPrecondition()

SurveyMultipleChoiceQuestion::usableForPrecondition ( )

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

424  : bool
425  {
426  return true;
427  }

Field Documentation

◆ $categories

SurveyCategories SurveyMultipleChoiceQuestion::$categories

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

Referenced by getCategories().


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