2018-11-30 15:45:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Models;
|
|
|
|
|
|
|
|
use Common\Model;
|
|
|
|
|
|
|
|
class Upload extends Model
|
|
|
|
{
|
|
|
|
protected $table = 'zz_files';
|
|
|
|
|
2018-11-30 19:40:06 +01:00
|
|
|
public function getCategoryAttribute()
|
|
|
|
{
|
|
|
|
return $this->attributes['category'] ?: 'Generale';
|
|
|
|
}
|
|
|
|
|
2019-01-17 16:11:10 +01:00
|
|
|
/**
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function getExtensionAttribute()
|
|
|
|
{
|
|
|
|
$pos = strrpos($this->filename, '.');
|
|
|
|
|
|
|
|
if (!$pos) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$extension = substr($this->filename, $pos + 1);
|
|
|
|
|
|
|
|
return strtolower($extension);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFilepathAttribute()
|
|
|
|
{
|
|
|
|
$parent = $this->plugin ?: $this->module;
|
|
|
|
|
|
|
|
return $parent->upload_directory.'/'.$this->filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isImage()
|
|
|
|
{
|
|
|
|
$list = ['jpg', 'png', 'gif', 'jpeg', 'bmp'];
|
|
|
|
|
|
|
|
return in_array($this->extension, $list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isFatturaElettronica()
|
|
|
|
{
|
|
|
|
return $this->extension == 'xml' && strtolower($this->category) == 'fattura elettronica';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isPDF()
|
|
|
|
{
|
|
|
|
return $this->extension == 'pdf';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasPreview()
|
|
|
|
{
|
|
|
|
return $this->isImage() || $this->isFatturaElettronica() || $this->isPDF();
|
|
|
|
}
|
|
|
|
|
2018-11-30 19:40:06 +01:00
|
|
|
/* Relazioni Eloquent */
|
|
|
|
|
2018-11-30 15:45:43 +01:00
|
|
|
public function module()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Module::class, 'id_module');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function plugin()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Plugin::class, 'id_plugin');
|
|
|
|
}
|
|
|
|
}
|