- Posts: 57
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Share settings in two plugins
- sodiumchl
- Topic Author
- Offline
- Senior Member
Less
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.
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13645
- Thank you received: 2491
3 years 1 month ago - 3 years 1 month ago #212651
by DenisChenu
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.
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 :
A solution can be
But you can not create a Plugin object like this.
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 :
No because you are inside plugin B, then you get mySurveySetting of plugin B.//This should print "Something to test", but is NULL if called from another plugin
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
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 57
- Thank you received: 1
3 years 1 month ago #212815
by sodiumchl
Replied by sodiumchl on topic Share settings in two plugins
Thanks!
The topic has been locked.