table = $db->prefix . 'us_policy_acceptances'; } public function insert( PolicyAcceptance $acceptance ): int { $this->db->insert( $this->table, [ 'policy_version_id' => $acceptance->policyVersionId, 'student_id' => $acceptance->studentId, 'registration_type' => $acceptance->registrationType, 'registration_id' => $acceptance->registrationId, 'ip_address' => $acceptance->ipAddress, 'accepted_at' => current_time( 'mysql' ), ], [ '%d', '%d', '%s', '%d', '%s', '%s' ] ); return $this->db->insert_id; } /** * Persist a batch of acceptances for a single registration. * * @param list $acceptances * @return list Inserted acceptance IDs. */ public function insertMany( array $acceptances ): array { return array_map( fn( PolicyAcceptance $a ): int => $this->insert( $a ), $acceptances ); } /** * Find all acceptances 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 %i WHERE registration_type = %s AND registration_id = %d ORDER BY id ASC', $this->table, $registrationType, $registrationId ) ); return array_map( PolicyAcceptance::fromRow( ... ), $rows ?? [] ); } /** * Find every acceptance a student has recorded, newest first. * * @return list */ public function findByStudent( int $studentId ): array { $rows = $this->db->get_results( $this->db->prepare( 'SELECT * FROM %i WHERE student_id = %d ORDER BY accepted_at DESC, id DESC', $this->table, $studentId ) ); return array_map( PolicyAcceptance::fromRow( ... ), $rows ?? [] ); } }