Skip to content

Commit

Permalink
Dev Working custom survye specific plugin settings!
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam committed Jan 24, 2013
1 parent c4acc85 commit b663c8d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
8 changes: 4 additions & 4 deletions application/controllers/admin/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -892,12 +892,12 @@ function index($sa = null)
{
// Save plugin settings.
$pluginSettings = App()->request->getPost('plugin', array());
var_dump($pluginSettings);
App()->getPluginManager()->s
die();
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');
Expand Down
3 changes: 2 additions & 1 deletion application/libraries/PluginManager/DbStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public function set($plugin, $key, $data, $model = null, $id = null) {
'plugin_id' => $plugin->getId(),
'model' => $model,
'model_id' => $id,
'key' => $key);
'key' => $key
);
$record = $this->model->findByAttributes($attributes);
if (is_null($record)) {
// New setting
Expand Down
2 changes: 1 addition & 1 deletion application/libraries/PluginManager/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function dispatchEvent(PluginEvent $event, $target = array())
foreach($this->subscriptions[$eventName] as $subscription)
{
if (!$event->isStopped()
&& (empty($target) || in_array($subscription[0], $target)))
&& (empty($target) || in_array(get_class($subscription[0]), $target)))
{
call_user_func($subscription, $event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
{
foreach ($plugin['settings'] as $name => $setting)
{
$name = "plugin[$id][$name]";
$name = "plugin[{$plugin['name']}][$name]";
echo CHtml::tag('li', array(), $PluginSettings->renderSetting($name, $setting, null, true));
}
}
Expand Down
13 changes: 12 additions & 1 deletion plugins/Example/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function registerEvents() {
$this->subscribe('dummyEvent', 'helloWorld');
$this->subscribe('afterAdminMenuLoaded');
$this->subscribe('beforeSurveySettings');
$this->subscribe('newSurveySettings');
}

/*
Expand Down Expand Up @@ -59,10 +60,20 @@ public function beforeSurveySettings(PluginEvent $event)
'settings' => array(
'message' => array(
'type' => 'string',
'label' => 'Message to show to users:'
'label' => 'Message to show to users:',
'current' => $this->get('message', 'Survey', $event->get('survey'))
)
)
));
}

public function newSurveySettings(PluginEvent $event)
{
foreach ($event->get('settings') as $name => $value)
{

$this->set($name, $value, 'Survey', $event->get('survey'));
}
}

}

0 comments on commit b663c8d

Please sign in to comment.