Actions

Question Objects

From LimeSurvey Manual

DEPRECATED DEPRECATED DEPRECATED DEPRECATED

New wiki page: https://manual.limesurvey.org/Question_object_types


As of LimeSurvey 2.0, questions type were internally identified by a single character. That is, a display question was represented by 'X' while a list question was represented by 'L' etc. Unfortunately, this made adding and altering question types incredibly difficult since code for each question type was spread across literally dozens of files. To make it easier for independent developers to add and modify question types, each question will have it's own class in the application/modules folder. These classes will contain all question-type-specific code.

There are 3 abstract question classes: QuestionModule, ArrayQuestion, and TextQuestion. All the question classes (including Array and Text) extend QuestionModule and end in "Question." Below is a list of class names and descriptions.

Description Class Prefix Legacy Character Code Parent (if blank assume QuestionModule)
5 point choice FiveList 5
List (dropdown) Select ! List
List (radio) List L
List with comment CommentList O List
Array RadioArray F Array
Array (10 point choice) TenRadioArray B RadioArray
Array (5 point choice) FiveRadioArray A RadioArray
Array (Increase/Same/Decrease) IDRadioArray E RadioArray
Array (Numbers) NumberArray : Array
Array (Texts) TextArray ; Array
Array (Yes/No/Uncertain) YNRadioArray C RadioArray
Array by column ColumnRadioArray H RadioArray
Array dual scale DualRadioArray 1 RadioArray
Date/Time Date D
Equation Equation *
File upload File pipe character
Gender Gender G
Language switch Language I
Multiple numerical input Multinumerical K
Numerical input Numerical N
Ranking Ranking R
Text display Display X
Yes/No YN Y
Huge free text HugeText U Text
Long free text LongText T Text
Multiple short text Multitext Q
Short free text ShortText S Text
Multiple choice Check M
Multiple choice with comments CommentCheck P Check

Each of these classes contains (or inherits) a number of public methods that are abstracted by the QuestionModule class. To execute this question specific code, the question class is loaded out of the database, the object is dynamically instantiated and the relevant function is called. The question objects store question id, group id, survey id, question text, and other relevant data. Question objects then become a very useful way to pass around data instead of the previously used arrays.

These question objects come with two new database tables. First, a question types table stores a list of type ids, group ids, description, and legacy character code. There is a new int tid column in the questions table that replaces the type column and maps to the tid column in the new question types table. In addition, there is a new question type groups table that contains a group id, a description, and an order. This configuration will allow for backend configuration in the future, and ultimately, custom question types that can be shared among the community.

One of the biggest advantages of switching from procedural code to object-oriented code is that it will both allow developers to easily create custom question types by extending any of the existing question types. In order to do this, a developer can either extend one of the predefined question types and override one or more of the methods (such as getAnswerHTML() which returns the HTML code that renders each question) or by extending the base QuestionModule class or one of the other abstract classes and implementing its abstract methods.

Abstract Method† Functionality
getAnswerHTML Returns the HTML for the question
getDataEntry Returns the HTML for manually entering survey data from the backend
availableAttributes Returns an array of attributes the question can have in the question_attributes table
questionProperties Returns an array of question properties including description, group name, whether the class has subquestions, css class name, whether the class has default values, whether the class is assessable, and whether the class has answer scales

†Once the porting of the question objects is completed, a table will be added with a complete list of methods both abstract and extendable.