ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
SurveySingleChoiceQuestion Class Reference

SingleChoice survey question. More...

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

Public Member Functions

 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...
 
 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 public

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

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

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

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

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

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  }
$result
global $ilUser
Definition: imgupload.php:15
global $ilDB

◆ addStandardNumbers()

SurveySingleChoiceQuestion::addStandardNumbers (   $lower_limit,
  $upper_limit 
)

Adds standard numbers as categories.

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

Definition at line 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 public

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

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

816  {
817  // check if text answer column is needed
818  $other = false;
819  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
820  {
821  $cat = $this->categories->getCategory($i);
822  if ($cat->other)
823  {
824  $other = true;
825  break;
826  }
827  }
828 
829  if (count($resultset["answers"][$this->getId()]))
830  {
831  foreach ($resultset["answers"][$this->getId()] as $key => $answer)
832  {
833  array_push($a_array, $answer["value"]+1);
834 
835  // add the text answer from the selected option
836  if ($other)
837  {
838  array_push($a_array, $answer["textanswer"]);
839  }
840  }
841  }
842  else
843  {
844  array_push($a_array, $this->getSkippedValue());
845 
846  if ($other)
847  {
848  array_push($a_array, "");
849  }
850  }
851  }
getId()
Gets the id of the SurveyQuestion object.
+ 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 public

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

References SurveyQuestion\$title.

786  {
787  $title = parent::addUserSpecificResultsExportTitles($a_array, $a_use_label, $a_substitute);
788 
789  // optionally add header for text answer
790  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
791  {
792  $cat = $this->categories->getCategory($i);
793  if ($cat->other)
794  {
795  if(!$a_use_label || $a_substitute)
796  {
797  array_push($a_array, $title. ' - '. $this->lng->txt('other'));
798  }
799  else
800  {
801  array_push($a_array, "");
802  }
803  break;
804  }
805  }
806  }

◆ checkUserInput()

SurveySingleChoiceQuestion::checkUserInput (   $post_data,
  $survey_id 
)

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

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

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

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

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.
getId()
Gets the id of the SurveyQuestion object.
+ Here is the call graph for this function:

◆ getAdditionalTableName()

SurveySingleChoiceQuestion::getAdditionalTableName ( )

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

Returns
string The additional table name public

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

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

468  {
469  return "svy_qst_sc";
470  }
+ Here is the caller graph for this function:

◆ getAvailableRelations()

SurveySingleChoiceQuestion::getAvailableRelations ( )

Returns the available relations for the question.

Returns
array An array containing the available relations public

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

929  {
930  return array("<", "<=", "=", "<>", ">=", ">");
931  }

◆ getCategories()

SurveySingleChoiceQuestion::getCategories ( )

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

References $categories.

◆ getCategoriesForPhrase()

& SurveySingleChoiceQuestion::getCategoriesForPhrase (   $phrase_id)

Gets the available categories for a given phrase.

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

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

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

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  }
$result
global $ilDB

◆ getCumulatedResults()

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

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

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

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

◆ getPreconditionOptions()

SurveySingleChoiceQuestion::getPreconditionOptions ( )

Returns the options for preconditions.

Returns
array

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

References SurveyQuestion\$lng, and $options.

Referenced by getPreconditionSelectValue().

939  {
940  global $lng;
941 
942  $options = array();
943  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
944  {
945  $category = $this->categories->getCategory($i);
946  $options[$category->scale-1] = $category->scale . " - " . $category->title;
947  }
948  return $options;
949  }
if(!is_array($argv)) $options
+ Here is the caller graph for this function:

◆ getPreconditionSelectValue()

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

Creates a form property for the precondition value.

Returns
The ILIAS form element public

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

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

958  {
959  include_once "./Services/Form/classes/class.ilSelectInputGUI.php";
960  $step3 = new ilSelectInputGUI($title, $variable);
961  $options = $this->getPreconditionOptions();
962  $step3->setOptions($options);
963  $step3->setValue($default);
964  return $step3;
965  }
This class represents a selection list property in a property form.
getPreconditionOptions()
Returns the options for preconditions.
if(!is_array($argv)) $options
+ Here is the call graph for this function:

◆ getPreconditionValueOutput()

SurveySingleChoiceQuestion::getPreconditionValueOutput (   $value)

Returns the output for a precondition value.

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

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

975  {
976  // #18136
977  $category = $this->categories->getCategoryForScale($value+1);
978 
979  // #17895 - see getPreconditionOptions()
980  return $category->scale .
981  " - " .
982  ((strlen($category->title)) ? $category->title : $this->lng->txt('other_answer'));
983  }

◆ getQuestionType()

SurveySingleChoiceQuestion::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question public

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 public

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

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

861  {
862  global $ilDB;
863 
864  $answers = array();
865 
866  $sql = "SELECT svy_answer.* FROM svy_answer".
867  " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
868  " WHERE svy_answer.question_fi = ".$ilDB->quote($this->getId(), "integer").
869  " AND svy_finished.survey_fi = ".$ilDB->quote($survey_id, "integer");
870  if($finished_ids)
871  {
872  $sql .= " AND ".$ilDB->in("svy_finished.finished_id", $finished_ids, "", "integer");
873  }
874 
875  $result = $ilDB->query($sql);
876  while ($row = $ilDB->fetchAssoc($result))
877  {
878  $category = $this->categories->getCategoryForScale($row["value"]+1);
879  $title = $row["value"] + 1 . " - " . $category->title;
880  if ($category->other) $title .= ": " . $row["textanswer"];
881  $answers[$row["active_fi"]] = $title;
882  }
883  return $answers;
884  }
$result
getId()
Gets the id of the SurveyQuestion object.
global $ilDB
+ 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 public

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

