ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
SurveySingleChoiceQuestion Class Reference

SingleChoice survey question. More...

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

Public Member Functions

 SurveySingleChoiceQuestion ( $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, $obligatory_state="")
 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...
 
 saveRandomData ($active_id)
 Saves random answers for a given active user in the database. More...
 
 saveUserInput ($post_data, $active_id, $a_return=false)
 
getCumulatedResults ($survey_id, $nr_of_users, $finished_ids)
 
 setExportDetailsXLS (&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
 Creates an Excel worksheet for the detailed cumulated results of this question. More...
 
 addUserSpecificResultsExportTitles (&$a_array, $a_use_label=false, $a_substitute=true)
 overwritten addUserSpecificResultsExportTitles More...
 
 addUserSpecificResultsData (&$a_array, &$resultset)
 Adds the values for the user specific results export for a given user. More...
 
getUserAnswers ($survey_id, $finished_ids)
 Returns an array containing all answers to this question in a given survey. More...
 
 importResponses ($a_data)
 Import response data from the question import file. More...
 
 usableForPrecondition ()
 Returns if the question is usable for preconditions. More...
 
 getAvailableRelations ()
 Returns the available relations for the question. More...
 
 getPreconditionOptions ()
 Returns the options for preconditions. More...
 
 getPreconditionSelectValue ($default="", $title, $variable)
 Creates a form property for the precondition value. More...
 
 getPreconditionValueOutput ($value)
 Returns the output for a precondition value. More...
 
 getCategories ()
 
- Public Member Functions inherited from SurveyQuestion
 SurveyQuestion ( $title="", $description="", $author="", $questiontext="", $owner=-1)
 SurveyQuestion constructor The constructor takes possible arguments an creates an instance of the SurveyQuestion object. More...
 
 _SurveyQuestion ()
 
 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="")
 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...
 
 _isComplete ($question_id)
 Checks whether the question is complete or not. 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...
 
 _getQuestionType ($question_id)
 Returns the question type of a question with a given id. More...
 
 _getTitle ($question_id)
 Returns the question title of a question with a given id. More...
 
 _getOriginalId ($question_id, $a_return_question_id_if_no_original=true)
 Returns the original id of a question. 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...
 
 _questionExists ($question_id)
 Returns true if the question already exists in the database. 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...
 
 _resolveInternalLink ($internal_link)
 
 _resolveIntLinks ($question_id)
 
 _getInternalLinkHref ($target="", $a_parent_ref_id=null)
 
 _isWriteable ($question_id, $user_id)
 Returns true if the question is writeable by a certain user. More...
 
 getQuestionTypeID ()
 Returns the question type ID of the question. More...
 
 getQuestionType ()
 Returns the question type of the question. More...
 
_instanciateQuestion ($question_id)
 Creates an instance of a question with a given question id. More...
 
_instanciateQuestionGUI ($question_id)
 Creates an instance of a question GUI with a given question id. 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...
 
 addUserSpecificResultsExportTitles (&$a_array, $a_use_label=false, $a_substitute=true)
 Adds the entries for the title row of the user specific results. More...
 
 addUserSpecificResultsData (&$a_array, &$resultset)
 Adds the values for the user specific results export for a given user. More...
 
getUserAnswers ($survey_id)
 Returns an array containing all answers to this question in a given survey. 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...
 
 setExportCumulatedXLS (&$worksheet, &$format_title, &$format_bold, &$eval_data, $row, $export_label)
 Creates the Excel output for the cumulated results of this question. More...
 
