Files
wticreatorstudio/Modules/Frontend/Entities/Video.php
T

87 lines
2.0 KiB
PHP

<?php
namespace Modules\Frontend\Entities;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Config;
use Modules\StudioPlus\Entities\StudioPlusVideo;
class Video extends StudioPlusVideo
{
protected $table = 'studio_plus_videos';
protected $appends = [
'ott_title',
'ott_description',
'ott_links',
//'creator',
];
protected $channel_buffer = null;
protected $ott_data_buffer = null;
const LAZY_LOAD_ITEM_COUNT = 24;
public static function boot()
{
parent::boot();
static::addGlobalScope('in_ott', function (Builder $builder) {
$builder->where('in_ott', true);
});
}
public function ottData()
{
$locale = 'en';
if (session()->has('frontend_locale')) {
$locale = session()->get('frontend_locale');
}
return $this->hasOne(OTTData::class, 'studio_plus_video_id', 'id')->where('locale', $locale);
}
public function getOttTitleAttribute()
{
if (!empty($this->ottData)) {
return $this->ottData->title;
}
return $this->product_name;
}
public function getOttDescriptionAttribute()
{
if (!empty($this->ottData)) {
return $this->ottData->description;
}
return '';
}
public function getOttLinksAttribute()
{
if (!empty($this->ottData)) {
return $this->ottData->links;
}
return [];
}
public function getCreatorAttribute()
{
if ($this->channel) {
return Creator::find($this->channel->user_id);
}
}
public function getVideoUrlAttribute($value)
{
$bucketName = Config::get('studioplus.bucket_name');
$value = Str::remove('wticreatorhub/', $value);
return Config::get('studioplus.google_api_endpoint') . "/$bucketName/$value";
}
}