Miglioramento relazione con uploads

This commit is contained in:
Thomas Zilio 2018-11-30 19:40:06 +01:00
parent 9258fbc6b9
commit dd24baf32f
8 changed files with 123 additions and 47 deletions

View File

@ -4,13 +4,18 @@ namespace Modules\Anagrafiche;
use Common\Model;
use Modules\Fatture\Fattura;
use Traits\RecordTrait;
use Util\Generator;
use Settings;
class Anagrafica extends Model
{
use RecordTrait;
protected $table = 'an_anagrafiche';
protected $primaryKey = 'idanagrafica';
protected $module = 'Anagrafiche';
/**
* The attributes that aren't mass assignable.
*

View File

@ -4,12 +4,20 @@ namespace Modules\Fatture;
use Common\Model;
use Util\Generator;
use Traits\RecordTrait;
use Modules\Anagrafiche\Anagrafica;
class Fattura extends Model
{
use RecordTrait;
protected $table = 'co_documenti';
public function getModuleAttribute()
{
return $this->tipo->dir == 'entrata' ? 'Fatture di vendita':'Fatture di acquisto';
}
/**
* Crea una nuova fattura.
*
@ -89,7 +97,7 @@ class Fattura extends Model
* Imposta il sezionale relativo alla fattura e calcola il relativo numero.
* **Attenzione**: la data deve inserita prima!
*
* @param [type] $value
* @param int $value
*/
public function setIdSegmentAttribute($value)
{

View File

@ -3,7 +3,7 @@
namespace Models;
use Auth;
use Traits\RecordTrait;
use Traits\ManagerTrait;
use Traits\UploadTrait;
use Traits\StoreTrait;
use Common\Model;
@ -11,7 +11,7 @@ use Illuminate\Database\Eloquent\Builder;
class Module extends Model
{
use RecordTrait, UploadTrait, StoreTrait;
use ManagerTrait, UploadTrait, StoreTrait;
protected $table = 'zz_modules';
protected $main_folder = 'modules';

View File

@ -3,7 +3,7 @@
namespace Models;
use App;
use Traits\RecordTrait;
use Traits\ManagerTrait;
use Traits\UploadTrait;
use Traits\StoreTrait;
use Common\Model;
@ -11,7 +11,10 @@ use Illuminate\Database\Eloquent\Builder;
class Plugin extends Model
{
use RecordTrait, UploadTrait, StoreTrait;
use ManagerTrait, StoreTrait;
use UploadTrait {
getUploadDirectoryAttribute as protected defaultUploadDirectory;
}
protected $table = 'zz_plugins';
protected $main_folder = 'plugins';
@ -83,6 +86,20 @@ class Plugin extends Model
return $this->getAddFile();
}
/**
* Restituisce il percorso per il salvataggio degli upload.
*
* @return string
*/
public function getUploadDirectoryAttribute()
{
if (!empty($this->script)) {
return $this->uploads_directory.'/'.basename($this->script, ".php");
}
return $this->defaultUploadDirectory();
}
/* Relazioni Eloquent */
public function originalModule()

View File

@ -8,6 +8,13 @@ class Upload extends Model
{
protected $table = 'zz_files';
public function getCategoryAttribute()
{
return $this->attributes['category'] ?: 'Generale';
}
/* Relazioni Eloquent */
public function module()
{
return $this->belongsTo(Module::class, 'id_module');

View File

@ -0,0 +1,60 @@
<?php
namespace Traits;
trait ManagerTrait
{
use PathTrait;
/**
* Restituisce il percorso per il file di crezione dei record.
*
* @return string
*/
public function getAddFile()
{
if (method_exists($this, 'getCustomAddFile')) {
$result = $this->getCustomAddFile();
if (!empty($result)) {
return $result;
}
}
$php = $this->filepath('add.php');
$html = $this->filepath('add.html');
return !empty($php) ? $php : $html;
}
/**
* Controlla l'esistenza del file di crezione dei record.
*
* @return bool
*/
public function hasAddFile()
{
return !empty($this->getAddFile());
}
/**
* Restituisce il percorso per il file di modifica dei record.
*
* @return string
*/
public function getEditFile()
{
if (method_exists($this, 'getCustomEditFile')) {
$result = $this->getCustomEditFile();
if (!empty($result)) {
return $result;
}
}
$php = $this->filepath('edit.php');
$html = $this->filepath('edit.html');
return !empty($php) ? $php : $html;
}
}

View File

@ -2,59 +2,34 @@
namespace Traits;
use Models\Module;
use Models\Plugin;
trait RecordTrait
{
use PathTrait;
/**
* Restituisce il percorso per il file di crezione dei record.
*
* @return string
*/
public function getAddFile()
public function getModule()
{
if (method_exists($this, 'getCustomAddFile')) {
$result = $this->getCustomAddFile();
if (!empty($result)) {
return $result;
}
}
$php = $this->filepath('add.php');
$html = $this->filepath('add.html');
return !empty($php) ? $php : $html;
return !empty($this->module) ? Module::get($this->module) : null;
}
/**
* Controlla l'esistenza del file di crezione dei record.
*
* @return bool
*/
public function hasAddFile()
public function getPlugin()
{
return !empty($this->getAddFile());
return !empty($this->plugin) ? Plugin::get($this->plugin) : null;
}
/**
* Restituisce il percorso per il file di modifica dei record.
*
* @return string
*/
public function getEditFile()
public function uploads()
{
if (method_exists($this, 'getCustomEditFile')) {
$result = $this->getCustomEditFile();
$module = $this->getModule();
$plugin = $this->getPlugin();
if (!empty($result)) {
return $result;
}
if (!empty($module)) {
return $module->uploads($this->id);
}
$php = $this->filepath('edit.php');
$html = $this->filepath('edit.html');
if (!empty($plugin)) {
return $plugin->uploads($this->id);
}
return !empty($php) ? $php : $html;
return collect();
}
}

View File

@ -6,6 +6,8 @@ use Models\Upload;
trait UploadTrait
{
protected $uploads_directory = 'files';
/**
* Restituisce il percorso per il salvataggio degli upload.
*
@ -13,7 +15,9 @@ trait UploadTrait
*/
public function getUploadDirectoryAttribute()
{
return 'files/'.$this->directory;
$directory = $this->directory ?: 'common';
return $this->uploads_directory.'/'.$directory;
}
public function uploads($id_record)