mbischof / LimeSurvey

The most popular FOSS online survey tool on the web.
https://www.limesurvey.org
Other
0 stars 0 forks source link

Basic Plugin #7

Open mbischof opened 4 years ago

mbischof commented 4 years ago

class SurveySettings extends PluginBase
{
    static protected $description = 'SurveySettings Plugin';
    static protected $name = 'SurveySettings';

    protected $storage = 'DbStorage';

    public function init()
    {
        $this->subscribe('beforeSurveySettings');
        $this->subscribe('newSurveySettings');
    }

    public function beforeSurveySettings()
    {
        $event = $this->event;
        $surveyId = intval($event->get('survey'));

        $event->set("surveysettings.{$this->id}", array(
            'name' => get_class($this),
            'settings' => array(
                'isActive' => array(
                    'type' => 'boolean',
                    'label' => 'enable for this survey',
                    'current' => $this->get('isActive', 'Survey', $surveyId, false)
                ),
            )
        ));
    }

    public function newSurveySettings()
    {
        $event = $this->event;
        foreach ($event->get('settings') as $name => $value) {
            $this->set($name, $value, 'Survey', $event->get('survey'));
        }
    }
}