Actions

Defining attributes: Difference between revisions

From LimeSurvey Manual

No edit summary
 
No edit summary
Line 14: Line 14:
Example:
Example:


<syntaxhighlight lang="php" enclose="div">protected $attributes = array(
<syntaxhighlight lang="php" enclose="div">


           'question' => array(
protected $attributes = array(


               'type' => 'html',
   'question' => array(


               'localized' => true,
       'type' => 'html',


               'label' => 'Question text:'
       'localized' => true,


           ),
       'label' => 'Question text:'


           'help' => array(
   ),


               'type' => 'html',
   'help' => array(


               'localized' => true,
       'type' => 'html',


               'label' => 'Help text:'
       'localized' => true,


           ),
       'label' => 'Help text:'


           'mandatory' => array(
   ),


               'type' => 'boolean',
   'mandatory' => array(


               'label' => 'Mandatory:'
       'type' => 'boolean',


           ),
       'label' => 'Mandatory:'


           'display' => array(
   ),


               'label' => 'Display using:',
   'display' => array(


               'type' =>  'select',
       'label' => 'Display using:',


               'options' => array(
       'type' =>  'select',


                   'radio' => 'Radio buttons',
       'options' => array(


                   'dropdown' => 'Dropdown list'
           'radio' => 'Radio buttons',


               ),
           'dropdown' => 'Dropdown list'


               'localized' => false,
       ),


               'advanced' => false,
       'localized' => false,


               'default' => 'dropdown'
       'advanced' => false,


           )
       'default' => 'dropdown'


       );</syntaxhighlight>
   )
 
);
 
</syntaxhighlight>

Revision as of 00:12, 26 February 2013

Defining attributes for question types.

Attributes for question types are all configurable, non default, aspects of a question. A good example of an attribute is question text.

Question attributes are defined using an array with the name of the attribute as a key. An attribute definition supports several keys.

  • type - string: The data type of the attribute. Supported types are ('html', 'string', 'boolean', 'select')
  • localized - boolean: Whether this attribute should be configurable per language.
  • advanced - boolean: Whether this attribute should be shown in the default or advanced tab.
  • label - string: The label of the attribute in English (this is localized by the admin interface).
  • options - array(string-string): Contains the options for an attribute of type 'select'.
  • default - mixed: Contains the default value for the attribute.

Example:

protected $attributes = array(

   'question' => array(

       'type' => 'html',

       'localized' => true,

       'label' => 'Question text:'

   ),

   'help' => array(

       'type' => 'html',

       'localized' => true,

       'label' => 'Help text:'

   ),

   'mandatory' => array(

       'type' => 'boolean',

       'label' => 'Mandatory:'

   ),

   'display' => array(

       'label' => 'Display using:',

       'type' =>  'select',

       'options' => array(

           'radio' => 'Radio buttons',

           'dropdown' => 'Dropdown list'

       ),

       'localized' => false,

       'advanced' => false,

       'default' => 'dropdown'

   )

);