Welcome to the LimeSurvey Community Forum

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

Share settings in two plugins

  • sodiumchl
  • sodiumchl's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 1 month ago - 3 years 1 month ago #212646 by sodiumchl
Share settings in two plugins was created by sodiumchl
How can I put a setting in plugin A (survey level), and retrieve it from plugin B (question level), of the same survey?
The following works fine if everything is in plugin A. But it does not work if beforeQuestionRender() is in plugin B.
Code:
   //In plugin A
    public function beforeSurveySettings() {
        $this->event->set("surveysettings.{$this->id}", array(
            'name' => get_class($this),
            'settings' => array(
                'mySurveySetting'=> array(
                    'type'=>'info',
                    'content'=>'Something to test')),
                ),
            ),
        ));
    }
 
    public function newSurveySettings() {
        foreach ($this->event->get('settings') as $name => $value) {
            $this->set($name, $value, 'Survey', $this->event->get('survey'));
        }
    }
 
    //In plugin B
    public function beforeQuestionRender() {
        $oEvent=$this->getEvent();
        $sid = $oEvent->get('surveyId');
        $info = $this->get('mySurveySetting', 'Survey', $sid);
        //This should print "Something to test", but is NULL if called from another plugin
        var_dump($info);
    }
Last edit: 3 years 1 month ago by sodiumchl.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago - 3 years 1 month ago #212651 by DenisChenu
Replied by DenisChenu on topic Share settings in two plugins
I don't know if there are better solution,

But personaly i create a Uitilities class for this now

See
gitlab.com/SondagesPro/TokenManagement/T...er/Utilities.php#L55
and usage
gitlab.com/SondagesPro/TokenManagement/T...stAndManage.php#L215

I like to have a better solution :/

PS :

//This should print "Something to test", but is NULL if called from another plugin

No because you are inside plugin B, then you get mySurveySetting of plugin B.

A solution can be
Code:
$oPluginA = new PluginA();
$info = $oPluginA->get('mySurveySetting', 'Survey', $sid);

But you can not create a Plugin object like this.

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: 3 years 1 month ago by DenisChenu.
The following user(s) said Thank You: sodiumchl
The topic has been locked.
  • sodiumchl
  • sodiumchl's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 1 month ago #212815 by sodiumchl
Replied by sodiumchl on topic Share settings in two plugins
Thanks!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose