DEV Community

Bismark
Bismark

Posted on

LimeSurvey afterSurveyComplete event

In my first article I created a simple plugin for LimeSurvey.
Now we want to add some text to the last page, when the user executes the survey.
LimeSurvey offers an event afterSurveyComplete.

All we have to to now is to subscribe to that event and implement an event handler method:

public function init()
{
    $this->subscribe('afterSurveyComplete');
}
Enter fullscreen mode Exit fullscreen mode

A minimal implementation looks like this.

public function afterSurveyComplete()
{
    $event = $this->getEvent();
    $event->getContent($this)->addContent('Hello World');
}
Enter fullscreen mode Exit fullscreen mode

For further processing, the event provides 2 parameters surveyId and responseId.


public function afterSurveyComplete()
{
    $event = $this->getEvent();

    $surveyId   = $event->get('surveyId');
    $responseId = $event->get('responseId');

    $response   = $this->pluginManager->getAPI()->getResponse($surveyId, $responseId);

    $myContent  = var_export($response, true);

    $event->getContent($this)->addContent($myContent);
}

Enter fullscreen mode Exit fullscreen mode

That's it.
Bye!

Discussion (0)