Skip to content

Commit

Permalink
Dev Fixed internal server error when no logging is used.
Browse files Browse the repository at this point in the history
Dev Added new plugin.
Dev Added plugin-survey settings...
  • Loading branch information
Sam committed Jan 24, 2013
1 parent f1ba544 commit c4acc85
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 39 deletions.
12 changes: 0 additions & 12 deletions application/controllers/PluginsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
*/
class PluginsController extends LSYii_Controller
{
protected $helpers = array(
'PluginSettings'
);

/**
* Stored dynamic properties set and unset via __get and __set.
* @var array of mixed.
Expand Down Expand Up @@ -117,14 +113,6 @@ public function actionConfigure($id)

public function beforeRender($view) {
parent::beforeRender($view);
// Load configured helpers.
foreach ($this->helpers as $helper)
{
$class = "{$helper}Helper";
Yii::import("application.helpers.$class");
$this->$helper = new $class;
}

return true;
}

Expand Down
12 changes: 10 additions & 2 deletions application/controllers/admin/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,6 @@ function index($sa = null)
$languagelist[]=Survey::model()->findByPk($surveyid)->language;

Yii::app()->loadHelper('database');

foreach ($languagelist as $langname)
{
if ($langname)
Expand Down Expand Up @@ -891,6 +890,16 @@ function index($sa = null)

if (($action == "updatesurveysettingsandeditlocalesettings" || $action == "updatesurveysettings") && hasSurveyPermission($surveyid,'surveysettings','update'))
{
// Save plugin settings.
$pluginSettings = App()->request->getPost('plugin', array());
var_dump($pluginSettings);
App()->getPluginManager()->s
die();
foreach($pluginSettings as $plugin => $settings)
{

}

Yii::app()->loadHelper('surveytranslator');
Yii::app()->loadHelper('database');
$formatdata=getDateFormatData(Yii::app()->session['dateformat']);
Expand Down Expand Up @@ -926,7 +935,6 @@ function index($sa = null)
{
$tokenlength = 15;
}

cleanLanguagesFromSurvey($surveyid,Yii::app()->request->getPost('languageids'));

fixLanguageConsistency($surveyid,Yii::app()->request->getPost('languageids'));
Expand Down
18 changes: 15 additions & 3 deletions application/controllers/admin/surveyadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ function editsurveysettings($iSurveyID)
$aData = array_merge($aData, $this->_tabPanelIntegration($esrow));
$aData = array_merge($aData, $this->_tabResourceManagement($iSurveyID));





$oResult = Questions::model()->with('groups')->with('question_types')->with('parents')->findAllByAttributes(array('sid' => $iSurveyID, 'language' => $esrow['language']), array('index' => 'qid', 'order' => 'group_order, t.question_order'));
$questions=array();
foreach ($oResult as $result)
Expand All @@ -203,7 +207,7 @@ function editsurveysettings($iSurveyID)
$aData['display']['menu_bars']['surveysummary'] = "editsurveysettings";
$tempData = $aData;
$aData['data'] = $tempData;

$this->_renderWrappedTemplate('survey', 'editSurvey_view', $aData);
}

Expand Down Expand Up @@ -800,6 +804,7 @@ public function editlocalsettings($iSurveyID)
$aViewUrls['output'] = PrepareEditorScript(false, $this->getController());

$i = 0;

foreach ($grplangs as $grouplang)
{
// this one is created to get the right default texts fo each language
Expand All @@ -818,7 +823,6 @@ public function editlocalsettings($iSurveyID)
$aData['esrow'] = $esrow;
$aData['action'] = "editsurveylocalesettings";
$aData['clang'] = $clang;

$tab_content[$i] = $this->getController()->render('/admin/survey/editLocalSettings_view', $aData, true);

$i++;
Expand All @@ -845,8 +849,10 @@ public function editlocalsettings($iSurveyID)
$aViewUrls[] = 'editLocalSettings_main_view';
}
else
{
$this->getController()->error('Access denied');

}

$this->_renderWrappedTemplate('survey', $aViewUrls, $aData);
}

Expand Down Expand Up @@ -1226,6 +1232,12 @@ 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
2 changes: 2 additions & 0 deletions application/controllers/survey/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ function action()
$data['sitename'] = Yii::app()->getConfig("sitename");
$data['languagechanger'] = makeLanguageChanger($sDisplayLanguage);



//A nice exit
sendCacheHeaders();
doHeader();
Expand Down
19 changes: 19 additions & 0 deletions application/helpers/PluginSettingsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ public function renderString($name, array $metaData, $form = null)
}
$out .= CHtml::textField($id, $value, array('id' => $id, 'form' => $form));

return $out;
}


public function renderBoolean($name, array $metaData, $form = null)
{
$out = '';
$id = $name;
$value = isset($metaData['current']) ? $metaData['current'] : '';
if (isset($metaData['label']))
{
$out .= CHtml::label($metaData['label'], $id);
}
$out .= CHtml::radioButtonList($id, $value, array(
0 => 'False',
1 => 'True'
), array('id' => $id, 'form' => $form));


return $out;
}
}
Expand Down
44 changes: 38 additions & 6 deletions application/libraries/PluginManager/PluginEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,39 @@ public function __construct($event, $sender = null)
* @param mixed $default
* @return mixed
*/
public function get($key, $default = null)
public function get($key = null, $default = null)
{
if (!array_key_exists($key, $this->_parameters))
if ($key != null)
{
return $default;
} else {
return $this->_parameters[$key];
$keys = explode('.', $key);
$array = $this->_parameters;

// Retrieve using dot notation.
while (count($keys) > 1)
{
$first = array_shift($keys);
if (isset($array[$first]))
{
$array = $array[$first];
}
else
{
return $default;
}
}

if (isset($array[$keys[0]]))
{
return $array[$keys[0]];
}
else
{
return $default;
}
}
else
{
return $this->_parameters;
}
}

Expand Down Expand Up @@ -104,7 +130,13 @@ public function getSender()
*/
public function set($key, $value)
{
$this->_parameters[$key] = $value;
// Split by . to allow for arrays using dotnotation.
$keys = explode('.', $key);
while (count($keys) > 1)
{
$value = array(array_pop($keys) => $value);
}
$this->_parameters[$keys[0]] = $value;

return $this;
}
Expand Down
Original file line number Diff line number Diff line change
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[$id][$name]";
echo CHtml::tag('li', array(), $PluginSettings->renderSetting($name, $setting, null, true));
}
}
}

