*/ public function answers( Lesson $lesson ): array { return array_map( function ( Answer $answer ): array { $question = $this->questions->findById( $answer->questionId ); $value = $answer->answerValue ?? ''; return [ 'question' => $question ? $question->label : sprintf( '#%d', $answer->questionId ), 'answer' => '' === $value ? '—' : $value, ]; }, $this->answers->findByRegistration( Answer::REG_LESSON, $this->registrationId( $lesson ) ) ); } /** * The policy versions the student accepted when booking this lesson, with the * captured acceptance time and IP for the audit trail. * * @return list */ public function acceptances( Lesson $lesson ): array { return array_map( function ( PolicyAcceptance $acceptance ): array { $version = $this->versions->findById( $acceptance->policyVersionId ); $policy = $version ? $this->policies->findById( $version->policyId ) : null; return [ 'policy' => $policy ? $policy->title : sprintf( '#%d', $acceptance->policyVersionId ), 'version' => $version ? sprintf( 'v%d', $version->versionNumber ) : '—', 'accepted_at' => $acceptance->acceptedAt ?? '', 'ip' => $acceptance->ipAddress ?? '', ]; }, $this->acceptances->findByRegistration( PolicyAcceptance::REG_LESSON, $this->registrationId( $lesson ) ) ); } /** * The lesson id the booking's answers and acceptances were recorded against: * the series anchor for a weekly reservation, the lesson itself otherwise. */ private function registrationId( Lesson $lesson ): int { return $lesson->seriesId ?? (int) $lesson->id; } }