table = $db->prefix . 'us_question_answers'; } public function insert( Answer $answer ): int { $this->db->insert( $this->table, [ 'question_id' => $answer->questionId, 'registration_type' => $answer->registrationType, 'registration_id' => $answer->registrationId, 'student_id' => $answer->studentId, 'answer_value' => $answer->answerValue, 'created_at' => current_time( 'mysql' ), ], [ '%d', '%s', '%d', '%d', '%s', '%s' ] ); return $this->db->insert_id; } /** * Persist a batch of answers for a single registration. * * @param list $answers * @return list Inserted answer IDs. */ public function insertMany( array $answers ): array { return array_map( fn( Answer $answer ): int => $this->insert( $answer ), $answers ); } /** * Find all answers attached to a registration (lesson or enrolment). * * @return list */ public function findByRegistration( string $registrationType, int $registrationId ): array { $rows = $this->db->get_results( $this->db->prepare( "SELECT * FROM {$this->table} WHERE registration_type = %s AND registration_id = %d ORDER BY id ASC", $registrationType, $registrationId ) ); return array_map( Answer::fromRow( ... ), $rows ?? [] ); } }