*/ public const VALID_STATUSES = [ self::STATUS_PENDING, self::STATUS_CONFIRMED, self::STATUS_CANCELLED ]; public const RECURRENCE_SINGLE = 'single'; public const RECURRENCE_WEEKLY = 'weekly'; /** * All valid recurrence values. * * @var list */ public const VALID_RECURRENCES = [ self::RECURRENCE_SINGLE, self::RECURRENCE_WEEKLY ]; public function __construct( public readonly int $slotId, public readonly int $studentId, public readonly int $instructorId, public readonly ?int $offeringId = null, public readonly string $recurrence = self::RECURRENCE_SINGLE, public readonly ?int $seriesId = null, public readonly string $status = self::STATUS_PENDING, public readonly ?int $paymentId = null, public readonly ?string $notes = null, /** * The staff member who booked this lesson on the student's behalf, from * wp-admin; 0 when it was booked through the student-facing flow, by the * student or their guardian. It is what marks a lesson whose intake answers * and policy acceptances may be recorded after the fact — nobody was at a * keyboard to give them at booking time. */ public readonly int $bookedBy = 0, public readonly ?int $id = null, ) {} public function intakeRegistrationType(): string { return Answer::REG_LESSON; } /** * The lesson id this booking's intake answers and policy acceptances hang * off: the series anchor for a weekly reservation, the lesson itself * otherwise. A series is answered for and agreed to once, so every occurrence * reads and writes the same registration. */ public function intakeRegistrationId(): int { return $this->seriesId ?? (int) $this->id; } public function intakeOfferingId(): int { return (int) $this->offeringId; } public function intakeStudentId(): int { return $this->studentId; } /** * Whether the studio booked this lesson on the student's behalf, rather than * the student (or their guardian) booking it themselves. */ public function isStaffRegistered(): bool { return $this->bookedBy > 0; } public static function fromRow( \stdClass $row ): self { return new self( slotId: Val::int( $row->slot_id ), studentId: Val::int( $row->student_id ), instructorId: Val::int( $row->instructor_id ), offeringId: Val::intOrNull( $row->offering_id ), recurrence: Val::string( $row->recurrence ), seriesId: Val::intOrNull( $row->series_id ), status: Val::string( $row->status ), paymentId: Val::intOrNull( $row->payment_id ), notes: Val::stringOrNull( $row->notes ), bookedBy: Val::int( $row->booked_by ?? 0 ), id: Val::int( $row->id ), ); } /** * Returns a plain array representation of the lesson. * * @return array */ public function toArray(): array { return [ 'id' => $this->id, 'slot_id' => $this->slotId, 'offering_id' => $this->offeringId, 'student_id' => $this->studentId, 'instructor_id' => $this->instructorId, 'recurrence' => $this->recurrence, 'series_id' => $this->seriesId, 'status' => $this->status, 'payment_id' => $this->paymentId, 'notes' => $this->notes, 'booked_by' => $this->bookedBy, ]; } }