chore: initial Laravel 13 project setup for eCert MBIP
- Laravel 13.9 + PHP 8.5 + MySQL - Bootstrap 5.3 + jQuery 3.7 + Chart.js (replacing Alpine/Tailwind) - Packages: intervention/image, dompdf, simple-qrcode, league/csv, laravel/breeze, laravel/boost - 17 database migrations: users, programs, qr_codes, participants, attendances, certificates, questionnaires, email_logs, audit_logs - 13 Eloquent models with full relationships - Admin layout (Bootstrap 5 sidebar) + public layout (mobile-first) - Rate limiters: checkin (60/min), certificate (30/min) - Admin seeder: admin@mbip.gov.my - Storage directories + symlink configured Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
122
app/Models/Program.php
Normal file
122
app/Models/Program.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Program extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'uuid', 'title', 'description', 'organizer', 'location',
|
||||
'start_date', 'end_date',
|
||||
'checkin_start_at', 'checkin_end_at',
|
||||
'ecert_download_start_at', 'ecert_download_end_at',
|
||||
'status', 'allow_walk_in',
|
||||
'default_staff_session', 'default_external_session',
|
||||
'created_by',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'start_date' => 'date',
|
||||
'end_date' => 'date',
|
||||
'checkin_start_at' => 'datetime',
|
||||
'checkin_end_at' => 'datetime',
|
||||
'ecert_download_start_at' => 'datetime',
|
||||
'ecert_download_end_at' => 'datetime',
|
||||
'allow_walk_in' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
protected static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
static::creating(fn($model) => $model->uuid ??= (string) Str::uuid());
|
||||
}
|
||||
|
||||
public function getRouteKeyName(): string
|
||||
{
|
||||
return 'uuid';
|
||||
}
|
||||
|
||||
public function creator()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
public function qrCode()
|
||||
{
|
||||
return $this->hasOne(ProgramQrCode::class)->where('is_active', true)->latestOfMany();
|
||||
}
|
||||
|
||||
public function qrCodes()
|
||||
{
|
||||
return $this->hasMany(ProgramQrCode::class);
|
||||
}
|
||||
|
||||
public function participants()
|
||||
{
|
||||
return $this->belongsToMany(Participant::class, 'program_participants')
|
||||
->withPivot(['registration_source', 'is_pre_registered', 'pre_registered_session', 'status', 'registered_at'])
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function programParticipants()
|
||||
{
|
||||
return $this->hasMany(ProgramParticipant::class);
|
||||
}
|
||||
|
||||
public function attendances()
|
||||
{
|
||||
return $this->hasMany(Attendance::class);
|
||||
}
|
||||
|
||||
public function certificateTemplate()
|
||||
{
|
||||
return $this->hasOne(CertificateTemplate::class)->where('is_active', true)->latestOfMany();
|
||||
}
|
||||
|
||||
public function certificateTemplates()
|
||||
{
|
||||
return $this->hasMany(CertificateTemplate::class);
|
||||
}
|
||||
|
||||
public function certificates()
|
||||
{
|
||||
return $this->hasMany(Certificate::class);
|
||||
}
|
||||
|
||||
public function questionnaire()
|
||||
{
|
||||
return $this->hasOne(ProgramQuestionnaire::class);
|
||||
}
|
||||
|
||||
public function questionnaireSets()
|
||||
{
|
||||
return $this->belongsToMany(QuestionnaireSet::class, 'program_questionnaires')
|
||||
->withPivot(['is_confirmed', 'confirmed_at', 'confirmed_by'])
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function isCheckinOpen(): bool
|
||||
{
|
||||
$now = now();
|
||||
return $this->status === 'published'
|
||||
&& $this->checkin_start_at
|
||||
&& $now->between($this->checkin_start_at, $this->checkin_end_at ?? $now->addYear());
|
||||
}
|
||||
|
||||
public function isDownloadOpen(): bool
|
||||
{
|
||||
$now = now();
|
||||
return $this->status === 'published'
|
||||
&& $this->ecert_download_start_at
|
||||
&& $now->gte($this->ecert_download_start_at)
|
||||
&& (! $this->ecert_download_end_at || $now->lte($this->ecert_download_end_at));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user