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

More
8 months 5 days ago #174044 by LouisGac
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.

LimeSurvey Partners
More
8 months 5 days ago #174046 by jelo
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.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

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

More
8 months 5 days ago #174047 by LouisGac
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!