- Posts: 23
- Thank you received: 6
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Plugin Event for Partially completed surveys
- aellison9
- Topic Author
- Offline
- Junior Member
Less
More
5 years 3 weeks ago #182627
by aellison9
Plugin Event for Partially completed surveys was created by aellison9
We have a scenario where we want to take action in another application as a survey participant progresses through a survey. Since Limesurvey updates the response record as a participant progresses, we felt the best design approach would be to leverage a Plugin Event to extract the response.
The logical Event seemed to be "afterResponseSave", but it does not appear to be triggered at any point during a participant's interaction with a survey.
The "afterSurveyComplete" event works as intended but that doesn't get us what we need for partially completed surveys.
I did see a previous topic on events and Denis mentioned "afterResponseSave" might not be working as intended. If this is still true, does anyone have any suggestions for alternative ways using a plugin event to accomplish the goal of being notified each time a response is saved? Obviously, we could use a database trigger but would prefer to use plugin events if possible.
Thanks in advance for any thoughts.
$config = '3.15.6';
$config = 355;
$config = '190108';
$config = true;
$config = '30070';
I've attached a small sample survey and the plugin log from my testing using the following code. The purpose of the code was to just see how and when various events were being called. You can see that "afterResponseSave" and "afterSurveySave" are never reported as being invoked when you run through the sample survey.
The logical Event seemed to be "afterResponseSave", but it does not appear to be triggered at any point during a participant's interaction with a survey.
The "afterSurveyComplete" event works as intended but that doesn't get us what we need for partially completed surveys.
I did see a previous topic on events and Denis mentioned "afterResponseSave" might not be working as intended. If this is still true, does anyone have any suggestions for alternative ways using a plugin event to accomplish the goal of being notified each time a response is saved? Obviously, we could use a database trigger but would prefer to use plugin events if possible.
Thanks in advance for any thoughts.
$config = '3.15.6';
$config = 355;
$config = '190108';
$config = true;
$config = '30070';
I've attached a small sample survey and the plugin log from my testing using the following code. The purpose of the code was to just see how and when various events were being called. You can see that "afterResponseSave" and "afterSurveySave" are never reported as being invoked when you run through the sample survey.
Code:
<?php class ShowResponse extends PluginBase { protected $storage = 'DbStorage'; static protected $description = 'Demo: handle a survey response'; static protected $name = 'Show response'; public function init() { /** * Here you should handle subscribing to the events your plugin will handle */ $this->subscribe('afterSurveyComplete', 'logEvent'); $this->subscribe('afterModelSave', 'logEvent'); $this->subscribe('afterSurveyDynamicSave','logEvent'); $this->subscribe('afterSurveySave','logEvent'); $this->subscribe('afterResponseSave','logEvent'); } /* * Below are the actual methods that handle events */ public function logEvent() { $event = $this->getEvent(); $this->log($event->getEventName(). ' was triggered successfully.'); } }
Attachments:
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13648
- Thank you received: 2491
5 years 3 weeks ago - 5 years 3 weeks ago #182644
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic Plugin Event for Partially completed surveys
If you want something happen at each page when all action is done : you can use
manual.limesurvey.org/GetPluginTwigPath
It's a workaround, but it work …
See gitlab.com/SondagesPro/SurveyAccess/part...enSurveyFill.php#L47
You must use Yii::app and not $this->getEvent to do something not related to twig.
[edit]
afterSurveySave is related to model saving : manual.limesurvey.org/Specific_model_events not online survey save.
[edit2] either afterSurveyDynamicSave or afterResponseSave happen in 3.X, but it's fixed in 4.0 : github.com/LimeSurvey/LimeSurvey/commit/...2d1584bb3e59dd9b5bbc
It's a workaround, but it work …
See gitlab.com/SondagesPro/SurveyAccess/part...enSurveyFill.php#L47
You must use Yii::app and not $this->getEvent to do something not related to twig.
[edit]
afterSurveySave is related to model saving : manual.limesurvey.org/Specific_model_events not online survey save.
[edit2] either afterSurveyDynamicSave or afterResponseSave happen in 3.X, but it's fixed in 4.0 : github.com/LimeSurvey/LimeSurvey/commit/...2d1584bb3e59dd9b5bbc
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 5 years 3 weeks ago by DenisChenu. Reason: edit + edit2
The following user(s) said Thank You: aellison9
The topic has been locked.
- aellison9
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 6
5 years 3 weeks ago #182645
by aellison9
Replied by aellison9 on topic Plugin Event for Partially completed surveys
Thanks Denis. I appreciate the advice. I will give this a shot and let you know.
Do you think afterResponseSave will ever work reliably? Just asking for possible future applications.
Do you think afterResponseSave will ever work reliably? Just asking for possible future applications.
The topic has been locked.
- aellison9
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 6
5 years 3 weeks ago #182646
by aellison9
Replied by aellison9 on topic Plugin Event for Partially completed surveys
I added the event to my test plugin and ran through my sample survey. getPluginTwigPath seems to be invoked a lot which is going to result in duplicate responses being transmitted to the secondary application.
The event was called 10 times during the initial load of the survey. 3 times after the submit of the first question (clicking the next button). 1 time after the submit of the survey (click submit button).
Any thoughts on how to reduce the invocation frequency?
The event was called 10 times during the initial load of the survey. 3 times after the submit of the first question (clicking the next button). 1 time after the submit of the survey (click submit button).
Any thoughts on how to reduce the invocation frequency?
Code:
2019/04/01 17:11:34 [trace] [plugin.Show response] afterSurveyDynamicSave was triggered successfully. 2019/04/01 17:11:34 [trace] [plugin.Show response] afterModelSave was triggered successfully. 2019/04/01 17:11:34 [trace] [plugin.Show response] getPluginTwigPath was triggered successfully. 2019/04/01 17:11:34 [trace] [plugin.Show response] getPluginTwigPath was triggered successfully. 2019/04/01 17:11:34 [trace] [plugin.Show response] getPluginTwigPath was triggered successfully. 2019/04/01 17:11:34 [trace] [plugin.Show response] getPluginTwigPath was triggered successfully. 2019/04/01 17:11:34 [trace] [plugin.Show response] getPluginTwigPath was triggered successfully. 2019/04/01 17:11:34 [trace] [plugin.Show response] getPluginTwigPath was triggered successfully. 2019/04/01 17:11:34 [trace] [plugin.Show response] getPluginTwigPath was triggered successfully. 2019/04/01 17:11:34 [trace] [plugin.Show response] getPluginTwigPath was triggered successfully. 2019/04/01 17:11:34 [trace] [plugin.Show response] getPluginTwigPath was triggered successfully. 2019/04/01 17:11:34 [trace] [plugin.Show response] getPluginTwigPath was triggered successfully. 2019/04/01 17:11:43 [trace] [plugin.Show response] getPluginTwigPath was triggered successfully. 2019/04/01 17:11:43 [trace] [plugin.Show response] getPluginTwigPath was triggered successfully. 2019/04/01 17:11:43 [trace] [plugin.Show response] getPluginTwigPath was triggered successfully. 2019/04/01 17:11:52 [trace] [plugin.Show response] afterSurveyComplete was triggered successfully. 2019/04/01 17:11:52 [trace] [plugin.Show response] getPluginTwigPath was triggered successfully.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13648
- Thank you received: 2491
5 years 3 weeks ago - 5 years 3 weeks ago #182654
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic Plugin Event for Partially completed surveys
gitlab.com/SondagesPro/SurveyAccess/part...urveyFill.php#L49-52
Usage of static var
Alternative solution : beforeControllerAction, but need to test «move» param for example and ExpressionManager (in fact no LimeSurvey) action was not done.
Another maybe (unsure i didn't use a lot) manual.limesurvey.org/BeforeCloseHtml : no script inside , and no usage of twig, but for logging it can be used too.
About afterResponseSave+afterSurveyDynamicSave in 4.0 : i think it's the event to use.
Usage of static var
Alternative solution : beforeControllerAction, but need to test «move» param for example and ExpressionManager (in fact no LimeSurvey) action was not done.
Another maybe (unsure i didn't use a lot) manual.limesurvey.org/BeforeCloseHtml : no script inside , and no usage of twig, but for logging it can be used too.
About afterResponseSave+afterSurveyDynamicSave in 4.0 : i think it's the event to use.
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 5 years 3 weeks ago by DenisChenu.
The topic has been locked.
- aellison9
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 6
5 years 3 weeks ago #182736
by aellison9
Replied by aellison9 on topic Plugin Event for Partially completed surveys
Thanks again Denis.
The usage of the static var definitely helped with the multiple invocations of getPluginTwigPath. Now I am trying to track down the name of the "responseId" parameter and the response itself.
The beforeControllerAction event doesn't seem to have a key for surveyId or responseId. beforeCloseHtml has a key for surveyId but not responseId. Since we are interested in the responses as the participant moves through the survey, this is proving to be problematic. Of course, I could always be doing something wrong.
Thanks again for all of your patience and assistance.
The usage of the static var definitely helped with the multiple invocations of getPluginTwigPath. Now I am trying to track down the name of the "responseId" parameter and the response itself.
The beforeControllerAction event doesn't seem to have a key for surveyId or responseId. beforeCloseHtml has a key for surveyId but not responseId. Since we are interested in the responses as the participant moves through the survey, this is proving to be problematic. Of course, I could always be doing something wrong.
Thanks again for all of your patience and assistance.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13648
- Thank you received: 2491
5 years 3 weeks ago - 5 years 3 weeks ago #182739
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic Plugin Event for Partially completed surveys
You can use Yii and php for this :
1. Get the surveyId :
2. get the session :
3. Check the response id :
1. Get the surveyId :
Code:
$surveyId = Yii::app()->getRequest()->getParam("sid");
Code:
$session = Yii::app()->session['survey_'.$surveyId]
Code:
$srid = isset($session['srid']) ? $session['srid'] : null;
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 5 years 3 weeks ago by DenisChenu.
The following user(s) said Thank You: aellison9
The topic has been locked.