openstamanager/src/Models/Plugin.php

139 lines
3.4 KiB
PHP
Raw Normal View History

<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Models;
use App;
use Common\SimpleModelTrait;
2018-08-11 15:37:38 +02:00
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
2019-07-29 13:16:55 +02:00
use Modules\Checklists\Traits\ChecklistTrait;
2019-07-26 16:24:20 +02:00
use Traits\Components\NoteTrait;
use Traits\Components\UploadTrait;
use Traits\LocalPoolTrait;
2018-12-29 12:03:22 +01:00
use Traits\ManagerTrait;
class Plugin extends Model
{
use SimpleModelTrait;
2019-07-11 17:20:58 +02:00
use ManagerTrait;
use LocalPoolTrait;
2018-11-30 19:40:06 +01:00
use UploadTrait {
getUploadDirectoryAttribute as protected defaultUploadDirectory;
}
2019-07-26 11:57:59 +02:00
use NoteTrait;
2019-07-26 16:24:20 +02:00
use ChecklistTrait;
2018-08-11 15:37:38 +02:00
protected $table = 'zz_plugins';
2018-08-11 15:37:38 +02:00
protected $main_folder = 'plugins';
2019-07-26 16:24:20 +02:00
protected $component_identifier = 'id_plugin';
protected $appends = [
2018-08-11 15:37:38 +02:00
'permission',
'option',
];
protected $hidden = [
'options',
'options2',
];
2018-08-11 15:37:38 +02:00
/**
* Restituisce i permessi relativi all'account in utilizzo.
*
* @return string
*/
public function getPermissionAttribute()
{
2018-10-26 16:22:47 +02:00
return $this->originalModule->permission;
}
public function getOptionAttribute()
{
2018-09-27 15:50:03 +02:00
return !empty($this->options2) ? $this->options2 : $this->options;
2018-08-11 15:37:38 +02:00
}
/* Metodi personalizzati */
2018-08-13 10:01:15 +02:00
/**
* Restituisce l'eventuale percorso personalizzato per il file di creazione dei record.
*
* @return string
*/
2018-08-11 15:37:38 +02:00
public function getCustomAddFile()
{
if (empty($this->script)) {
return;
}
2018-10-26 16:22:47 +02:00
$directory = 'modules/'.$this->originalModule->directory.'|custom|/plugins';
2018-08-11 15:37:38 +02:00
return App::filepath($directory, $this->script);
}
2018-08-13 10:01:15 +02:00
/**
* Restituisce l'eventuale percorso personalizzato per il file di modifica dei record.
*
* @return string
*/
2018-08-11 15:37:38 +02:00
public function getCustomEditFile()
{
2018-09-06 10:23:54 +02:00
if (empty($this->script)) {
return;
}
2018-08-11 15:37:38 +02:00
return $this->getAddFile();
}
2018-11-30 19:40:06 +01:00
/**
* Restituisce il percorso per il salvataggio degli upload.
*
* @return string
*/
public function getUploadDirectoryAttribute()
{
if (!empty($this->script)) {
2018-12-23 14:01:59 +01:00
return $this->uploads_directory.'/'.basename($this->script, '.php');
2018-11-30 19:40:06 +01:00
}
return $this->defaultUploadDirectory();
}
/* Relazioni Eloquent */
public function originalModule()
{
2018-10-25 16:57:39 +02:00
return $this->belongsTo(Module::class, 'idmodule_from');
}
public function module()
{
2018-10-25 16:57:39 +02:00
return $this->belongsTo(Module::class, 'idmodule_to');
}
2018-12-29 12:03:22 +01:00
protected static function boot()
{
parent::boot();
static::addGlobalScope('enabled', function (Builder $builder) {
$builder->where('enabled', true);
});
}
}