*/ public function answers( IntakeSubject $subject ): 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, 'source' => $this->source( $answer->collectedVia, $answer->collectedNote, $answer->recordedBy ), ]; }, $this->answers->findByRegistration( $subject->intakeRegistrationType(), $subject->intakeRegistrationId() ) ); } /** * Where a recorded row came from: given online by the student, or collected * some other way and typed in — in which case who typed it is named, since an * unattributed transcription is worth much less than an attributed one. */ private function source( ?string $collectedVia, ?string $collectedNote, int $recordedBy ): string { $described = IntakeProvenance::describe( $collectedVia, $collectedNote ); if ( null === $collectedVia || '' === $collectedVia || $recordedBy <= 0 ) { return $described; } $user = get_userdata( $recordedBy ); return sprintf( /* translators: 1: how the answer was collected, 2: name of the staff member who recorded it. */ __( '%1$s — recorded by %2$s', 'unsupervised-schedular' ), $described, UserName::format( $user instanceof \WP_User ? $user : null, $recordedBy ) ); } /** * The policy versions the student accepted for this registration, with the * captured acceptance time and IP for the audit trail. * * @return list */ public function acceptances( IntakeSubject $subject ): 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 ?? '', 'source' => $this->source( $acceptance->collectedVia, $acceptance->collectedNote, $acceptance->recordedBy ), ]; }, $this->acceptances->findByRegistration( $subject->intakeRegistrationType(), $subject->intakeRegistrationId() ) ); } }