Actions

SetVariableExpressionEnd: Difference between revisions

From LimeSurvey Manual

(Page creation)
 
(More detail and add plugins samples)
Line 4: Line 4:




'''Usage'''
## Usage


This event happen when Expression Manager is constructed. It allow to update know variables array by expression.  
This event happen when Expression Manager is constructed. It allow to update know variables array by expression.  


'''Input'''
## Input


* surveyId : the related survey id
* surveyId : the related survey id
Line 15: Line 15:
* newExpressionSuffixes : and empty array by default. To be added as expression suffix (like .question, .NAOK etc …)
* newExpressionSuffixes : and empty array by default. To be added as expression suffix (like .question, .NAOK etc …)


'''Possible output'''
## Possible output


* knownVars : The new knowVars
* knownVars : The new knowVars


'''Some detail of knowVars'''
### Some detail of knowVars


knowVars are array of variables know by expression manager. Key are the variables
knowVars are array of variables know by expression manager. Key are the variables.
 
{{Alert|Update knowVars in your plugins can break LimeSurvey core functionnality.}}


LimeSurvey core have 2 types of variables for knowVars :  
LimeSurvey core have 2 types of variables for knowVars :  
Line 65: Line 67:
);
);
</syntaxhighlight>
</syntaxhighlight>
### About Expression Suffixes
When Expression Manager get a variables, if there are no suffix, default one is code. If you want to add new suffixes : you can add it in newExpressionSuffixes. Currently only «Fixed» suffix is allowed. Value of the suffix is same in PHP and javascript.
## Sample plugins
* [https://github.com/LimeSurvey/LimeSurvey/tree/develop/plugins/expressionFixedDbVar expressionFixedDbVar]
* [https://github.com/LimeSurvey/LimeSurvey/tree/develop/plugins/expressionQuestionForAll expressionQuestionForAll]
* [https://github.com/LimeSurvey/LimeSurvey/tree/develop/plugins/expressionQuestionHelp expressionQuestionHelp]

Revision as of 16:48, 5 August 2019

 Hint: This features is available starting in version 4.0.0


  This feature is currently implemented in beta version of LimeSurvey.



    1. Usage

This event happen when Expression Manager is constructed. It allow to update know variables array by expression.

    1. Input
  • surveyId : the related survey id
  • language : the related language
  • knownVars : the current known Variables by expression.
  • newExpressionSuffixes : and empty array by default. To be added as expression suffix (like .question, .NAOK etc …)
    1. Possible output
  • knownVars : The new knowVars
      1. Some detail of knowVars

knowVars are array of variables know by expression manager. Key are the variables.

  Update knowVars in your plugins can break LimeSurvey core functionnality.


LimeSurvey core have 2 types of variables for knowVars :

  • Value fixed by template or survey or current view : SID, SURVEYURL, QID …
  • Value from response of the user.

Fixed variables are stored as

$knownVars[$variable] = array(
    'code' => // the static value for the variable
    'type' => // ''
    'jsName_on' => // ''
    'jsName' => // ''
    'readWrite' => // 'N' - since these are always read-only variables
);

Dynamic variables are stored as

$knownVars[$sgqa] = array(
    'jsName_on' => // the name of the javascript variable if it is defined on the current page - often 'answerSGQA'
    'jsName' => // the name of the javascript variable when referenced  on different pages - usually 'javaSGQA'
    'readWrite' => // 'Y' for yes, 'N' for no - currently not used
    'hidden' => // 1 if the question attribute 'hidden' is true, otherwise 0
    'question' => // the text of the question (or subquestion)
    'qid' => // the numeric question id - e.g. the Q part of the SGQA name
    'gid' => // the numeric group id - e.g. the G part of the SGQA name
    'grelevance' =>  // the group level relevance string
    'relevance' => // the question level relevance string
    'qcode' => // the qcode-style variable name for this question  (or subquestion)
    'qseq' => // the 0-based index of the question within the survey
    'gseq' => // the 0-based index of the group within the survey
    'type' => // the single character type code for the question
    'sgqa' => // the SGQA name for the variable
    'ansList' => // ansArray converted to a JavaScript fragment - e.g. ",'answers':{ 'M':'Male','F':'Female'}"
    'ansArray' => // PHP array of answer strings, keyed on the answer code = e.g. array['M']='Male';
    'scale_id' => // '0' for most answers.  '1' for second scale within dual-scale questions
    'rootVarName' => // the root code / name / title for the question, without any subquestion or answer-level suffix.  This is from the title column in the questions table
    'subqtext' => // the subquestion text
    'rowdivid' => // the JavaScript ID of the row identifier for a question.  This is used to show/hide entire question rows
    'onlynum' => // 1 if only numbers are allowed for this variable.  If so, then extra processing is needed to ensure that can use comma as a decimal separator
);
      1. About Expression Suffixes

When Expression Manager get a variables, if there are no suffix, default one is code. If you want to add new suffixes : you can add it in newExpressionSuffixes. Currently only «Fixed» suffix is allowed. Value of the suffix is same in PHP and javascript.

    1. Sample plugins