setExportCumulatedCVS (&$eval_data, $export_label)
 Creates the CSV output for the cumulated results of this question. More...
 
 setExportDetailsXLS (&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
 Creates an Excel worksheet for the detailed cumulated results of this question. 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...
 
 outChart ($survey_id, $type="")
 Creates an image visualising the results of the question. More...
 
 setOriginalId ($original_id)
 
 getOriginalId ()
 
 saveRandomData ($active_id)
 Saves random answers for a given active user in the database. More...
 
 getMaterial ()
 
 setSubtype ($a_subtype)
 
 getSubtype ()
 
 getCumulatedResultData ($survey_id, $counter, $finished_ids)
 Creates a the cumulated results data for the question. More...
 
 __get ($value)
 Object getter. More...
 
 __set ($key, $value)
 Object setter. More...
 
 getCopyIds ($a_group_by_survey=false)
 
 hasCopies ()
 
 getSkippedValue ()
 

Data Fields

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

Additional Inherited Members

- Static Public Member Functions inherited from SurveyQuestion
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 _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 Member Functions inherited from SurveyQuestion
calculateCumulatedResults ($survey_id, $finished_ids)
 
- Protected Attributes inherited from SurveyQuestion
 $cumulated
 An array containing the cumulated results of the question for a given survey. More...
 

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

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

Member Function Documentation

◆ _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 @access public

Reimplemented from SurveyQuestion.

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

138 {
139 global $ilDB;
140
141 $result = $ilDB->queryF("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",
142 array('integer'),
143 array($id)
144 );
145 if ($result->numRows() == 1)
146 {
147 return $ilDB->fetchAssoc($result);
148 }
149 else
150 {
151 return array();
152 }
153 }
$result
getAdditionalTableName()
Returns the name of the additional question data table in the database.
global $ilDB

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

+ Here is the call graph for this function:

◆ addPhrase()

SurveySingleChoiceQuestion::addPhrase (   $phrase_id)

Adds a phrase to the question.

Parameters
integer$phrase_idThe database id of the given phrase @access public

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

108 {
109 global $ilUser;
110 global $ilDB;
111
112 $result = $ilDB->queryF("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",
113 array('integer', 'integer'),
114 array($phrase_id, $ilUser->getId())
115 );
116 while ($row = $ilDB->fetchAssoc($result))
117 {
118 $neutral = $row["neutral"];
119 if (($row["defaultvalue"] == 1) and ($row["owner_fi"] == 0))
120 {
121 $this->categories->addCategory($this->lng->txt($row["title"]), 0, $neutral);
122 }
123 else
124 {
125 $this->categories->addCategory($row["title"], 0, $neutral);
126 }
127 }
128 }
global $ilUser
Definition: imgupload.php:15

References $ilDB, $ilUser, $result, and $row.

◆ addStandardNumbers()

SurveySingleChoiceQuestion::addStandardNumbers (   $lower_limit,
  $upper_limit 
)

Adds standard numbers as categories.

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

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

406 {
407 for ($i = $lower_limit; $i <= $upper_limit; $i++)
408 {
409 $this->categories->addCategory($i);
410 }
411 }

◆ addUserSpecificResultsData()

SurveySingleChoiceQuestion::addUserSpecificResultsData ( $a_array,
$resultset 
)

Adds the values for the user specific results export for a given user.

Parameters
array$a_arrayAn array which is used to append the values
array$resultsetThe evaluation data for a given user @access public

Reimplemented from SurveyQuestion.

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

827 {
828 // check if text answer column is needed
829 $other = false;
830 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
831 {
832 $cat = $this->categories->getCategory($i);
833 if ($cat->other)
834 {
835 $other = true;
836 break;
837 }
838 }
839
840 if (count($resultset["answers"][$this->getId()]))
841 {
842 foreach ($resultset["answers"][$this->getId()] as $key => $answer)
843 {
844 array_push($a_array, $answer["value"]+1);
845
846 // add the text answer from the selected option
847 if ($other)
848 {
849 array_push($a_array, $answer["textanswer"]);
850 }
851 }
852 }
853 else
854 {
855 array_push($a_array, $this->getSkippedValue());
856
857 if ($other)
858 {
859 array_push($a_array, "");
860 }
861 }
862 }
getId()
Gets the id of the SurveyQuestion object.

References SurveyQuestion\getId(), and SurveyQuestion\getSkippedValue().

+ Here is the call graph for this function:

◆ addUserSpecificResultsExportTitles()

SurveySingleChoiceQuestion::addUserSpecificResultsExportTitles ( $a_array,
  $a_use_label = false,
  $a_substitute = true 
)

overwritten addUserSpecificResultsExportTitles

Adds the entries for the title row of the user specific results

Parameters
array$a_arrayAn array which is used to append the title row entries @access public

Reimplemented from SurveyQuestion.

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

797 {
798 $title = parent::addUserSpecificResultsExportTitles($a_array, $a_use_label, $a_substitute);
799
800 // optionally add header for text answer
801 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
802 {
803 $cat = $this->categories->getCategory($i);
804 if ($cat->other)
805 {
806 if(!$a_use_label || $a_substitute)
807 {
808 array_push($a_array, $title. ' - '. $this->lng->txt('other'));
809 }
810 else
811 {
812 array_push($a_array, "");
813 }
814 break;
815 }
816 }
817 }

References SurveyQuestion\$title.

◆ 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 @access public

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

513 {
514 $entered_value = $post_data[$this->getId() . "_value"];
515
516 if ((!$this->getObligatory($survey_id)) && (strlen($entered_value) == 0)) return "";
517
518 if (strlen($entered_value) == 0) return $this->lng->txt("question_not_checked");
519
520 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
521 {
522 $cat = $this->categories->getCategory($i);
523 if ($cat->other)
524 {
525 if ($i == $entered_value)
526 {
527 if (array_key_exists($this->getId() . "_" . $entered_value . "_other", $post_data) && !strlen($post_data[$this->getId() . "_" . $entered_value . "_other"]))
528 {
529 return $this->lng->txt("question_mr_no_other_answer");
530 }
531 }
532 else
533 {
534 if (strlen($post_data[$this->getId() . "_" . $i . "_other"]))
535 {
536 return $this->lng->txt("question_sr_no_other_answer_checked");
537 }
538 }
539 }
540 }
541
542 return "";
543 }
getObligatory($survey_id="")
Gets the obligatory state of the question.

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

+ 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 @access public

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

468 {
469 return "svy_qst_sc";
470 }

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

+ 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 @access public

Reimplemented from SurveyQuestion.

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

940 {
941 return array("<", "<=", "=", "<>", ">=", ">");
942 }

◆ getCategories()

SurveySingleChoiceQuestion::getCategories ( )

◆ 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 @access public

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

80 {
81 global $ilDB;
82 $categories = array();
83 $result = $ilDB->queryF("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",
84 array('integer'),
85 array($phrase_id)
86 );
87 while ($row = $ilDB->fetchAssoc($result))
88 {
89 if (($row["defaultvalue"] == 1) and ($row["owner_fi"] == 0))
90 {
91 $categories[$row["category_id"]] = $this->lng->txt($row["title"]);
92 }
93 else
94 {
95 $categories[$row["category_id"]] = $row["title"];
96 }
97 }
98 return $categories;
99 }

References $categories, $ilDB, $result, and $row.

◆ getCumulatedResults()

& SurveySingleChoiceQuestion::getCumulatedResults (   $survey_id,
  $nr_of_users,
  $finished_ids 
)

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

595 {
596 global $ilDB;
597
598 $question_id = $this->getId();
599
600 $result_array = array();
601 $cumulated = array();
602
603 $sql = "SELECT svy_answer.* FROM svy_answer".
604 " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
605 " WHERE svy_answer.question_fi = ".$ilDB->quote($question_id, "integer").
606 " AND svy_finished.survey_fi = ".$ilDB->quote($survey_id, "integer");
607 if($finished_ids)
608 {
609 $sql .= " AND ".$ilDB->in("svy_finished.finished_id", $finished_ids, "", "integer");
610 }
611
612 $result = $ilDB->query($sql);
613 while ($row = $ilDB->fetchAssoc($result))
614 {
615 $cumulated[$row["value"]]++;
616
617 // add text value to result array
618 if ($row["textanswer"])
619 {
620 $result_array["textanswers"][$row["value"]][] = $row["textanswer"];
621 }
622 }
623 // sort textanswers by value
624 if (is_array($result_array["textanswers"]))
625 {
626 ksort($result_array["textanswers"], SORT_NUMERIC);
627 }
628 asort($cumulated, SORT_NUMERIC);
629 end($cumulated);
630 $numrows = $result->numRows();
631 $result_array["USERS_ANSWERED"] = $result->numRows();
632 $result_array["USERS_SKIPPED"] = $nr_of_users - $result->numRows();
633
634 if(sizeof($cumulated))
635 {
636 $prefix = "";
637 if (strcmp(key($cumulated), "") != 0)
638 {
639 $prefix = (key($cumulated)+1) . " - ";
640 }
641 $category = $this->categories->getCategoryForScale(key($cumulated)+1);
642 $result_array["MODE"] = $prefix . $category->title;
643 $result_array["MODE_VALUE"] = key($cumulated)+1;
644 $result_array["MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
645 }
646 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
647 {
648 $cat = $this->categories->getCategory($key);
649 $percentage = 0;
650 if ($numrows > 0)
651 {
652 $percentage = (float)((int)$cumulated[$cat->scale-1]/$numrows);
653 }
654 if ($cat->other)
655 {
656 $result_array["variables"][$key] = array("title" => (strlen($cat->title)) ? $cat->title : $this->lng->txt('other_answer'), "selected" => (int)$cumulated[$cat->scale-1], "percentage" => $percentage);
657 }
658 else
659 {
660 $result_array["variables"][$key] = array("title" => $cat->title, "selected" => (int)$cumulated[$cat->scale-1], "percentage" => $percentage);
661 }
662 }
663 ksort($cumulated, SORT_NUMERIC);
664 $median = array();
665 $total = 0;
666 foreach ($cumulated as $value => $key)
667 {
668 $total += $key;
669 for ($i = 0; $i < $key; $i++)
670 {
671 array_push($median, $value+1);
672 }
673 }
674 if ($total > 0)
675 {
676 if (($total % 2) == 0)
677 {
678 $median_value = 0.5 * ($median[($total/2)-1] + $median[($total/2)]);
679 if (round($median_value) != $median_value)
680 {
681 $median_value = $median_value . "<br />" . "(" . $this->lng->txt("median_between") . " " . (floor($median_value)) . "-" . $this->categories->getCategory((int)floor($median_value)-1)->title . " " . $this->lng->txt("and") . " " . (ceil($median_value)) . "-" . $this->categories->getCategory((int)ceil($median_value)-1)->title . ")";
682 }
683 }
684 else
685 {
686 $median_value = $median[(($total+1)/2)-1];
687 }
688 }
689 else
690 {
691 $median_value = "";
692 }
693 $result_array["ARITHMETIC_MEAN"] = "";
694 $result_array["MEDIAN"] = $median_value;
695 $result_array["QUESTION_TYPE"] = "SurveySingleChoiceQuestion";
696 return $result_array;
697 }
$cumulated
An array containing the cumulated results of the question for a given survey.

References SurveyQuestion\$cumulated, $ilDB, $result, $row, SurveyQuestion\$survey_id, $total, and SurveyQuestion\getId().

+ Here is the call graph for this function:

◆ getPreconditionOptions()

SurveySingleChoiceQuestion::getPreconditionOptions ( )

Returns the options for preconditions.

Returns
array

Reimplemented from SurveyQuestion.

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

950 {
951 global $lng;
952
953 $options = array();
954 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
955 {
956 $category = $this->categories->getCategory($i);
957 $options[$category->scale-1] = $category->scale . " - " . $category->title;
958 }
959 return $options;
960 }
if(!is_array($argv)) $options

References SurveyQuestion\$lng, and $options.

Referenced by getPreconditionSelectValue().

+ 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 @access public

Reimplemented from SurveyQuestion.

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

969 {
970 include_once "./Services/Form/classes/class.ilSelectInputGUI.php";
971 $step3 = new ilSelectInputGUI($title, $variable);
973 $step3->setOptions($options);
974 $step3->setValue($default);
975 return $step3;
976 }
getPreconditionOptions()
Returns the options for preconditions.
This class represents a selection list property in a property form.

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

+ 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 @access public

Reimplemented from SurveyQuestion.

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

986 {
987 // #18136
988 $category = $this->categories->getCategoryForScale($value+1);
989
990 // #17895 - see getPreconditionOptions()
991 return $category->scale .
992 " - " .
993 ((strlen($category->title)) ? $category->title : $this->lng->txt('other_answer'));
994 }

◆ getQuestionType()

SurveySingleChoiceQuestion::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question @access public

Reimplemented from SurveyQuestion.

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

457 {
458 return "SurveySingleChoiceQuestion";
459 }

◆ getUserAnswers()

& SurveySingleChoiceQuestion::getUserAnswers (   $survey_id,
  $finished_ids 
)

Returns an array containing all answers to this question in a given survey.

Parameters
integer$survey_idThe database ID of the survey
Returns
array An array containing the answers to the question. The keys are either the user id or the anonymous id @access public

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

872 {
873 global $ilDB;
874
875 $answers = array();
876
877 $sql = "SELECT svy_answer.* FROM svy_answer".
878 " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
879 " WHERE svy_answer.question_fi = ".$ilDB->quote($this->getId(), "integer").
880 " AND svy_finished.survey_fi = ".$ilDB->quote($survey_id, "integer");
881 if($finished_ids)
882 {
883 $sql .= " AND ".$ilDB->in("svy_finished.finished_id", $finished_ids, "", "integer");
884 }
885
886 $result = $ilDB->query($sql);
887 while ($row = $ilDB->fetchAssoc($result))
888 {
889 $category = $this->categories->getCategoryForScale($row["value"]+1);
890 $title = $row["value"] + 1 . " - " . $category->title;
891 if ($category->other) $title .= ": " . $row["textanswer"];
892 $answers[$row["active_fi"]] = $title;
893 }
894 return $answers;
895 }

References $ilDB, $result, $row, SurveyQuestion\$survey_id, SurveyQuestion\$title, and SurveyQuestion\getId().

+ Here is the call graph for this function:

◆ 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 @access public

Reimplemented from SurveyQuestion.

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

479 {
480 $entered_value = $post_data[$this->getId() . "_value"];
481 $data = array();
482 if (strlen($entered_value))
483 {
484 array_push($data, array("value" => $entered_value, "textanswer" => $post_data[$this->getId() . '_' . $entered_value . '_other']));
485 }
486 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
487 {
488 $cat = $this->categories->getCategory($i);
489 if ($cat->other)
490 {
491 if ($i != $entered_value)
492 {
493 if (strlen($post_data[$this->getId() . "_" . $i . "_other"]))
494 {
495 array_push($data, array("value" => $i, "textanswer" => $post_data[$this->getId() . '_' . $i . '_other'], "uncheck" => true));
496 }
497 }
498 }
499 }
500 return $data;
501 }
$data

References $data, and SurveyQuestion\getId().

+ 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 @access public

Reimplemented from SurveyQuestion.

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

386 {
387 foreach ($a_meta as $key => $value)
388 {
389 switch ($value["label"])
390 {
391 case "orientation":
392 $this->setOrientation($value["entry"]);
393 break;
394 }
395 }
396 }
setOrientation($orientation=0)
Sets the orientation of the question output.

References SurveyQuestion\setOrientation().

+ 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 @access public

Reimplemented from SurveyQuestion.

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

904 {
905 foreach ($a_data as $id => $data)
906 {
907 $categorytext = "";
908 foreach ($data["material"] as $material)
909 {
910 $categorytext .= $material["text"];
911 }
912 $this->categories->addCategory(
913 $categorytext,
914 strlen($data['other']) ? $data['other'] : 0,
915 strlen($data['neutral']) ? $data['neutral'] : 0,
916 strlen($data['label']) ? $data['label'] : null,
917 strlen($data['scale']) ? $data['scale'] : null
918 );
919 }
920 }

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

◆ insertXML()

SurveySingleChoiceQuestion::insertXML ( $a_xml_writer,
  $a_include_header = TRUE,
  $obligatory_state = "" 
)

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
string$obligatory_stateThe value of the obligatory state @access public

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

306 {
307 $attrs = array(
308 "id" => $this->getId(),
309 "title" => $this->getTitle(),
310 "type" => $this->getQuestiontype(),
311 "obligatory" => $this->getObligatory()
312 );
313 $a_xml_writer->xmlStartTag("question", $attrs);
314
315 $a_xml_writer->xmlElement("description", NULL, $this->getDescription());
316 $a_xml_writer->xmlElement("author", NULL, $this->getAuthor());
317 if (strlen($this->label))
318 {
319 $attrs = array(
320 "label" => $this->label,
321 );
322 }
323 else
324 {
325 $attrs = array();
326 }
327 $a_xml_writer->xmlStartTag("questiontext", $attrs);
328 $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
329 $a_xml_writer->xmlEndTag("questiontext");
330
331 $a_xml_writer->xmlStartTag("responses");
332
333 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
334 {
335 $attrs = array(
336 "id" => $i
337 );
338 if (strlen($this->categories->getCategory($i)->other)) $attrs['other'] = $this->categories->getCategory($i)->other;
339 if (strlen($this->categories->getCategory($i)->neutral)) $attrs['neutral'] = $this->categories->getCategory($i)->neutral;
340 if (strlen($this->categories->getCategory($i)->label)) $attrs['label'] = $this->categories->getCategory($i)->label;
341 if (strlen($this->categories->getCategory($i)->scale)) $attrs['scale'] = $this->categories->getCategory($i)->scale;
342 $a_xml_writer->xmlStartTag("response_single", $attrs);
343 $this->addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
344 $a_xml_writer->xmlEndTag("response_single");
345 }
346
347 $a_xml_writer->xmlEndTag("responses");
348
349 if (count($this->material))
350 {
351 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
352 {
353 $attrs = array(
354 "label" => $this->material["title"]
355 );
356 $a_xml_writer->xmlStartTag("material", $attrs);
357 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
358 if (strcmp($matches[1], "") != 0)
359 {
360 $intlink = $this->material["internal_link"];
361 }
362 $a_xml_writer->xmlElement("mattext", NULL, $intlink);
363 $a_xml_writer->xmlEndTag("material");
364 }
365 }
366
367 $a_xml_writer->xmlStartTag("metadata");
368 $a_xml_writer->xmlStartTag("metadatafield");
369 $a_xml_writer->xmlElement("fieldlabel", NULL, "orientation");
370 $a_xml_writer->xmlElement("fieldentry", NULL, $this->getOrientation());
371 $a_xml_writer->xmlEndTag("metadatafield");
372 $a_xml_writer->xmlEndTag("metadata");
373
374 $a_xml_writer->xmlEndTag("question");
375 }
getDescription()
Gets the description string of the SurveyQuestion object.
getAuthor()
Gets the authors name of the SurveyQuestion object.
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getTitle()
Gets the title string of the SurveyQuestion object.
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.
getOrientation()
Gets the orientation of the question output.

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

Referenced by toXML().

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

◆ isComplete()

SurveySingleChoiceQuestion::isComplete ( )

Returns true if the question is complete for use.

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

Reimplemented from SurveyQuestion.

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

209 {
210 if (
211 strlen($this->getTitle()) &&
212 strlen($this->getAuthor()) &&
213 strlen($this->getQuestiontext()) &&
214 $this->categories->getCategoryCount()
215 )
216 {
217 return 1;
218 }
219 else
220 {
221 return 0;
222 }
223 }

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

+ 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 @access public

Reimplemented from SurveyQuestion.

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

162 {
163 global $ilDB;
164
165 $result = $ilDB->queryF("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",
166 array('integer'),
167 array($id)
168 );
169 if ($result->numRows() == 1)
170 {
171 $data = $ilDB->fetchAssoc($result);
172 $this->setId($data["question_id"]);
173 $this->setTitle($data["title"]);
174 $this->label = $data['label'];
175 $this->setDescription($data["description"]);
176 $this->setObjId($data["obj_fi"]);
177 $this->setAuthor($data["author"]);
178 $this->setOwner($data["owner_fi"]);
179 include_once("./Services/RTE/classes/class.ilRTE.php");
180 $this->setQuestiontext(ilRTE::_replaceMediaObjectImageSrc($data["questiontext"], 1));
181 $this->setObligatory($data["obligatory"]);
182 $this->setComplete($data["complete"]);
183 $this->setOriginalId($data["original_id"]);
184 $this->setOrientation($data["orientation"]);
185
186 $this->categories->flushCategories();
187 $result = $ilDB->queryF("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",
188 array('integer'),
189 array($id)
190 );
191 if ($result->numRows() > 0)
192 {
193 while ($data = $ilDB->fetchAssoc($result))
194 {
195 $this->categories->addCategory($data["title"], $data["other"], $data["neutral"], null, ($data['scale']) ? $data['scale'] : ($data['sequence'] + 1));
196 }
197 }
198 }
199 parent::loadFromDb($id);
200 }
setQuestiontext($questiontext="")
Sets the questiontext of the SurveyQuestion object.
setId($id=-1)
Sets the id of the SurveyQuestion object.
setAuthor($author="")
Sets the authors name of the SurveyQuestion object.
setDescription($description="")
Sets the description string of the SurveyQuestion object.
setObjId($obj_id=0)
Set the reference id of the container object.
setOriginalId($original_id)
setComplete($a_complete)
Sets the complete state of the question.
setOwner($owner="")
Sets the creator/owner ID of the SurveyQuestion object.
setTitle($title="")
Sets the title string of the SurveyQuestion object.
setObligatory($obligatory=1)
Sets the obligatory state of the question.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...

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

+ Here is the call graph for this function:

◆ saveCategoriesToDb()

SurveySingleChoiceQuestion::saveCategoriesToDb ( )

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

255 {
256 global $ilDB;
257
258 $affectedRows = $ilDB->manipulateF("DELETE FROM svy_variable WHERE question_fi = %s",
259 array('integer'),
260 array($this->getId())
261 );
262
263 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
264 {
265 $cat = $this->categories->getCategory($i);
266 $category_id = $this->saveCategoryToDb($cat->title, $cat->neutral);
267 $next_id = $ilDB->nextId('svy_variable');
268 $affectedRows = $ilDB->manipulateF("INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, other, sequence, scale, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
269 array('integer','integer','integer','float','integer','integer', 'integer','integer'),
270 array($next_id, $category_id, $this->getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
271 );
272 }
273 $this->saveCompletionStatus();
274 }
saveCategoryToDb($categorytext, $neutral=0)
Saves a category to the database.
saveCompletionStatus($original_id="")
Saves the complete flag to the database.

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

Referenced by saveToDb().

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

◆ 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 @access public

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

421 {
422 global $ilUser;
423 global $ilDB;
424
425 $next_id = $ilDB->nextId('svy_phrase');
426 $affectedRows = $ilDB->manipulateF("INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
427 array('integer','text','text','integer','integer'),
428 array($next_id, $title, 1, $ilUser->getId(), time())
429 );
430 $phrase_id = $next_id;
431
432 $counter = 1;
433 foreach ($_SESSION['save_phrase_data'] as $data)
434 {
435 $next_id = $ilDB->nextId('svy_category');
436 $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
437 array('integer','text','text','integer','integer','text'),
438 array($next_id, $data['answer'], 1, $ilUser->getId(), time(), $data['neutral'])
439 );
440 $category_id = $next_id;
441 $next_id = $ilDB->nextId('svy_phrase_cat');
442 $affectedRows = $ilDB->manipulateF("INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence, other, scale) VALUES (%s, %s, %s, %s, %s, %s)",
443 array('integer', 'integer', 'integer','integer', 'integer', 'integer'),
444 array($next_id, $phrase_id, $category_id, $counter, ($data['other']) ? 1 : 0, $data['scale'])
445 );
446 $counter++;
447 }
448 }
$_SESSION["AccountId"]

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

◆ saveRandomData()

SurveySingleChoiceQuestion::saveRandomData (   $active_id)

Saves random answers for a given active user in the database.

Parameters
integer$active_idThe database ID of the active user

Reimplemented from SurveyQuestion.

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

551 {
552 global $ilDB;
553 // single response
554 $category = rand(0, $this->categories->getCategoryCount()-1);
555 $cat = $this->categories->getCategory($category);
556 $next_id = $ilDB->nextId('svy_answer');
557 $affectedRows = $ilDB->manipulateF("INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
558 array('integer','integer','integer','float','text','integer'),
559 array($next_id, $this->getId(), $active_id, $category, ($cat->other) ? "Random Data" : null, time())
560 );
561 }

References $ilDB, and SurveyQuestion\getId().

+ Here is the call graph for this function:

◆ saveToDb()

SurveySingleChoiceQuestion::saveToDb (   $original_id = "")

Saves a SurveySingleChoiceQuestion object to a database.

@access public

Reimplemented from SurveyQuestion.

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

231 {
232 global $ilDB;
233
234 $affectedRows = parent::saveToDb($original_id);
235 if ($affectedRows == 1)
236 {
237 $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
238 array('integer'),
239 array($this->getId())
240 );
241 $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, orientation) VALUES (%s, %s)",
242 array('integer', 'text'),
243 array(
244 $this->getId(),
245 $this->getOrientation()
246 )
247 );
248
249 $this->saveMaterial();
250 $this->saveCategoriesToDb();
251 }
252 }
saveMaterial()
save material to db

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

