mein-sterntours/packages/iqcontent/laravel-filemanager/src/Models/IQContentFile.php

130 lines
5.4 KiB
PHP

<?php
namespace IqContent\LaravelFilemanager\Models;
use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
/**
* IqContent\LaravelFilemanager\Models\IQContentFile
*
* @property int $id
* @property int|null $folder_id
* @property string $name
* @property string|null $identifier
* @property string $slug
* @property string|null $ext
* @property string|null $mine
* @property int $size
* @property string|null $dimensions
* @property string|null $content
* @property int $color
* @property int $pos
* @property int $active
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\IqContent\LaravelFilemanager\Models\IQContentFileTag[] $file_tags
* @property-read \IqContent\LaravelFilemanager\Models\IQContentFolder|null $folder
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile findSimilarSlugs($attribute, $config, $slug)
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile query()
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile whereColor($value)
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile whereContent($value)
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile whereDimensions($value)
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile whereExt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile whereFolderId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile whereIdentifier($value)
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile whereMine($value)
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile wherePos($value)
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile whereSize($value)
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile whereSlug($value)
* @method static \Illuminate\Database\Eloquent\Builder|\IqContent\LaravelFilemanager\Models\IQContentFile whereUpdatedAt($value)
* @mixin \Eloquent
*/
class IQContentFile extends Model
{
use Sluggable;
//use the connection to sec. Datebase sterntours
protected $connection = 'mysql_stern';
protected $table = 'i_q_content_files';
protected $fillable = [
'folder_id', 'name', 'identifier', 'ext', 'mine', 'size', 'dimensions', 'content', 'color', 'pos', 'active'
];
protected $casts = [
'content' => 'array',
];
public function folder() {
return $this->belongsTo('IqContent\LaravelFilemanager\Models\IQContentFolder', 'folder_id');
}
public function file_tags() {
return $this->hasMany('IqContent\LaravelFilemanager\Models\IQContentFileTag', 'file_id');
}
public function sluggable()
{
return [
'slug' => [
'source' => 'name'
]
];
}
public function setIdentifierAttribute( $value ) {
if(!isset($value) || $value == ""){
$this->attributes['identifier'] = Str::slug(pre_slug($this->name), '-');
}else{
$this->attributes['identifier'] = Str::slug(pre_slug($value), '-');
}
}
public function formatBytes($precision = 2)
{
$size = $this->size;
if ($size > 0) {
$size = (int) $size;
$base = log($size) / log(1024);
$suffixes = array(' KB', ' MB', ' GB', ' TB');
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
} else {
return $size;
}
}
public function hasTags()
{
if($this->file_tags()->count()){
return true;
}
return false;
}
/* public function hasThumb(){
if(\Storage::disk('local')->exists('thumb/'.$this->filename) || \Storage::disk('local')->exists('thumb/'.$this->filename.".jpg")){
return true;
}
return false;
}
public function hasBig(){
if(\Storage::disk('local')->exists('big/'.$this->filename) || \Storage::disk('local')->exists('big/'.$this->filename.".jpg")){
return true;
}
return false;
}*/
}