Accessing database from survey. Ex: getting all previous answers of a token

More
2 months 4 weeks ago #174044 by LouisGac
LouisGac created the topic: Accessing database from survey. Ex: getting all previous answers of a token
In this thread:
www.limesurvey.org/forum/can-i-do-this-w...ow-survey-data-total

someone asked (again) to access to the previous answers of a given token from the survey itself.
We're often asked for those kind of functionalities, so I did it to show how to proceed:

github.com/LimeSurvey/LimeSurvey/commit/...bda5204cdcc8750efe16


For now, it implies to change a bit the core (internal.php and LS_Twig_Extension.php), but we will make it modular in the upcoming versions of LimeSurvey.

As you can see, in LS_Twig_Extension you can add new twig functions, written in PHP, that can access the DB via the models. So from here, you can do what ever you want. The function in LS_Twig_Extension must be then made accessible in the Sand Box inside internal.php (for security reason). From here, you can call that function from any twig file (survey/question theme)

Please Log in or Create an account to join the conversation.

More
2 months 4 weeks ago #174046 by jelo
jelo replied the topic: Accessing database from survey. Ex: getting all previous answers of a token
Thanks for pointing to your post. Wasn't aware of that.

LouisGac wrote: For now, it implies to change a bit the core (internal.php and LS_Twig_Extension.php), but we will make it modular in the upcoming versions of LimeSurvey.

That is an important point. I feel not comfortable suggesting workarounds with corechange.
Will hunt us back when updates or upgrades are applied or people forgot the corechange someone once did.

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?
www.limesurvey.org/forum/development/116...y-you-use-limesurvey

Please Log in or Create an account to join the conversation.

More
2 months 4 weeks ago #174047 by LouisGac
LouisGac replied the topic: Accessing database from survey. Ex: getting all previous answers of a token
it's like for question theming, we want to make it stable before making it openly modular.
but clearly: it is stable now.

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!