Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Possible? Datebase SELECT shown in Attribute_X

  • LS_SR
  • LS_SR's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 11 months ago - 8 years 11 months ago #119258 by LS_SR
Hello,

I was wondering if and how it is possible that a {TOKEN:ATTRIBUTE_1} can show a value from another non-limesurvey-table (but same database).

For example within MYSQL I have a table called tblThanks
And I want that the participant can see his 'thanks' shown in the survey. The thanks are stored in a non-limesurvey-table.
Code:
SELECT tblExample.tid, Sum(tblExample.thanks) AS SumThanks
FROM lime_tokens_111111 INNER JOIN tblExample ON lime_tokens_111111.tid = tblExample.tid
GROUP BY tblExample.tid, lime_tokens_111111.token
HAVING (((lime_tokens_111111.token.token) Like '{TOKEN:TOKEN}'));
Last edit: 8 years 11 months ago by LS_SR.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 11 months ago #119282 by DenisChenu
Replied by DenisChenu on topic Possible? Datebase SELECT shown in Attribute_X
Hi,

Extend EM is on projet, but we need to simplify, then rewrite it before.

All is done in helper/expression/em_core_helper.php ... a really big file with really big function.

Actually : we don't have included solution ...

BUT : you can do a plugin to search in the database with beforeSurveyPage and fill a "hidden" question with the answer.
Something like that (very quick)
Code:
public function beforeSurveyPage()
{
    $questionId="123X45X67"; // SGQA style
    $oEvent=$this->getEvent();
    $iSurveyId=$oEvent->get('surveyId');
    $sessionSurvey=Yii::app()->session["survey_{$iSurveyId}"];
    if($sessionSurvey && empty($sessionSurvey[$questionId]) && !empty($sessionSurvey['token'])))
    {
        $sessionSurvey[$questionId]=$this->callFuction($sessionSurvey['token']);
        Yii::app()->session["survey_{$iSurveyId}"]=$sessionSurvey;
    }
}
 
private function callFuction($sToken)
{
    // Here the best is to create a new connexion DB with Yii and use Yii to find the information
    // But i think Yii can accept another method
    // See https://gitlab.com/Shnoulle-LimeSurvey-plugin/authWPbyDB/blob/master/AuthWPbyDB.php#L193 for an example
}

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.
The following user(s) said Thank You: LS_SR
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose