You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
willaengine/app/SpFrame.php

97 lines
2.5 KiB

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\Appended\Classes\Specials\Assets\Traits\StaticData;
class SpFrame extends Model
{
use StaticData;
protected $fillable = ['name_en', 'name_fa', 'description', 'sp_template_id', 'user_id',
'sp_section_id', 'path', 'frame_info', 'action', 'sp_frame_type_id',
'resource', 'customizable', 'responsibility', 'detail_info', 'action_name_fa', 'is_global', 'section', 'type', 'sp_page_id','visibility_level'
];
public function template()
{
return $this->belongsTo('App\SpTemplate', 'sp_template_id');
}
public function user_pages()
{
return $this->belongsToMany('App\SpUserPage', 'sp_user_frames', 'sp_user_page_id', 'sp_frame_id');
}
public function page()
{
return $this->belongsTo('App\SpPage', 'sp_page_id');
}
public function orginalTitleImage()
{
return $this->morphToMany('App\Gallery', 'uploadable')->wherePivot('image_role', 'TitleImage')->where('parent_id', null);
}
public function title_image()
{
return $this->morphToMany('App\Gallery', 'uploadable')->wherePivot('image_role', 'TitleImage')->where('parent_id', null);
}
public function images()
{
return $this->morphToMany('App\Gallery', 'uploadable');
}
public function files()
{
return $this->morphToMany('App\Gallery', 'uploadable');
}
public function frame_type()
{
return $this->belongsTo('App\SpFrameType', 'sp_frame_type_id');
}
public function getThumbnailAttribute()
{
if ($this->title_image->isNotEmpty()) {
return $this->title_image[0]->path;
}
return 'WM-Main/Assets/NoPreview/preview.png';
}
public function getTypeAttribute()
{
return $this->frame_type->type;
}
public function scopeSection($query, $frameTypeId, $masterPageId)
{
return $query->where('sp_page_id', $masterPageId)->where('sp_frame_type_id', $frameTypeId);
}
public function getFrameInfoAttribute($value)
{
return json_decode($value, true);
}
public function setFrameInfoAttribute($value)
{
$this->attributes['frame_info'] = json_encode($value, JSON_UNESCAPED_UNICODE);
}
public function users()
{
return $this->belongsToMany('App\User', 'sp_frame_user')->withPivot('action')->withTimestamps();
}
public function user_frames()
{
return $this->hasMany('App\\SpUserFrame', 'sp_frame_id');
}
}