openstamanager/src/Models/Hook.php

68 lines
1.2 KiB
PHP
Raw Normal View History

2019-05-10 06:32:06 +02:00
<?php
namespace Models;
use Common\Model;
2019-08-27 15:42:13 +02:00
use Hooks\Manager;
2019-05-24 21:07:10 +02:00
use Illuminate\Database\Eloquent\Builder;
2019-05-10 06:32:06 +02:00
use Traits\StoreTrait;
class Hook extends Model
{
use StoreTrait;
protected $table = 'zz_hooks';
2019-05-24 21:07:10 +02:00
protected $appends = [
'permission',
];
/**
* Restituisce i permessi relativi all'account in utilizzo.
*
* @return string
*/
public function getPermissionAttribute()
{
return $this->module->permission;
}
2019-05-10 06:32:06 +02:00
public function execute()
{
$class = $this->class;
$hook = new $class();
2019-08-27 15:42:13 +02:00
if (!$hook instanceof Manager) {
return [
'show' => false,
];
}
2019-05-10 06:32:06 +02:00
2019-08-27 15:42:13 +02:00
return $hook->manage();
2019-05-10 06:32:06 +02:00
}
2019-08-26 18:02:05 +02:00
public function prepare()
2019-07-05 09:53:53 +02:00
{
2019-08-26 18:02:05 +02:00
$class = $this->class;
$hook = new $class();
2019-05-10 06:32:06 +02:00
2019-08-27 15:42:13 +02:00
return $hook->prepare();
2019-05-10 06:32:06 +02:00
}
2019-05-24 21:07:10 +02:00
/* Relazioni Eloquent */
public function module()
{
return $this->belongsTo(Module::class, 'id_module');
}
protected static function boot()
{
parent::boot();
static::addGlobalScope('enabled', function (Builder $builder) {
$builder->where('enabled', true);
});
}
2019-05-10 06:32:06 +02:00
}