+ Here is the call graph for this function:

◆ saveUserInput()

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

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

564 {
565 global $ilDB;
566
567 $entered_value = $post_data[$this->getId() . "_value"];
568
569 if($a_return)
570 {
571 return array(array("value"=>$entered_value,
572 "textanswer"=>$post_data[$this->getId() . "_" . $entered_value . "_other"]));
573 }
574 if (strlen($entered_value) == 0) return;
575
576 $next_id = $ilDB->nextId('svy_answer');
577
578 /*$affectedRows = $ilDB->manipulateF("INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
579 array('integer','integer','integer','float','text','integer'),
580 array($next_id, $this->getId(), $active_id, (strlen($entered_value)) ? $entered_value : NULL, ($post_data[$this->getId() . "_" . $entered_value . "_other"]) ? $post_data[$this->getId() . "_" . $entered_value . "_other"] : null, time())
581 );*/
582 #20216
583 $fields = array();
584 $fields['answer_id'] = array("integer", $next_id);
585 $fields['question_fi'] = array("integer", $this->getId());
586 $fields['active_fi'] = array("integer", $active_id);
587 $fields['value'] = array("float", (strlen($entered_value)) ? $entered_value : NULL);
588 $fields['textanswer'] = array("clob", ($post_data[$this->getId() . "_" . $entered_value . "_other"]) ? $post_data[$this->getId() . "_" . $entered_value . "_other"] : null);
589 $fields['tstamp'] = array("integer", time());
590
591 $affectedRows = $ilDB->insert("svy_answer", $fields);
592 }

