Skip to content

Commit

Permalink
fix when enableAuditField is set to in behavior options, fixes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
cornernote committed May 19, 2014
1 parent 2479284 commit 6578bd3
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions audit/components/AuditFieldBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ class AuditFieldBehavior extends CActiveRecordBehavior
/**
* Set to false if you just want to use getDbAttribute and other methods in this class.
* If left unset the value will come from AuditModule::enableAuditField
* @see getEnableAuditField()
* @see setEnableAuditField()
* @var bool
*/
public $enableAuditField;
private $_enableAuditField;

/**
* Any additional models you want to use to write model and model_id audits to. If this array is not empty then
Expand All @@ -49,18 +51,6 @@ class AuditFieldBehavior extends CActiveRecordBehavior
*/
private $_dbAttributes = array();

/**
*
*/
public function __construct()
{
if ($this->enableAuditField === null) {
/** @var AuditModule $audit */
$audit = Yii::app()->getModule('audit');
$this->enableAuditField = $audit->enableAuditField;
}
}

/**
* A list of fields to be ignored on update and delete
* @var array
Expand Down Expand Up @@ -337,4 +327,24 @@ protected function getModelPrimaryKeyString($model)
return is_array($model->getPrimaryKey()) ? implode('-', $model->getPrimaryKey()) : $model->getPrimaryKey();
}

/**
*
*/
public function getEnableAuditField()
{
if ($this->_enableAuditField === null) {
/** @var AuditModule $audit */
$audit = Yii::app()->getModule('audit');
$this->_enableAuditField = $audit->enableAuditField;
}
}

/**
* @param $enableAuditField
*/
public function setEnableAuditField($enableAuditField)
{
$this->_enableAuditField = $enableAuditField;
}

}

0 comments on commit 6578bd3

Please sign in to comment.