mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-27 00:37:38 +01:00
Miglioramento relazione con uploads
This commit is contained in:
parent
9258fbc6b9
commit
dd24baf32f
@ -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.
|
||||
*
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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';
|
||||
|
@ -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()
|
||||
|
@ -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');
|
||||
|
60
src/Traits/ManagerTrait.php
Normal file
60
src/Traits/ManagerTrait.php
Normal 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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user