Skip to content

Commit

Permalink
Dev Added automatic timestamping for fields created/modified in LSAct…
Browse files Browse the repository at this point in the history
…iveRecordTables

Dev Added AuditLog plugin base
  • Loading branch information
c-schmitz committed Mar 20, 2013
1 parent 906f299 commit e5bf860
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3 deletions.
2 changes: 0 additions & 2 deletions application/controllers/admin/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,6 @@ function index($sa = null)

$aURLParams=json_decode(Yii::app()->request->getPost('allurlparams'),true);
Survey_url_parameters::model()->deleteAllByAttributes(array('sid'=>$surveyid));
var_dump($aURLParams);
die();
foreach($aURLParams as $aURLParam)
{
$aURLParam['parameter']=trim($aURLParam['parameter']);
Expand Down
11 changes: 11 additions & 0 deletions application/models/LSActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
*/
class LSActiveRecord extends CActiveRecord
{

public function behaviors(){
return array(
'CTimestampBehavior' => array(
'class' => 'zii.behaviors.CTimestampBehavior',
'createAttribute' => 'created',
'updateAttribute' => 'modified',
)
);
}

/**
* Modified version that default to do the same as the original, but allows via a
* third parameter to retrieve the result as array instead of active records. This
Expand Down
2 changes: 1 addition & 1 deletion application/models/Survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

class Survey extends CActiveRecord
class Survey extends LSActiveRecord
{
/**
* This is a static cache, it lasts only during the active request. If you ever need
Expand Down
63 changes: 63 additions & 0 deletions plugins/AuditLog/AuditLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
class AuditLog extends PluginBase {

protected $storage = 'DbStorage';
static protected $description = 'Example plugin';

protected $settings = array(
'logo' => array(
'type' => 'logo',
'path' => 'assets/logo.png'
),
'message' => array(
'type' => 'string',
'label' => 'Message'
)
);

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


/**
* Here you should handle subscribing to the events your plugin will handle
*/
//$this->subscribe('afterPluginLoad', 'helloWorld');
$this->subscribe('beforeSurveySettings');
$this->subscribe('newSurveySettings');
}

/**
* 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(
'auditing' => array(
'type' => 'select',
'options'=>array(0=>'No',
1=>'Yes'),
'default'=>0,
'tab'=>'notification', // @todo: Setting no used yet
'category'=>'Auditing for person-related data', // @todo: Setting no used yet
'label' => 'Audit log for this survey:',
'current' => $this->get('auditing', 'Survey', $event->get('survey'))
)
)
));
}

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

}
Empty file.

0 comments on commit e5bf860

Please sign in to comment.