PHP 클래스 SoftDeleteBehavior

Uso: deve existir uma coluna na tabela do modelo utilizado que indique se o registro está ativo ou não (valor binário do tipo boolean, integer, tinyint, etc). Por default o nome dessa coluna é 'active'. Se outro nome for utilizado, deve ser informado ao behavior através do atributo 'field' das configurações do behavior. A exclusão de registros é feita através do método softDelete(). Qualquer busca feita pelos registros que utilizem o behavior SoftDelete somente incluem os registros cujo campo active seja true (1) PHP version > 5.3.1 Licensed under The MIT License Redistributions of files must retain the above copyright notice.
상속: extends ModelBehavior
파일 보기 프로젝트 열기: baserproject/basercms

공개 프로퍼티들

프로퍼티 타입 설명
$default array Default settings
$runtime array Holds activity flags for models

공개 메소드들

메소드 설명
beforeDelete ( Model $model, boolean $cascade = true ) : boolean Before delete callback
beforeFind ( Model $model, array $query ) : array Before find callback
delete ( object $model, integer $id ) : boolean Mark record as deleted
existsAndNotDeleted ( Model $model, $id ) : mixed Check if a record exists for the given id
purgeDeleted ( object $model, mixed $expiration = '-90 days' ) : boolean Purge table
purgeDeletedCount ( object $model, mixed $expiration = '-90 days' ) : integer Returns number of outdated softdeleted records prepared for purge
setup ( Model $model, array $settings = [] ) Setup callback
softDelete ( object $model, mixed $active ) : mixed Enable/disable SoftDelete functionality
undelete ( object $model, integer $id ) : boolean Mark record as not deleted

보호된 메소드들

메소드 설명
_normalizeFields ( object $model, array $settings = [] ) : array Return normalized field array
_purgeDeletedConditions ( object $model, mixed $expiration = '-90 days' ) : array Returns conditions for finding outdated records
_softDeleteAssociations ( object $model, mixed $active ) Modifies conditions of hasOne and hasMany associations

메소드 상세

_normalizeFields() 보호된 메소드

Return normalized field array
protected _normalizeFields ( object $model, array $settings = [] ) : array
$model object
$settings array
리턴 array

_purgeDeletedConditions() 보호된 메소드

Returns conditions for finding outdated records
protected _purgeDeletedConditions ( object $model, mixed $expiration = '-90 days' ) : array
$model object
$expiration mixed anything parseable by strtotime(), by default '-90 days'
리턴 array

_softDeleteAssociations() 보호된 메소드

If multiple delete flags are configured for model, then $active=true doesn't do anything - you have to alter conditions in association definition
protected _softDeleteAssociations ( object $model, mixed $active )
$model object
$active mixed

beforeDelete() 공개 메소드

Before delete callback
public beforeDelete ( Model $model, boolean $cascade = true ) : boolean
$model Model
$cascade boolean
리턴 boolean

beforeFind() 공개 메소드

Before find callback
public beforeFind ( Model $model, array $query ) : array
$model Model
$query array
리턴 array

delete() 공개 메소드

Mark record as deleted
public delete ( object $model, integer $id ) : boolean
$model object
$id integer
리턴 boolean

existsAndNotDeleted() 공개 메소드

Check if a record exists for the given id
public existsAndNotDeleted ( Model $model, $id ) : mixed
$model Model
리턴 mixed

purgeDeleted() 공개 메소드

Purge table
public purgeDeleted ( object $model, mixed $expiration = '-90 days' ) : boolean
$model object
$expiration mixed anything parseable by strtotime(), by default '-90 days'
리턴 boolean if there were some outdated records

purgeDeletedCount() 공개 메소드

Returns number of outdated softdeleted records prepared for purge
public purgeDeletedCount ( object $model, mixed $expiration = '-90 days' ) : integer
$model object
$expiration mixed anything parseable by strtotime(), by default '-90 days'
리턴 integer

setup() 공개 메소드

Setup callback
public setup ( Model $model, array $settings = [] )
$model Model
$settings array

softDelete() 공개 메소드

Usage from model: $this->softDelete(false); deactivate this behavior for model $this->softDelete('field_two'); enabled only for this flag field $this->softDelete(true); enable again for all flag fields $config = $this->softDelete(null); for obtaining current setting
public softDelete ( object $model, mixed $active ) : mixed
$model object
$active mixed
리턴 mixed if $active is null, then current setting/null, or boolean if runtime setting for model was changed

undelete() 공개 메소드

Mark record as not deleted
public undelete ( object $model, integer $id ) : boolean
$model object
$id integer
리턴 boolean

프로퍼티 상세

$default 공개적으로 프로퍼티

Default settings
public array $default
리턴 array

$runtime 공개적으로 프로퍼티

Holds activity flags for models
public array $runtime
리턴 array