insert( Schema::events_table(), array( 'receipt_id' => $receipt_id, 'type' => $type, 'from_status' => (string) ( $data['from_status'] ?? '' ), 'to_status' => (string) ( $data['to_status'] ?? '' ), 'public_note' => (string) ( $data['public_note'] ?? '' ), 'private_note' => (string) ( $data['private_note'] ?? '' ), 'actor_id' => (int) ( $data['actor_id'] ?? 0 ), 'created_at' => current_time( 'mysql', true ), ), array( '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%s' ) ); return (int) $wpdb->insert_id; } public static function for_receipt( int $receipt_id ): array { global $wpdb; $table = Schema::events_table(); return (array) $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %i WHERE receipt_id = %d ORDER BY id ASC', $table, $receipt_id ), ARRAY_A ); } /** * Events the visitor is allowed to see (no private notes, no email log). */ public static function public_timeline( int $receipt_id ): array { $out = array(); foreach ( self::for_receipt( $receipt_id ) as $event ) { if ( self::EMAIL_SENT === $event['type'] ) { continue; } if ( self::NOTE === $event['type'] && '' === (string) $event['public_note'] ) { continue; } unset( $event['private_note'], $event['actor_id'] ); $out[] = $event; } return $out; } }