?>
</ul>
</div>
32 changes: 16 additions & 16 deletions application/views/plugins/configure.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<div id="plugin-<?php echo $plugin['name']; ?>">
<h1>Settings for plugin "<?php echo $plugin['name']; ?>".</h1>
<div class="pluginsettings">
<?php

Yii::import("application.helpers.PluginSettingsHelper");
$PluginSettings = new PluginSettingsHelper();

echo CHtml::beginForm('', 'post', array('id' => "pluginsettings-{$plugin['name']}"));

<h1>Settings for plugin "<?php echo $plugin['name']; ?>".</h1>
<div class="pluginsettings">
<?php
foreach ($settings as $name => $setting)
{
$PluginSettings->renderSetting($name, $setting, "pluginsettings-{$plugin['name']}");
}
echo CHtml::submitButton('Save plugin settings');
echo CHtml::endForm();

// @var PluginsController Description
$this;

echo CHtml::beginForm('', 'post', array('id' => 'pluginsettings'));

foreach ($settings as $name => $setting)
{
$this->PluginSettings->renderSetting($name, $setting, 'pluginsettings');
}
echo CHtml::submitButton('Save plugin settings');
echo CHtml::endForm();

?>
?>

</div>
</div>
21 changes: 21 additions & 0 deletions plugins/Example/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Example extends PluginBase {
public function registerEvents() {
$this->subscribe('dummyEvent', 'helloWorld');
$this->subscribe('afterAdminMenuLoaded');
$this->subscribe('beforeSurveySettings');
}

/*
Expand All @@ -43,5 +44,25 @@ public function helloWorld(PluginEvent $event)
Yii::app()->session['flashmessage'] = $this->get('message') . $count;
$this->set('count', $count);
}


/**
* This event is fired by the administration panel to gather extra settings
* available for a survey.
* The plugin should return setting meta data.
* @param PluginEvent $event
*/
public function beforeSurveySettings(PluginEvent $event)
{
$event->set("surveysettings.{$this->id}", array(
'name' => get_class($this),
'settings' => array(
'message' => array(
'type' => 'string',
'label' => 'Message to show to users:'
)
)
));
}

}
73 changes: 73 additions & 0 deletions plugins/Maintenance/Maintenance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

class Maintenance extends PluginBase
{

protected $storage = 'DbStorage';
static protected $description = 'Maintenance mode plugin';

protected $settings = array(
'maintenance' => array(
'type' => 'boolean',
'label' => 'Enable maintence mode:'
),
'message' => array(
'type' => 'string',
'label' => 'Message to show to users:'
)
);

/**
* Here you should handle subscribing to the events your plugin will handle
*/
public function registerEvents() {
// Only describe to events if in maintenance mode.
if ($this->get('maintenance') == 1)
{
$this->subscribe('beforeLogin');
$this->subscribe('beforeSurveyController');
}
}

public function __construct(PluginManager $pluginManager, $id)
{
parent::__construct($pluginManager, $id);
}


public function beforeLogin(PluginEvent $event)
{
if ($this->get('maintenance') == 1)
{
$user = $event->get('user');
if ($user == null || $user->superadmin != 1)
{
Yii::app()->session['flashmessage'] = 'Login denied for non-super-users. Maintenance mode is active.';
$event->stop();
}
}
}

public function beforeSurveyController(PluginEvent $event)
{
$event->stop();
// Render an alternative view.
echo $this->get('message');
}



}












?>

0 comments on commit c4acc85

Please sign in to comment.