Hi all
I have a question ?. I assuming have two model implement method beforeDelete and beforeUpdate
class Job extends ModelBase
{
[...]
**
* Implements hook beforeDelete
*
* Check permission before deleted task
*
* @return bool
*/
public function beforeDelete()
{
// d($this->idUser);
if ($this->idUser != (int)$this->getDI()->getSession()->get('auth')['id']) {
$this->getDI()->getflashSession()->error(t('The object is not owner, it can\'t be deleted'));
return false;
}
return true;
}
/**
* Implements hook beforeUpdate
*
* Check permission before updated task
*
* @return bool
*/
public function beforeUpdate()
{
if ($this->idUser != (int)$this->getDI()->getSession()->get('auth')['id']) {
$this->getDI()->getflashSession()->error(t('The object is not owner, it can\'t be edit'));
return false;
}
return true;
}
Then model Task
class Task extends ModelBase
{
[...]
**
* Implements hook beforeDelete
*
* Check permission before deleted task
*
* @return bool
*/
public function beforeDelete()
{
// d($this->idUser);
if ($this->idUser != (int)$this->getDI()->getSession()->get('auth')['id']) {
$this->getDI()->getflashSession()->error(t('The object is not owner, it can\'t be deleted'));
return false;
}
return true;
}
/**
* Implements hook beforeUpdate
*
* Check permission before updated task
*
* @return bool
*/
public function beforeUpdate()
{
if ($this->idUser != (int)$this->getDI()->getSession()->get('auth')['id']) {
$this->getDI()->getflashSession()->error(t('The object is not owner, it can\'t be edit'));
return false;
}
return true;
}
In this case two model, but many model used code above . How to reusable code ?
Thanks all