References $ilDB, and SurveyQuestion\getId().

+ Here is the call graph for this function:

◆ setExportDetailsXLS()

SurveySingleChoiceQuestion::setExportDetailsXLS ( $workbook,
$format_title,
$format_bold,
$eval_data,
  $export_label 
)

Creates an Excel worksheet for the detailed cumulated results of this question.

Parameters
object$workbookReference to the parent excel workbook
object$format_titleExcel title format
object$format_boldExcel bold format
array$eval_dataCumulated evaluation data @access public

Reimplemented from SurveyQuestion.

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

709 {
710 include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
711 $worksheet =& $workbook->addWorksheet();
712 $rowcounter = 0;
713 switch ($export_label)
714 {
715 case 'label_only':
716 $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("label")), $format_bold);
717 $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->label));
718 break;
719 case 'title_only':
720 $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
721 $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
722 break;
723 default:
724 $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
725 $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
726 $rowcounter++;
727 $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("label")), $format_bold);
728 $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->label));
729 break;
730 }
731 $rowcounter++;
732 $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("question")), $format_bold);
733 $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->getQuestiontext()));
734 $rowcounter++;
735 $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("question_type")), $format_bold);
736 $worksheet->writeString($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())));
737 $rowcounter++;
738 $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("users_answered")), $format_bold);
739 $worksheet->write($rowcounter, 1, $eval_data["USERS_ANSWERED"]);
740 $rowcounter++;
741 $worksheet->writeString($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("users_skipped")), $format_bold);
742 $worksheet->write($rowcounter, 1, $eval_data["USERS_SKIPPED"]);
743 $rowcounter++;
744
745 preg_match("/(.*?)\s+-\s+(.*)/", $eval_data["MODE"], $matches);
746 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode")), $format_bold);
747 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($matches[1]));
748 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_text")), $format_bold);
749 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($matches[2]));
750 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections")), $format_bold);
751 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE_NR_OF_SELECTIONS"]));
752 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("median")), $format_bold);
753 $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text(str_replace("<br />", " ", $eval_data["MEDIAN"])));
754 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("categories")), $format_bold);
755 $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
756 $worksheet->write($rowcounter, 2, ilExcelUtils::_convert_text($this->lng->txt("value")), $format_title);
757 $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($this->lng->txt("category_nr_selected")), $format_title);
758 $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($this->lng->txt("svy_fraction_of_selections")), $format_title);
759
760 foreach ($eval_data["variables"] as $key => $value)
761 {
762 $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($value["title"]));
763 $category = $this->categories->getCategory($key);
764 $worksheet->write($rowcounter, 2, $category->scale);
765 $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($value["selected"]));
766 $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($value["percentage"]), $format_percent);
767 }
768
769 // add text answers to detailed results
770 if (is_array($eval_data["textanswers"]))
771 {
772 $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("freetext_answers")), $format_bold);
773 $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
774 $worksheet->write($rowcounter++, 2, ilExcelUtils::_convert_text($this->lng->txt("answer")), $format_title);
775
776 foreach ($eval_data["textanswers"] as $key => $answers)
777 {
778 $title = $eval_data["variables"][$key]["title"];
779 foreach ($answers as $answer)
780 {
781 $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($title));
782 $worksheet->write($rowcounter++, 2, ilExcelUtils::_convert_text($answer));
783 }
784 }
785 }
786 }
_convert_text($a_text, $a_target="has been removed")

