'', 'fields' => array(), 'url' => '', 'link_label' => '' ); $type = (string) ( $row['object_type'] ?? '' ); $id = (int) ( $row['object_id'] ?? 0 ); $bookings = current_user_can( 'abientot_manage_bookings' ); $customers = current_user_can( 'abientot_manage_customers' ); $settings = current_user_can( 'abientot_manage_settings' ); $locations = current_user_can( 'abientot_manage_locations' ); $location_selection = false !== has_filter( 'abientot_render_locations_admin' ); $field = is_string( $row['notification_field'] ?? null ) ? $row['notification_field'] : ''; $key = get_current_user_id() . ':' . (int) $bookings . (int) $customers . (int) $settings . (int) $locations . (int) $location_selection . ':' . $type . ':' . $id . ':' . ( $type === 'settings' ? $field : '' ); if ( array_key_exists( $key, self::$cache ) ) { return self::$cache[ $key ]; } $details = $empty; try { if ( $type === 'appointment' && $id > 0 && $bookings ) { $booking = ( new AppointmentsRepository() )->find_for_admin( $id ); if ( $booking ) { $fields = array( __( 'Customer', 'abientot' ) => (string) ( $booking['customer_name'] ?? '' ) ); if ( ( $booking['booking_kind'] ?? '' ) === 'resource' ) { $fields[ __( 'Resource category', 'abientot' ) ] = (string) ( $booking['resource_category'] ?? '' ); $fields[ __( 'Resource', 'abientot' ) ] = (string) ( $booking['resource_label'] ?? '' ); $fields[ __( 'Guests', 'abientot' ) ] = (string) max( 1, (int) ( $booking['party_size'] ?? 1 ) ); } else { $fields[ __( 'Service', 'abientot' ) ] = (string) ( $booking['service_name'] ?? '' ); } $timezone = (string) ( $booking['timezone'] ?? '' ); $fields[ __( 'When', 'abientot' ) ] = DateTimeHelper::format_utc_datetime( (string) $booking['start_utc'], $timezone ?: null ) . ( $timezone ? ' (' . $timezone . ')' : '' ); $fields[ __( 'Duration', 'abientot' ) ] = sprintf( /* translators: %d: appointment duration in minutes. */ __( '%d min', 'abientot' ), (int) ( $booking['duration_minutes'] ?? 0 ) ); $fields[ __( 'Staff', 'abientot' ) ] = (string) ( $booking['staff_name'] ?? '' ); $fields[ __( 'Location', 'abientot' ) ] = (string) ( $booking['location_name'] ?? '' ); $fields[ __( 'Booking status', 'abientot' ) ] = (string) ( $booking['status_label'] ?? '' ); $payment = (string) ( $booking['payment_status'] ?? 'not_required' ); if ( (int) ( $booking['price_cents'] ?? 0 ) > 0 || $payment !== 'not_required' ) { $fields[ __( 'Price', 'abientot' ) ] = Currency::format( (int) ( $booking['price_cents'] ?? 0 ), (string) ( $booking['currency'] ?? '' ) ); $payments = array( 'paid' => __( 'Paid', 'abientot' ), 'unpaid' => __( 'Unpaid', 'abientot' ), 'not_required' => __( 'Not required', 'abientot' ), 'partial' => __( 'Partially paid', 'abientot' ), 'pending' => __( 'Pending', 'abientot' ), 'refunded' => __( 'Refunded', 'abientot' ) ); if ( isset( $payments[ $payment ] ) ) { $fields[ __( 'Payment status', 'abientot' ) ] = $payments[ $payment ]; } } $details = array( 'title' => sprintf( /* translators: %d: booking ID. */ __( 'Booking #%d', 'abientot' ), $id ), 'fields' => array_filter( $fields, static fn( string $value ): bool => $value !== '' ), 'url' => admin_url( 'admin.php?page=abientot-bookings&booking_id=' . $id ), 'link_label' => __( 'Open booking', 'abientot' ) ); } } elseif ( $type === 'customer' && $id > 0 && $customers ) { $customer = ( new CustomersRepository() )->find( $id ); if ( $customer ) { $name = (string) ( $customer['display_name'] ?? '' ); if ( $name === '' ) { $name = trim( (string) ( $customer['first_name'] ?? '' ) . ' ' . (string) ( $customer['last_name'] ?? '' ) ); } $details = array( 'title' => sprintf( /* translators: %d: customer ID. */ __( 'Customer #%d', 'abientot' ), $id ), 'fields' => $name === '' ? array() : array( __( 'Customer', 'abientot' ) => $name ), 'url' => admin_url( 'admin.php?page=abientot-customers&customer_id=' . $id ), 'link_label' => __( 'Open customer', 'abientot' ) ); } } elseif ( $type === 'settings' && $settings ) { $notifications = in_array( $field, array( 'categories', 'hours', 'extend_closures' ), true ); $details = array( 'title' => $notifications ? __( 'Notifications', 'abientot' ) : __( 'Settings', 'abientot' ), 'fields' => array(), 'url' => admin_url( 'admin.php?page=abientot-' . ( $notifications ? 'notification-settings' : 'settings' ) ), 'link_label' => __( 'Open settings', 'abientot' ) ); if ( $id > 0 && $locations ) { $location = ( new LocationsRepository() )->find( $id ); if ( $location ) { $details['fields'] = array( __( 'Location', 'abientot' ) => (string) ( $location['name'] ?? '' ) ); $selectable = $location_selection || ! empty( $location['is_default'] ); $details['url'] = $selectable ? admin_url( 'admin.php?page=abientot-locations&location_id=' . $id ) : ''; $details['link_label'] = $selectable ? __( 'Open location', 'abientot' ) : ''; } } } elseif ( $bookings && $id > 0 && ! in_array( $type, array( 'appointment', 'customer', 'settings' ), true ) ) { // Premium adapters own optional-store readiness and contextual destinations. $details = apply_filters( 'abientot_activity_details', $empty, array( 'object_type' => $type, 'object_id' => $id, 'event' => (string) ( $row['event'] ?? '' ) ) ); } } catch ( \Throwable $error ) { $details = $empty; } return self::$cache[ $key ] = $details; } }