- Posts: 11956
- Thank you received: 2808
Ask the community, share ideas, and connect with other LimeSurvey users!
Updating LimeSurvey core are always a bad solution.holch wrote: Denis, not everyone is as firm with the plugin system for Limesurvey as you are.
kclingerman needed a quick solution and this is what he found. Might there be a better solution? Obviously, as you have shown. But we should be happy that he was giving back to the community, most people here are only taking.
We have an extandable system : we must give good advice on forum not broken advice ... that potentially broke update ...
<?php class CustomReplyTo extends PluginBase { protected $storage = 'DbStorage'; static protected $description = 'Set reply-to address'; static protected $name = 'CustomReplyTo'; public function init() { $this->subscribe('beforeEmail','beforeEmail'); $this->subscribe('beforeSurveyEmail','beforeEmail'); $this->subscribe('beforeTokenEmail','beforeEmail'); // Provides survey specific settings. $this->subscribe('beforeSurveySettings'); // Saves survey specific settings. $this->subscribe('newSurveySettings'); } public function beforeSurveySettings() { $pluginsettings = $this->getPluginSettings(true); $event = $this->getEvent(); $iSurveyID=$event->get('iSurveyID'); $event->set("surveysettings.{$iSurveyID}", array( 'name' => get_class($this), 'settings' => array( 'customReplyTo' => array( 'type' => 'string', 'label' => 'Custom Reply-To:', 'current' => $this->get('customReplyTo', 'Survey', $event->get('survey')) ) ) )); } /** * Save the settings */ public function newSurveySettings() { $event = $this->getEvent(); foreach ($event->get('settings') as $name => $value) { $this->set($name, $value, 'Survey', $event->get('survey')); } } /** * Set From and Bounce of PHPmailer to siteadminemail * @link https://www.limesurvey.org/manual/BeforeTokenEmail */ public function beforeEmail() { $emailsmtpuser = Yii::app()->getConfig('emailsmtpuser'); if(empty($emailsmtpuser)) { return; } $limeMailer = $this->getEvent()->get('mailer'); $limeMailer->AddReplyTo($this->get('customReplyTo', 'Survey', $event->get('survey'))); $this->getEvent()->set('updateDisable',$updateDisable); } }
$this->get('customReplyTo', 'Survey', $surveyId);
public function beforeEmail() { /* Global one (if you have a global settings array */ $customReplyTo = $this->get('customReplyTo'); /* get the current survey id */ $surveyId = $this->getEvent()->get('survey'); // Survey id as integer if($surveyId) { /* Maybe use globalk is empty ( == "") */ $customReplyTo = $this->get('customReplyTo', 'Survey', $surveyId); } if(empty($customReplyTo)) { return; } $limeMailer = $this->getEvent()->get('mailer'); $limeMailer->AddReplyTo($customReplyTo); }
class CustomReplyTo extends PluginBase { protected $storage = 'DbStorage'; static protected $description = 'Set reply-to address'; static protected $name = 'CustomReplyTo'; public function init() { $this->subscribe('beforeEmail','beforeEmail'); $this->subscribe('beforeSurveyEmail','beforeEmail'); $this->subscribe('beforeTokenEmail','beforeEmail'); // Provides survey specific settings. $this->subscribe('beforeSurveySettings'); // Saves survey specific settings. $this->subscribe('newSurveySettings'); } public function beforeSurveySettings() { $pluginsettings = $this->getPluginSettings(true); $event = $this->getEvent(); $iSurveyID=$event->get('iSurveyID'); $event->set("surveysettings.{$iSurveyID}", array( 'name' => get_class($this), 'settings' => array( 'customReplyTo' => array( 'type' => 'string', 'label' => 'Custom Reply-To:', 'current' => $this->get('customReplyTo', 'Survey', $event->get('survey')) ) ) )); } /** * Save the settings */ public function newSurveySettings() { $event = $this->getEvent(); foreach ($event->get('settings') as $name => $value) { $this->set($name, $value, 'Survey', $event->get('survey')); } } /** * Set From and Bounce of PHPmailer to siteadminemail * @link https://www.limesurvey.org/manual/BeforeTokenEmail */ public function beforeEmail() { /* Global one (if you have a global settings array */ $customReplyTo = $this->get('customReplyTo'); /* get the current survey id */ $surveyId = $this->getEvent()->get('survey'); // Survey id as integer if($surveyId) { /* Maybe use globalk is empty ( == "") */ $customReplyTo = $this->get('customReplyTo', 'Survey', $surveyId); } if(empty($customReplyTo)) { return; } $limeMailer = $this->getEvent()->get('mailer'); $limeMailer->AddReplyTo($customReplyTo); } }
Unsure,kclingerman wrote: The only issue I see now is when the plugin customToken is enabled, my customReplyTo plugin does not show up under the "Simple plugins" menu, only the customToken setting is shown. Is this an issue with limesurvey, or how the plugin was created?
$oEvent->set("surveysettings.{$this->id}", array(
$event->set("surveysettings.{$iSurveyID}", array(