mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-07-14 09:01:42 -04:00
85 lines
2.1 KiB
PHP
85 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Modules\StudioPlus\Entities;
|
|
|
|
use App\Models\Staff;
|
|
use App\Models\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Modules\StudioPlus\Traits\ScopeTrait;
|
|
|
|
class StudioPlusUser extends User
|
|
{
|
|
use ScopeTrait;
|
|
|
|
protected $table = 'users';
|
|
protected $appends = [
|
|
'full_name',
|
|
'total_videos_for_the_month',
|
|
'active',
|
|
];
|
|
|
|
public function staff()
|
|
{
|
|
return $this->belongsTo(Staff::class, 'id', 'user_id');
|
|
}
|
|
|
|
public function channel()
|
|
{
|
|
return $this->hasOne(StudioPlusChannel::class, 'user_id', 'id');
|
|
}
|
|
|
|
public function videos()
|
|
{
|
|
return $this->hasManyThrough(
|
|
StudioPlusVideo::class,
|
|
StudioPlusChannel::class,
|
|
'user_id',
|
|
'studio_plus_channel_id'
|
|
);
|
|
}
|
|
|
|
public function getFullNameAttribute()
|
|
{
|
|
return "{$this->first_name} {$this->last_name}";
|
|
}
|
|
|
|
public function downline()
|
|
{
|
|
return $this->hasMany(self::class, 'parent_id', 'id');
|
|
}
|
|
|
|
public function downlines()
|
|
{
|
|
return $this->hasMany(self::class, 'parent_id', 'id');
|
|
}
|
|
|
|
public function getIsVcOrVcmAttribute()
|
|
{
|
|
if (!permissionCheck('studio-plus.can_view_all_videos') && permissionCheck('downline') && permissionCheck('studio-plus.can_upload_video')) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function getTotalVideosForTheMonthAttribute()
|
|
{
|
|
$current_month = Carbon::now()->month;
|
|
$current_year = Carbon::now()->year;
|
|
|
|
$start_date = Carbon::create($current_year, $current_month, 1)->startOfDay();
|
|
$end_date = $start_date->copy()->endOfMonth();
|
|
|
|
return $this->videos()->whereBetween('studio_plus_videos.created_at', [$start_date, $end_date])->get()->count();
|
|
}
|
|
|
|
public function getActiveAttribute()
|
|
{
|
|
$min_date = Carbon::now()->subMonths(2);
|
|
$videos = $this->videos()->where('studio_plus_videos.created_at', '>', $min_date)->get();
|
|
|
|
return $videos->count() > 0;
|
|
}
|
|
}
|