- Schedule 모델 생성 (schedules 테이블, type별 색상 상수) - DashboardCalendarController 생성 (CRUD + 달력 partial) - 대시보드 뷰에 월간 달력 섹션 추가 (HTMX + Vanilla JS) - 일정 생성/수정/삭제 모달 구현 - 공휴일 빨간색 표시, 일정 유형별 색상 뱃지 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
102 lines
2.9 KiB
PHP
102 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models\System;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Schedule extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'schedules';
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'title',
|
|
'description',
|
|
'start_date',
|
|
'end_date',
|
|
'start_time',
|
|
'end_time',
|
|
'is_all_day',
|
|
'type',
|
|
'is_recurring',
|
|
'recurrence_rule',
|
|
'color',
|
|
'is_active',
|
|
'created_by',
|
|
'updated_by',
|
|
'deleted_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'start_date' => 'date',
|
|
'end_date' => 'date',
|
|
'is_all_day' => 'boolean',
|
|
'is_recurring' => 'boolean',
|
|
'is_active' => 'boolean',
|
|
];
|
|
|
|
protected $attributes = [
|
|
'is_all_day' => true,
|
|
'type' => 'event',
|
|
'is_recurring' => false,
|
|
'is_active' => true,
|
|
];
|
|
|
|
public const TYPE_EVENT = 'event';
|
|
public const TYPE_MEETING = 'meeting';
|
|
public const TYPE_NOTICE = 'notice';
|
|
public const TYPE_OTHER = 'other';
|
|
|
|
public const TYPES = [
|
|
self::TYPE_EVENT => '일정',
|
|
self::TYPE_MEETING => '회의',
|
|
self::TYPE_NOTICE => '공지',
|
|
self::TYPE_OTHER => '기타',
|
|
];
|
|
|
|
public const TYPE_COLORS = [
|
|
self::TYPE_EVENT => ['bg' => 'bg-emerald-50', 'text' => 'text-emerald-700', 'border' => 'border-emerald-200'],
|
|
self::TYPE_MEETING => ['bg' => 'bg-blue-50', 'text' => 'text-blue-700', 'border' => 'border-blue-200'],
|
|
self::TYPE_NOTICE => ['bg' => 'bg-amber-50', 'text' => 'text-amber-700', 'border' => 'border-amber-200'],
|
|
self::TYPE_OTHER => ['bg' => 'bg-gray-50', 'text' => 'text-gray-700', 'border' => 'border-gray-200'],
|
|
];
|
|
|
|
public function scopeForTenant(Builder $query, int $tenantId): Builder
|
|
{
|
|
return $query->where(function ($q) use ($tenantId) {
|
|
$q->where('tenant_id', $tenantId)
|
|
->orWhereNull('tenant_id');
|
|
});
|
|
}
|
|
|
|
public function scopeActive(Builder $query): Builder
|
|
{
|
|
return $query->where('is_active', true);
|
|
}
|
|
|
|
public function scopeBetweenDates(Builder $query, string $startDate, string $endDate): Builder
|
|
{
|
|
return $query->where(function ($q) use ($startDate, $endDate) {
|
|
$q->where('start_date', '<=', $endDate)
|
|
->where(function ($inner) use ($startDate) {
|
|
$inner->where('end_date', '>=', $startDate)
|
|
->orWhereNull('end_date');
|
|
});
|
|
});
|
|
}
|
|
|
|
public function getTypeLabelAttribute(): string
|
|
{
|
|
return self::TYPES[$this->type] ?? $this->type;
|
|
}
|
|
|
|
public function getTypeColorsAttribute(): array
|
|
{
|
|
return self::TYPE_COLORS[$this->type] ?? self::TYPE_COLORS[self::TYPE_OTHER];
|
|
}
|
|
}
|