$id > 0 ) ) : array(); return new self( (int) $row['id'], InvitationKind::tryFrom( (int) $row['kind'] ) ?? InvitationKind::RSVP, (int) $row['course_id'], (int) $row['unit_id'], (int) $row['occurrence_id'], (int) $row['template_id'], (int) ( $row['announcement_id'] ?? 0 ), max( 1, (int) $row['version'] ), $ids, (int) $row['rsvp'], (string) ( $row['rsvp_until'] ?? '' ), YesAction::tryFrom( (int) $row['yes_action'] ) ?? YesAction::NONE, (int) $row['places'], InvitationState::tryFrom( (int) $row['state'] ) ?? InvitationState::DRAFT, (string) ( $row['scheduled_at'] ?? '' ), (string) ( $row['sent_at'] ?? '' ), (string) ( $row['subject'] ?? '' ), (string) ( $row['body'] ?? '' ), (string) ( $row['lang'] ?? '' ), (int) $row['created_by'], (string) $row['created_at'], (int) ( $row['target_cohort_id'] ?? 0 ) ); } public function is_cohort_only(): bool { return $this->course_id <= 0 && $this->target_cohort_id > 0; } public function asks(): bool { return InvitationKind::RSVP === $this->kind && array() !== RsvpAnswer::offered( $this->rsvp ); } public function is_cancelled(): bool { return InvitationState::CANCELLED === $this->state; } public function to_array(): array { return array( 'id' => $this->id, 'kind' => match ( $this->kind ) { InvitationKind::RSVP => 'rsvp', InvitationKind::INTEREST => 'interest', default => 'announcement', }, 'course_id' => $this->course_id, 'unit_id' => $this->unit_id, 'occurrence_id' => $this->occurrence_id, 'template_id' => $this->template_id, 'announcement_id' => $this->announcement_id, 'version' => $this->version, 'attachment_ids' => $this->attachment_ids, 'rsvp' => array_map( static fn( RsvpAnswer $a ): string => $a->slug(), RsvpAnswer::offered( $this->rsvp ) ), 'rsvp_until' => $this->rsvp_until, 'yes_action' => match ( $this->yes_action ) { YesAction::REGISTER => 'register', YesAction::ENROL => 'enrol', YesAction::JOIN_COHORT => 'join_cohort', default => 'none', }, 'target_cohort_id' => $this->target_cohort_id, 'places' => $this->places, 'state' => $this->state->slug(), 'scheduled_at' => $this->scheduled_at, 'sent_at' => $this->sent_at, 'subject' => $this->subject, 'body' => $this->body, 'created_by' => $this->created_by, 'created_at' => $this->created_at, ); } }