References SurveyQuestion\$title, ilExcelUtils\_convert_text(), SurveyQuestion\getQuestiontext(), and SurveyQuestion\getTitle().

+ Here is the call graph for this function:

◆ SurveySingleChoiceQuestion()

SurveySingleChoiceQuestion::SurveySingleChoiceQuestion (   $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 @access public

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

65 {
67 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
68 $this->orientation = $orientation;
69 $this->categories = new SurveyCategories();
70 }
Class SurveyCategories.
SurveyQuestion( $title="", $description="", $author="", $questiontext="", $owner=-1)
SurveyQuestion constructor The constructor takes possible arguments an creates an instance of the Sur...

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

+ 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 @access public

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

283 {
284 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
285 $a_xml_writer = new ilXmlWriter;
286 $a_xml_writer->xmlHeader();
287 $this->insertXML($a_xml_writer, $a_include_header, $obligatory_state);
288 $xml = $a_xml_writer->xmlDumpMem(FALSE);
289 if (!$a_include_header)
290 {
291 $pos = strpos($xml, "?>");
292 $xml = substr($xml, $pos + 2);
293 }
294 return $xml;
295 }
insertXML(&$a_xml_writer, $a_include_header=TRUE, $obligatory_state="")
Adds the question XML to a given XMLWriter object.
XML writer class.
xmlHeader()
Writes xml header @access public.

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

+ 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 @access public

Reimplemented from SurveyQuestion.

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

929 {
930 return TRUE;
931 }

Field Documentation

◆ $categories

SurveySingleChoiceQuestion::$categories

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

Referenced by getCategories(), and getCategoriesForPhrase().


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