x

Main chapters

  1. LimeSurvey Cloud vs LimeSurvey CE
  2. LimeSurvey Cloud - Quick start guide
  3. LimeSurvey CE - Installation
  4. How to design a good survey (Guide)
  5. Getting started
  6. LimeSurvey configuration
  7. Introduction - Surveys
  8. View survey settings
  9. View survey menu
  10. View survey structure
  11. Introduction - Questions
  12. Introduction - Question Groups
  13. Introduction - Surveys - Management
  14. Survey toolbar options
  15. Multilingual survey
  16. Quick start guide - ExpressionScript
  17. Advanced features
  18. General FAQ
  19. Troubleshooting
  20. Workarounds
  21. License
  22. Version change log
  23. Plugins - Advanced
 Actions

Dynamic model events: Difference between revisions

From LimeSurvey Manual

DenisChenu (talk | contribs)
Page create + simple example
 
DenisChenu (talk | contribs)
m fix event name …⋅
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{FeatureChange|3.5.1}}
Before LimeSurvey 3.5.1 version : only token dynamic event can be used like that.
'''When'''
'''When'''


Line 7: Line 11:
*''model'' : The current model as a [https://www.yiiframework.com/doc/api/1.1/CActiveRecord ActiveRecord]
*''model'' : The current model as a [https://www.yiiframework.com/doc/api/1.1/CActiveRecord ActiveRecord]
*''dynamicId'' : if model extend Dynamic model ( ie Token and Response ). The related dynamic id
*''dynamicId'' : if model extend Dynamic model ( ie Token and Response ). The related dynamic id
*''iSurveyID'' and ''iSurveyID'' : The survey id if model is related to a survey id ( ie Token, TokenDynamic, Response, SurveyDynamic, Timing, SurveyTimingDynamic)
*''surveyId'' and ''iSurveyID'' : The survey id if model is related to a survey id ( ie Token, TokenDynamic, Response, SurveyDynamic, Timing, SurveyTimingDynamic)


'''Possible output'''
'''Possible output'''
Line 21: Line 25:
     function init()
     function init()
     {
     {
         $this->subscribe('afterTokenSave');
         $this->subscribe('afterResponseSave');
         $this->subscribe('afterTokenDynamicSave','afterTokenSave');
         $this->subscribe('afterSurveyDynamicSave','afterResponseSave');
     }
     }


public function afterTokenSave()
public function afterResponseSave()
{   
{   
     $surveyId = $this->getEvent()->get('surveyId');
     $surveyId = $this->getEvent()->get('surveyId');
Line 32: Line 36:
     } else {
     } else {
         // Log it somewhere
         // Log it somewhere
         $oToken = $this->getEvent()->get('model');
         $oResponse = $this->getEvent()->get('model');
         $this->log($oToken->token." updated in survey".$surveyId);
         $this->log($oResponse->id." updated in survey".$surveyId);
     }
     }
}
}
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 09:18, 15 November 2018

 Hint: This feature changed with version 3.5.1


Before LimeSurvey 3.5.1 version : only token dynamic event can be used like that.

When

Like Specific Model events.

Input

  • model : The current model as a ActiveRecord
  • dynamicId : if model extend Dynamic model ( ie Token and Response ). The related dynamic id
  • surveyId and iSurveyID : The survey id if model is related to a survey id ( ie Token, TokenDynamic, Response, SurveyDynamic, Timing, SurveyTimingDynamic)

Possible output

None.

Example of usage

See AuditLog

    function init()
    {
        $this->subscribe('afterResponseSave');
        $this->subscribe('afterSurveyDynamicSave','afterResponseSave');
    }

public function afterResponseSave()
{   
    $surveyId = $this->getEvent()->get('surveyId');
    if (empty($surveyId)) {
        // Something strange happen
    } else {
        // Log it somewhere
        $oResponse = $this->getEvent()->get('model');
        $this->log($oResponse->id." updated in survey".$surveyId);
    }
}