- Posts: 31
- Thank you received: 5
Ask the community, share ideas, and connect with other LimeSurvey users!
<?php
class SurveyApproval extends PluginBase {
protected $storage = 'DbStorage';
static protected $description = 'This plugin prevents surveys from being published without approval.';
static protected $name = 'SurveyApproval';
protected $surveyId;
// global level settings for plugin
protected $settings = array();
public function init()
{
$this->subscribe('beforeSurveyActivate');
$this->subscribe('beforeSurveySettings'); // add new survey settings
$this->subscribe('newSurveySettings'); // save new survey settings
}
// survey level settings for plugin
public function beforeSurveySettings()
{
$this->log('beforeSurveySettings');
$oEvent = $this->event;
$oEvent->set("surveysettings.{$this->id}", array(
'name' => get_class($this),
'settings' => array(
'bSurveyIsApproved' => array(
'type' => 'boolean',
'label' => 'Survey approval received?',
'default' => 0,
'help' => 'Has this survey\'s questions, translations, accessibility, etc. been approved for publishing?',
'current' => $this->get('bSurveyIsApproved', 'Survey', $oEvent->get('survey'))
),
'bDebugMode' => array(
'type' => 'boolean',
'default' => 0,
'label' => 'Debug Mode',
'help' => 'This should be `Off` for live surveys.',
'current' => $this->get('bDebugMode', 'Survey', $oEvent->get('survey')),
)
)
));
}
public function newSurveySettings()
{
$this->log('newSurveySettings');
$oEvent = $this->event;
foreach ($oEvent->get('settings') as $name => $value)
{
$this->set($name, $value, 'Survey', $oEvent->get('survey'));
}
}
// ensure the survey is approved before users can activate it
public function beforeSurveyActivate()
{
$this->log('beforeSurveyActivate');
$this->log($this->get('bSurveyIsApproved'));// nothing is printed
$this->log($this->get('bDebugMode'));// nothing is printed
$this->log(is_null($this->get('bDebugMode')));// 1 is printed meaning the settings I get are NULL
if ($this->get('bSurveyIsApproved') == 0)
{
$oEvent = $this->getEvent();
$oEvent->set('success', false);
$oEvent->set('message', 'This survey cannot be activated. Before publishing a survey, it must be approved.');
}
}
}
$this->get('bDebugMode', 'Survey', $oEvent->get('survey')
Please Log in to join the conversation.
Please Log in to join the conversation.
I was using the key `survey` when I needed to use `surveyId`.$oEvent = $this->event;
$my_setting = $this->get('bSurveyIsApproved', 'Survey', $oEvent->get('surveyId'));
Please Log in to join the conversation.
Please Log in to join the conversation.