08 2024
This commit is contained in:
parent
04d677d37a
commit
bfa3bb1df4
1191 changed files with 637397 additions and 10619 deletions
190
app/Models/DcFile.php
Normal file
190
app/Models/DcFile.php
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class DcFile
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $filename
|
||||
* @property string $original_name
|
||||
* @property string $ext
|
||||
* @property string $mine
|
||||
* @property int|null $size
|
||||
* @property int|null $active
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @property Collection|DcFileTag[] $dc_file_tags
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class DcFile extends Model
|
||||
{
|
||||
protected $table = 'dc_files';
|
||||
|
||||
protected $casts = [
|
||||
'size' => 'int',
|
||||
'active' => 'int'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'filename',
|
||||
'original_name',
|
||||
'ext',
|
||||
'mine',
|
||||
'size',
|
||||
'active'
|
||||
];
|
||||
|
||||
public function dc_file_tags()
|
||||
{
|
||||
return $this->hasMany(DcFileTag::class, 'file_id');
|
||||
}
|
||||
|
||||
public function tags(){
|
||||
return $this->belongsToMany(DcTag::class, 'dc_file_tags', 'file_id', 'tag_id');
|
||||
}
|
||||
|
||||
public function fileTag(){
|
||||
return $this->hasMany(DcFileTag::class, 'file_id');
|
||||
}
|
||||
|
||||
public function hasTags()
|
||||
{
|
||||
if($this->fileTag()->count()){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//path /storage/app/dc/ ...
|
||||
/*public function isImage(){
|
||||
if(empty($this->attributes['filename']) || @$this->attributes['filename'] == null || @$this->attributes['filename'] == ""){
|
||||
return false;
|
||||
}
|
||||
if(!\Storage::disk('public')->has('images/shop/'.$this->filename)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getImage(){
|
||||
if($this->isImage()){
|
||||
$link = 'images/shop/'.$this->filename;
|
||||
return '/storage/'.$link.'?=lm='.\Storage::disk('public')->lastModified($link);
|
||||
}
|
||||
return false;
|
||||
}*/
|
||||
|
||||
public function hasThumb(){
|
||||
if(\Storage::disk('public')->exists('dc/thumb/'.$this->filename) || \Storage::disk('public')->exists('dc/thumb/'.$this->filename.".jpg")){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function hasBig(){
|
||||
if(\Storage::disk('public')->exists('dc/big/'.$this->filename) || \Storage::disk('public')->exists('dc/big/'.$this->filename.".jpg")){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function hasFile(){
|
||||
if(\Storage::disk('public')->exists('dc/files/'.$this->filename) || \Storage::disk('public')->exists('dc/files/'.$this->filename.".jpg")){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getThumb($full = false){
|
||||
$link = 'dc/thumb/'.$this->filename;
|
||||
if(\Storage::disk('public')->exists($link)){
|
||||
return $full ? \Storage::disk('public')->path($link) : $link;
|
||||
}
|
||||
$link.=".jpg";
|
||||
if(\Storage::disk('public')->exists($link)){
|
||||
return $full ? \Storage::disk('public')->path($link) : $link;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getBig($full = false){
|
||||
$link = 'dc/big/'.$this->filename;
|
||||
if(\Storage::disk('public')->exists($link)){
|
||||
return $full ? \Storage::disk('public')->path($link) : $link;
|
||||
}
|
||||
$link.=".jpg";
|
||||
if(\Storage::disk('public')->exists($link)){
|
||||
return $full ? \Storage::disk('public')->path($link) : $link;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function getFile($full = false){
|
||||
$link = 'dc/files/'.$this->filename;
|
||||
if(\Storage::disk('public')->exists($link)){
|
||||
return $full ? \Storage::disk('public')->path($link) : $link;
|
||||
}
|
||||
$link.=".jpg";
|
||||
if(\Storage::disk('public')->exists($link)){
|
||||
return $full ? \Storage::disk('public')->path($link) : $link;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getLastModified($type = 'thumb'){
|
||||
if($type == 'thumb'){
|
||||
$link = $this->getThumb();
|
||||
}
|
||||
if($type == 'big'){
|
||||
$link = $this->getBig();
|
||||
}
|
||||
if($type == 'file'){
|
||||
$link = $this->getFile();
|
||||
}
|
||||
return \Storage::disk('public')->lastModified($link);
|
||||
}
|
||||
|
||||
|
||||
public function getTags(){
|
||||
$tags = $this->tags;
|
||||
$tagArray = [];
|
||||
foreach($tags as $tag){
|
||||
$tagArray[] = $tag->name;
|
||||
}
|
||||
return implode(', ', $tagArray);
|
||||
}
|
||||
public function thumb(){
|
||||
$ext = $this->ext;
|
||||
$ext = strtolower($ext);
|
||||
if($ext == 'pdf'){
|
||||
return 'pdf.png';
|
||||
}
|
||||
if($ext == 'doc' || $ext == 'docx'){
|
||||
return 'doc.png';
|
||||
}
|
||||
if($ext == 'xls' || $ext == 'xlsx'){
|
||||
return 'xls.png';
|
||||
}
|
||||
if($ext == 'ppt' || $ext == 'pptx'){
|
||||
return 'ppt.png';
|
||||
}
|
||||
if($ext == 'zip' || $ext == 'rar'){
|
||||
return 'zip.png';
|
||||
}
|
||||
if($ext == 'jpg' || $ext == 'jpeg' || $ext == 'png' || $ext == 'gif'){
|
||||
return $this->filename;
|
||||
}
|
||||
return 'file.png';
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue