@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\SchoolYear;
|
||||
|
||||
final class SchoolYearContext
|
||||
{
|
||||
public function __construct(
|
||||
private readonly int $id,
|
||||
private readonly string $yearName,
|
||||
private readonly string $status,
|
||||
private readonly bool $explicitSelection = false,
|
||||
) {
|
||||
}
|
||||
|
||||
public function id(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function yearName(): string
|
||||
{
|
||||
return $this->yearName;
|
||||
}
|
||||
|
||||
public function status(): string
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->status === 'active';
|
||||
}
|
||||
|
||||
public function isReadonly(): bool
|
||||
{
|
||||
return in_array($this->status, ['closed', 'archived'], true);
|
||||
}
|
||||
|
||||
public function isExplicitSelection(): bool
|
||||
{
|
||||
return $this->explicitSelection;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->yearName,
|
||||
'status' => $this->status,
|
||||
'readonly' => $this->isReadonly(),
|
||||
'explicitSelection' => $this->explicitSelection,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\SchoolYear;
|
||||
|
||||
final class SchoolYearStatus
|
||||
{
|
||||
public const DRAFT = 'draft';
|
||||
public const ACTIVE = 'active';
|
||||
public const CLOSING = 'closing';
|
||||
public const CLOSED = 'closed';
|
||||
public const ARCHIVED = 'archived';
|
||||
|
||||
public const ALL = [
|
||||
self::DRAFT,
|
||||
self::ACTIVE,
|
||||
self::CLOSING,
|
||||
self::CLOSED,
|
||||
self::ARCHIVED,
|
||||
];
|
||||
|
||||
public const TRANSITIONS = [
|
||||
self::DRAFT => [self::ACTIVE],
|
||||
self::ACTIVE => [self::CLOSING],
|
||||
self::CLOSING => [self::ACTIVE, self::CLOSED],
|
||||
self::CLOSED => [self::ACTIVE, self::ARCHIVED],
|
||||
self::ARCHIVED => [],
|
||||
];
|
||||
|
||||
public static function canTransition(string $from, string $to): bool
|
||||
{
|
||||
return in_array($to, self::TRANSITIONS[$from] ?? [], true);
|
||||
}
|
||||
|
||||
public static function isReadonly(string $status): bool
|
||||
{
|
||||
return in_array($status, [self::CLOSED, self::ARCHIVED], true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\SchoolYear;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
final class SchoolYearTableRegistry
|
||||
{
|
||||
public const YEAR_SCOPED = [
|
||||
'additional_charges',
|
||||
'archived_paypal_transactions',
|
||||
'attendance_data',
|
||||
'attendance_day',
|
||||
'attendance_record',
|
||||
'attendance_tracking',
|
||||
'badge_print_logs',
|
||||
'below_sixty_decisions',
|
||||
'calendar_events',
|
||||
'certificate_records',
|
||||
'classSection',
|
||||
'class_progress_reports',
|
||||
'competitions',
|
||||
'current_flag',
|
||||
'discount_vouchers',
|
||||
'early_dismissal_signatures',
|
||||
'enrollments',
|
||||
'events',
|
||||
'exams',
|
||||
'exam_drafts',
|
||||
'expenses',
|
||||
'final_exam',
|
||||
'final_score',
|
||||
'flag',
|
||||
'grading_locks',
|
||||
'homework',
|
||||
'inventory_movements',
|
||||
'invoices',
|
||||
'late_slip_logs',
|
||||
'manual_payments',
|
||||
'midterm_exam',
|
||||
'missing_score_overrides',
|
||||
'parent_attendance_reports',
|
||||
'parent_meeting_schedules',
|
||||
'parent_notifications',
|
||||
'participation',
|
||||
'payments',
|
||||
'payment_transactions',
|
||||
'placement_batches',
|
||||
'print_requests',
|
||||
'project',
|
||||
'quiz',
|
||||
'refunds',
|
||||
'reimbursements',
|
||||
'reimbursement_batches',
|
||||
'report_card_acknowledgements',
|
||||
'scan_log',
|
||||
'score_comments',
|
||||
'semester_scores',
|
||||
'staff_attendance',
|
||||
'student_class',
|
||||
'student_decisions',
|
||||
'teacher_attendance_data',
|
||||
'teacher_class',
|
||||
'teacher_submission_notification_history',
|
||||
'whatsapp_group_links',
|
||||
'whatsapp_group_memberships',
|
||||
];
|
||||
|
||||
public const GLOBAL = [
|
||||
'authorized_users',
|
||||
'cache',
|
||||
'cache_locks',
|
||||
'configuration',
|
||||
'email_templates',
|
||||
'ip_attempts',
|
||||
'login_activity',
|
||||
'migrations',
|
||||
'nav_items',
|
||||
'parent_accounts',
|
||||
'password_reset_requests',
|
||||
'password_resets',
|
||||
'permissions',
|
||||
'personal_access_tokens',
|
||||
'preferences',
|
||||
'role_nav_items',
|
||||
'role_permissions',
|
||||
'roles',
|
||||
'school_years',
|
||||
'sessions',
|
||||
'settings',
|
||||
'user_preferences',
|
||||
'user_roles',
|
||||
'users',
|
||||
];
|
||||
|
||||
public const IDENTITY_WITH_YEAR_RELATION = [
|
||||
'emergency_contacts',
|
||||
'families',
|
||||
'family_guardians',
|
||||
'family_students',
|
||||
'parents',
|
||||
'staff',
|
||||
'student_allergies',
|
||||
'student_medical_conditions',
|
||||
'students',
|
||||
'teachers',
|
||||
];
|
||||
|
||||
public const CONTEXT = [
|
||||
'audit_logs',
|
||||
'communication_logs',
|
||||
'contactus',
|
||||
'finance_notification_logs',
|
||||
'messages',
|
||||
'notification_recipients',
|
||||
'notifications',
|
||||
'payment_notification_logs',
|
||||
'support_requests',
|
||||
'user_notifications',
|
||||
];
|
||||
|
||||
public static function isYearScoped(string $table): bool
|
||||
{
|
||||
return in_array($table, self::YEAR_SCOPED, true);
|
||||
}
|
||||
|
||||
public static function isGlobal(string $table): bool
|
||||
{
|
||||
return in_array($table, self::GLOBAL, true);
|
||||
}
|
||||
|
||||
public static function isIdentityWithYearRelation(string $table): bool
|
||||
{
|
||||
return in_array($table, self::IDENTITY_WITH_YEAR_RELATION, true);
|
||||
}
|
||||
|
||||
public static function isContext(string $table): bool
|
||||
{
|
||||
return in_array($table, self::CONTEXT, true);
|
||||
}
|
||||
|
||||
public static function categoryOf(string $table): string
|
||||
{
|
||||
return match (true) {
|
||||
self::isYearScoped($table) => 'YEAR_SCOPED',
|
||||
self::isGlobal($table) => 'GLOBAL',
|
||||
self::isIdentityWithYearRelation($table) => 'IDENTITY_WITH_YEAR_RELATION',
|
||||
self::isContext($table) => 'CONTEXT',
|
||||
default => throw new InvalidArgumentException(
|
||||
"Table '{$table}' is not registered for school-year behavior."
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user