Welcome to the LimeSurvey Community Forum

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

Share settings in two plugins

More
5 years 7 months ago - 5 years 7 months ago #212646 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: 5 years 7 months ago by sodiumchl.
The topic has been locked.
More
5 years 7 months ago - 5 years 7 months ago #212651 by DenisChenu
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 support - Plugins, theme and development .
I don't answer to private message.
Last edit: 5 years 7 months ago by DenisChenu.
The following user(s) said Thank You: sodiumchl
The topic has been locked.
More
5 years 7 months ago #212815 by sodiumchl
Thanks!
The topic has been locked.
Moderators: holch, tpartner

Lime-years ahead

Online-surveys for every purse and purpose