References $data, and SurveyQuestion\getId().

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  }
getId()
Gets the id of the SurveyQuestion object.
+ Here is the call graph for this function:

◆ importAdditionalMetadata()

SurveySingleChoiceQuestion::importAdditionalMetadata (   $a_meta)

Import additional meta data from the question import file.

Usually the meta data section is used to store question elements which are not part of the standard XML schema.

Returns
array $a_meta Array containing the additional meta data public

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

References SurveyQuestion\setOrientation().

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.
+ Here is the call graph for this function:

◆ importResponses()

SurveySingleChoiceQuestion::importResponses (   $a_data)

Import response data from the question import file.

Returns
array $a_data Array containing the response data public

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

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

893  {
894  foreach ($a_data as $id => $data)
895  {
896  $categorytext = "";
897  foreach ($data["material"] as $material)
898  {
899  $categorytext .= $material["text"];
900  }
901  $this->categories->addCategory(
902  $categorytext,
903  strlen($data['other']) ? $data['other'] : 0,
904  strlen($data['neutral']) ? $data['neutral'] : 0,
905  strlen($data['label']) ? $data['label'] : null,
906  strlen($data['scale']) ? $data['scale'] : null
907  );
908  }
909  }

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

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

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

Referenced by toXML().

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  }
getAuthor()
Gets the authors name of the SurveyQuestion object.
getTitle()
Gets the title string of the SurveyQuestion object.
getObligatory($survey_id="")
Gets the obligatory state of the question.
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getOrientation()
Gets the orientation of the question output.
getId()
Gets the id of the SurveyQuestion object.
addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag=TRUE, $add_mobs=TRUE, $a_attrs=null)
Creates an XML material tag from a plain text or xhtml text.
getDescription()
Gets the description string of the SurveyQuestion object.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isComplete()

SurveySingleChoiceQuestion::isComplete ( )

Returns true if the question is complete for use.

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

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

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

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  }
getAuthor()
Gets the authors name of the SurveyQuestion object.
getTitle()
Gets the title string of the SurveyQuestion object.
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
+ Here is the call graph for this function:

◆ loadFromDb()

SurveySingleChoiceQuestion::loadFromDb (   $id)

Loads a SurveySingleChoiceQuestion object from the database.

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

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

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().

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  }
$result
setObligatory($obligatory=1)
Sets the obligatory state of the question.
setOrientation($orientation=0)
Sets the orientation of the question output.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
setId($id=-1)
Sets the id of the SurveyQuestion object.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
setOwner($owner="")
Sets the creator/owner ID of the SurveyQuestion object.
setComplete($a_complete)
Sets the complete state of the question.
setOriginalId($original_id)
setQuestiontext($questiontext="")
Sets the questiontext of the SurveyQuestion object.
setAuthor($author="")
Sets the authors name of the SurveyQuestion object.
setDescription($description="")
Sets the description string of the SurveyQuestion object.
global $ilDB
setObjId($obj_id=0)
Set the reference id of the container object.
setTitle($title="")
Sets the title string of the SurveyQuestion object.
+ Here is the call graph for this function:

◆ saveCategoriesToDb()

SurveySingleChoiceQuestion::saveCategoriesToDb ( )

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

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

Referenced by saveToDb().

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.
getId()
Gets the id of the SurveyQuestion object.
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ savePhrase()

SurveySingleChoiceQuestion::savePhrase (   $title)

Saves a set of categories to a default phrase.

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

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

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

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  }
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
global $ilUser
Definition: imgupload.php:15
global $ilDB

◆ 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

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

References $ilDB, and SurveyQuestion\getId().

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  }
getId()
Gets the id of the SurveyQuestion object.
global $ilDB
+ Here is the call graph for this function:

◆ saveToDb()

SurveySingleChoiceQuestion::saveToDb (   $original_id = "")

Saves a SurveySingleChoiceQuestion object to a database.

public

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

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

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  }
getAdditionalTableName()
Returns the name of the additional question data table in the database.
getOrientation()
Gets the orientation of the question output.
getId()
Gets the id of the SurveyQuestion object.
saveMaterial()
save material to db
global $ilDB
+ Here is the call graph for this function:

◆ saveUserInput()

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

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

References $ilDB, and SurveyQuestion\getId().

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  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
578  array('integer','integer','integer','float','text','integer'),
579  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())
580  );
581  }
getId()
Gets the id of the SurveyQuestion object.
global $ilDB
+ 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 public

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

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

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

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

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

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

◆ toXML()

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

Returns an xml representation of the question.

Returns
string The xml representation of the question public

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

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

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  }
XML writer class.
insertXML(&$a_xml_writer, $a_include_header=TRUE, $obligatory_state="")
Adds the question XML to a given XMLWriter object.
xmlHeader()
Writes xml header public.
+ Here is the call graph for this function:

◆ usableForPrecondition()

SurveySingleChoiceQuestion::usableForPrecondition ( )

Returns if the question is usable for preconditions.

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

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

918  {
919  return TRUE;
920  }

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: