Question Objects

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

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.

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