- added persistent system information, #184
- fixed some PHPDoc comments - fixed bug where system "status" change fails to update
This commit is contained in:
@@ -48,6 +48,14 @@ abstract class BasicModel extends \DB\Cortex {
|
||||
*/
|
||||
protected $validate = [];
|
||||
|
||||
/**
|
||||
* enables change for "active" column
|
||||
* -> see setActive();
|
||||
* -> $this->active = false; will NOT work (prevent abuse)!
|
||||
* @var bool
|
||||
*/
|
||||
protected $allowActiveChange = false;
|
||||
|
||||
/**
|
||||
* getData() cache key prefix
|
||||
* -> do not change, otherwise cached data is lost
|
||||
@@ -76,23 +84,30 @@ abstract class BasicModel extends \DB\Cortex {
|
||||
|
||||
parent::__construct($db, $table, $fluid, $ttl);
|
||||
|
||||
// events -----------------------------------------
|
||||
// insert events ------------------------------------------------------------------------------------
|
||||
$this->beforeinsert( function($self, $pkeys){
|
||||
return $self->beforeInsertEvent($self, $pkeys);
|
||||
});
|
||||
|
||||
$this->afterinsert(function($self, $pkeys){
|
||||
$self->afterInsertEvent($self, $pkeys);
|
||||
$self->clearCacheData();
|
||||
});
|
||||
|
||||
// update events ------------------------------------------------------------------------------------
|
||||
$this->beforeupdate( function($self, $pkeys){
|
||||
return $self->beforeUpdateEvent($self, $pkeys);
|
||||
});
|
||||
|
||||
$this->afterupdate( function($self, $pkeys){
|
||||
$self->afterUpdateEvent($self, $pkeys);
|
||||
$self->clearCacheData();
|
||||
});
|
||||
|
||||
$this->beforeinsert( function($self, $pkeys){
|
||||
$self->beforeInsertEvent($self, $pkeys);
|
||||
});
|
||||
// erase events -------------------------------------------------------------------------------------
|
||||
|
||||
$this->beforeerase( function($self, $pkeys){
|
||||
$self->beforeEraseEvent($self, $pkeys);
|
||||
return $self->beforeEraseEvent($self, $pkeys);
|
||||
});
|
||||
|
||||
$this->aftererase( function($self, $pkeys){
|
||||
@@ -100,7 +115,6 @@ abstract class BasicModel extends \DB\Cortex {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $val
|
||||
@@ -109,11 +123,6 @@ abstract class BasicModel extends \DB\Cortex {
|
||||
*/
|
||||
public function set($key, $val){
|
||||
|
||||
if($key == 'active'){
|
||||
// prevent abuse
|
||||
return;
|
||||
}
|
||||
|
||||
if(
|
||||
!$this->dry() &&
|
||||
$key != 'updated'
|
||||
@@ -152,6 +161,24 @@ abstract class BasicModel extends \DB\Cortex {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* setter for "active" status
|
||||
* -> default: keep current "active" status
|
||||
* -> can be overwritten
|
||||
* @param bool $active
|
||||
* @return mixed
|
||||
*/
|
||||
public function set_active($active){
|
||||
if( $this->allowActiveChange ){
|
||||
// allowed to set/change -> reset "allowed" property
|
||||
$this->allowActiveChange = false;
|
||||
}else{
|
||||
// not allowed to set/change -> keep current status
|
||||
$active = $this->active;
|
||||
}
|
||||
return $active;
|
||||
}
|
||||
|
||||
/**
|
||||
* extent the fieldConf Array with static fields for each table
|
||||
*/
|
||||
@@ -371,10 +398,14 @@ abstract class BasicModel extends \DB\Cortex {
|
||||
|
||||
/**
|
||||
* set active state for a model
|
||||
* @param $value
|
||||
* -> do NOT use $this->active for status change!
|
||||
* -> this will not work (prevent abuse)
|
||||
* @param bool $active
|
||||
*/
|
||||
public function setActive($value){
|
||||
$this->set('active', (int)$value);
|
||||
public function setActive($active){
|
||||
// enables "active" change for this model
|
||||
$this->allowActiveChange = true;
|
||||
$this->active = $active;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -430,6 +461,18 @@ abstract class BasicModel extends \DB\Cortex {
|
||||
public function afterInsertEvent($self, $pkeys){
|
||||
}
|
||||
|
||||
/**
|
||||
* Event "Hook" function
|
||||
* can be overwritten
|
||||
* return false will stop any further action
|
||||
* @param self $self
|
||||
* @param $pkeys
|
||||
* @return bool
|
||||
*/
|
||||
public function beforeUpdateEvent($self, $pkeys){
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event "Hook" function
|
||||
* can be overwritten
|
||||
|
||||
Reference in New Issue
Block a user