You've already forked Atomcms-edit
51 lines
1.1 KiB
PHP
Executable File
51 lines
1.1 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class RadioContest extends Model
|
|
{
|
|
#[\Override]
|
|
protected $table = 'radio_contests';
|
|
|
|
#[\Override]
|
|
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'prize'];
|
|
|
|
/** @var array<string, string> */
|
|
#[\Override]
|
|
protected $casts = [
|
|
'starts_at' => 'datetime',
|
|
'ends_at' => 'datetime',
|
|
'is_active' => 'boolean',
|
|
'is_ended' => 'boolean',
|
|
'winners_announced' => 'boolean',
|
|
];
|
|
|
|
public function entries(): HasMany
|
|
{
|
|
return $this->hasMany(RadioContestEntry::class);
|
|
}
|
|
|
|
public function isActive(): bool
|
|
{
|
|
return $this->is_active &&
|
|
now()->gte($this->starts_at) &&
|
|
now()->lte($this->ends_at) &&
|
|
! $this->is_ended;
|
|
}
|
|
|
|
public function entryCount(): int
|
|
{
|
|
return $this->entries()->count();
|
|
}
|
|
|
|
public function uniqueParticipants(): int
|
|
{
|
|
return $this->entries()->distinct('user_id')->count('user_id');
|
|
}
|
|
}
|