PHP Class AuditableBehavior

Store info about user which created entry, and user which modified an entry at the proper table. Also use a table called 'logs' (or other configurated for that) to save created/edited action for continuous changes history. Code comments in brazilian portuguese. ----- Behavior que permite log automágico de ações executadas em uma aplicação com usuários autenticados. Armazena informações do usuário que criou um registro, e do usuário que alterou o registro no próprio registro. Ainda utiliza um modelo auxiliar Logger (ou outro configurado para isso) para registrar ações de inserção/edição e manter um histórico contínuo de alterações. PHP version > 5.3.1 Licensed under The MIT License Redistributions of files must retain the above copyright notice.
Inheritance: extends ModelBehavior
显示文件 Open project: robwilkerson/cakephp-audit-log-plugin Class Usage Examples

Protected Properties

Property Type Description
$_modelOrder A copy of the model order to restore from
$_modelVirtualFields A copy of the model virtual fields to restore from
$_original array A copy of the object as it existed prior to the save. We're going to store this off, so we can calculate the deltas after save.
$_requestId string The requestId is a unique ID generated once per request to allow multiple record changes to be grouped by request

Public Methods

Method Description
afterDelete ( Model $Model ) : void Executed after a model is deleted.
afterSave ( Model $Model, boolean $created, array $options = [] ) : true Executed after a save operation completes.
beforeDelete ( Model $Model, boolean $cascade = true ) : true Executed before a delete operation.
beforeSave ( Model $Model, array $options = [] ) : true Executed before a save operation.
setup ( Model $Model, array $settings = [] ) : void Initiate behavior for the model using specified settings.

Protected Methods

Method Description
_getModelData ( Model $Model ) : array | false Get model data
_isAuditLogModel ( Model $Model ) : boolean Check if the given model is one of AuditLog ones
_requestId ( ) : null | string Get request ID
_restoreVirtualFields ( Model $Model ) : void Restore the virtual fields & order
_unsetVirtualFieldsTemporarily ( Model $Model ) : void Preserve and unset virtual fields and order as we don't need them and since they can cause SQL errors

Method Details

_getModelData() protected method

Retrieves the entire set model data contained to the primary object and any/all HABTM associated data that has been configured with the behavior. Additionally, for the HABTM data, all we care about is the IDs, so the data will be reduced to an indexed array of those IDs.
protected _getModelData ( Model $Model ) : array | false
$Model Model The model that uses the behavior.
return array | false The model data or false.

_isAuditLogModel() protected method

Check if the given model is one of AuditLog ones
protected _isAuditLogModel ( Model $Model ) : boolean
$Model Model The model to check
return boolean True if yes, else false.

_requestId() protected method

Get request ID
protected _requestId ( ) : null | string
return null | string The request ID.

_restoreVirtualFields() protected method

Restore the virtual fields & order
protected _restoreVirtualFields ( Model $Model ) : void
$Model Model The model to restore the virtual fields for.
return void

_unsetVirtualFieldsTemporarily() protected method

Preserve and unset virtual fields and order as we don't need them and since they can cause SQL errors
protected _unsetVirtualFieldsTemporarily ( Model $Model ) : void
$Model Model The model to unset the virtual fields from.
return void

afterDelete() public method

Executed after a model is deleted.
public afterDelete ( Model $Model ) : void
$Model Model The model that is used for the delete operation.
return void

afterSave() public method

Executed after a save operation completes.
public afterSave ( Model $Model, boolean $created, array $options = [] ) : true
$Model Model The model that is used for the save operation.
$created boolean True, if the save operation was an insertion, false otherwise.
$options array The options data (unused).
return true Always true.

beforeDelete() public method

Executed before a delete operation.
public beforeDelete ( Model $Model, boolean $cascade = true ) : true
$Model Model The model using the behavior.
$cascade boolean Whether to cascade (unused).
return true Always true.

beforeSave() public method

Executed before a save operation.
public beforeSave ( Model $Model, array $options = [] ) : true
$Model Model The model using the behavior.
$options array The options data (unused).
return true Always true.

setup() public method

Available settings: - ignore array, optional An array of property names to be ignored when records are created in the deltas table. - habtm array, optional An array of models that have a HABTM relationship with the acting model and whose changes should be monitored with the model.
public setup ( Model $Model, array $settings = [] ) : void
$Model Model The model using the behavior.
$settings array The settings overrides.
return void

Property Details

$_modelOrder protected_oe property

A copy of the model order to restore from
protected $_modelOrder

$_modelVirtualFields protected_oe property

A copy of the model virtual fields to restore from
protected $_modelVirtualFields

$_original protected_oe property

A copy of the object as it existed prior to the save. We're going to store this off, so we can calculate the deltas after save.
protected array $_original
return array

$_requestId protected_oe static_oe property

The requestId is a unique ID generated once per request to allow multiple record changes to be grouped by request
protected static string $_requestId
return string