Skip to content

Commit

Permalink
Dev Added survey specific settings viewing and saving.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Mar 5, 2013
1 parent 320f144 commit 8a23ea1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
10 changes: 10 additions & 0 deletions application/controllers/admin/database.php
Expand Up @@ -965,6 +965,16 @@ function index($sa = null)

if (($action == "updatesurveysettingsandeditlocalesettings" || $action == "updatesurveysettings") && hasSurveyPermission($surveyid,'surveysettings','update'))
{
// Save plugin settings.
$pluginSettings = App()->request->getPost('plugin', array());
foreach($pluginSettings as $plugin => $settings)
{
$settingsEvent = new PluginEvent('newSurveySettings');
$settingsEvent->set('settings', $settings);
$settingsEvent->set('survey', $surveyid);
App()->getPluginManager()->dispatchEvent($settingsEvent, $plugin);
}

Yii::app()->loadHelper('surveytranslator');
Yii::app()->loadHelper('database');
$formatdata=getDateFormatData(Yii::app()->session['dateformat']);
Expand Down
5 changes: 5 additions & 0 deletions application/controllers/admin/surveyadmin.php
Expand Up @@ -1233,6 +1233,11 @@ private function _generalTabEditSurvey($iSurveyID, $esrow)
$aData['clang'] = $clang;
$aData['esrow'] = $esrow;
$aData['surveyid'] = $iSurveyID;

$beforeSurveySettings = new PluginEvent('beforeSurveySettings');
$beforeSurveySettings->set('survey', $iSurveyID);
App()->getPluginManager()->dispatchEvent($beforeSurveySettings);
$aData['pluginSettings'] = $beforeSurveySettings->get('surveysettings');
return $aData;
}

Expand Down
Expand Up @@ -54,5 +54,21 @@
<li><label for='faxto'><?php $clang->eT("Fax to:"); ?></label>
<input type='text' size='50' id='faxto' name='faxto' value="<?php echo $esrow['faxto']; ?>" />
</li>
<?php
if (isset($pluginSettings))
{
Yii::import('application.helpers.PluginSettingsHelper');
$PluginSettings = new PluginSettingsHelper();
foreach ($pluginSettings as $id => $plugin)
{
foreach ($plugin['settings'] as $name => $setting)
{
$name = "plugin[{$plugin['name']}][$name]";
echo CHtml::tag('li', array(), $PluginSettings->renderSetting($name, $setting, null, true));
}
}
}

?>
</ul>
</div>
16 changes: 1 addition & 15 deletions plugins/Example/Example.php
Expand Up @@ -23,7 +23,6 @@ public function __construct(PluginManager $manager, $id) {
* Here you should handle subscribing to the events your plugin will handle
*/
$this->subscribe('afterPluginLoad', 'helloWorld');
$this->subscribe('afterAdminMenuLoaded');
$this->subscribe('beforeSurveySettings');
$this->subscribe('newSurveySettings');
}
Expand All @@ -32,19 +31,6 @@ public function __construct(PluginManager $manager, $id) {
/*
* Below are the actual methods that handle events
*/

public function afterAdminMenuLoaded(PluginEvent $event)
{
$menu = $event->get('menu', array());
$menu['left'][]=array(
'href' => "http://docs.limesurvey.org",
'alt' => gT('LimeSurvey online manual'),
'image' => 'showhelp.png'
);

$event->set('menu', $menu);
}

public function helloWorld(PluginEvent $event)
{
$this->pluginManager->getAPI()->setFlash($this->get('message', null, null, 'Example popup. Change this via plugin settings.'));
Expand All @@ -63,7 +49,7 @@ public function beforeSurveySettings(PluginEvent $event)
'settings' => array(
'message' => array(
'type' => 'string',
'label' => 'Message to show to users:',
'label' => 'Example survey specific setting (not used):',
'current' => $this->get('message', 'Survey', $event->get('survey'))
)
)
Expand Down
Binary file added plugins/Example/assets/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8a23ea1

Please sign in to comment.