Files
citrus/app/Models/CompanyHistoryItem.php
T

64 lines
1.4 KiB
PHP

<?php
namespace App\Models;
use App\Traits\HasTranslations;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class CompanyHistoryItem extends Model
{
use HasFactory, SoftDeletes, HasTranslations;
public const QUARTERS = ['Q1', 'Q2', 'Q3', 'Q4'];
protected $fillable = [
'year',
'quarter',
'title',
'content',
'color',
'icon',
'position',
'is_active',
'sort_order',
];
/**
* @var list<string>
*/
protected $translatable = [
'title',
'content',
];
protected $casts = [
'year' => 'integer',
'is_active' => 'boolean',
'sort_order' => 'integer',
];
public function scopeActive($query)
{
return $query->where('is_active', true);
}
public function scopeOrdered($query)
{
return $query
->orderBy('year', 'asc')
->orderByRaw("CASE quarter WHEN 'Q1' THEN 1 WHEN 'Q2' THEN 2 WHEN 'Q3' THEN 3 WHEN 'Q4' THEN 4 ELSE 5 END")
->orderBy('sort_order', 'asc');
}
public function getResolvedPositionAttribute(): string
{
if (in_array($this->position, ['left', 'right'], true)) {
return $this->position;
}
return ($this->sort_order % 2 === 1) ? 'right' : 'left';
}
}