$details Context, stored as JSON. * @param string $type Object type. */ public function record( int $booking_id, string $action, array $details = array(), string $type = 'booking' ): void { $this->db->insert( $this->table, array( 'object_type' => $type, 'object_id' => $booking_id, 'user_id' => get_current_user_id(), 'action' => $action, 'details' => array() === $details ? null : wp_json_encode( $details ), 'created_at' => self::now(), ) ); } /** * An object's history, oldest first. * * @param int $id Object. * @param string $type Object type. * @return array> */ public function for_object( int $id, string $type = 'booking' ): array { // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery $rows = (array) $this->db->get_results( $this->db->prepare( "SELECT * FROM {$this->table} WHERE object_type = %s AND object_id = %d ORDER BY id", $type, $id ), ARRAY_A ); return array_map( static fn( array $row ): array => array( 'user_id' => (int) $row['user_id'], 'action' => (string) $row['action'], 'details' => (array) self::json( $row['details'] ), 'created_at' => self::ts( $row['created_at'] ), ), $rows ); } }