__('Broadcast', 'wp-ultimo'), // singular name of the listed records 'plural' => __('Broadcasts', 'wp-ultimo'), // plural name of the listed records 'ajax' => true, // does this table support ajax? 'add_new' => array( 'url' => wu_get_form_url('add_new_broadcast_message'), 'classes' => 'wubox', ), ) ); } /** * Overrides the checkbox column to disable the checkboxes on the email types. * * @since 2.0.0 * * @param \WP_Ultimo\Models\Broadcast $item The broadcast object. * @return string */ public function column_cb($item) { if ($item->get_type() === 'broadcast_email') { return ''; } return parent::column_cb($item); } /** * Returns the markup for the type column. * * @since 2.0.0 * * @param \WP_Ultimo\Models\Broadcast $item The broadcast object. * @return string */ public function column_type($item) { $type = $item->get_type(); $class = 'wu-bg-gray-200'; if ($type === 'broadcast_email') { $label = __('Email', 'wp-ultimo'); } if ($type === 'broadcast_notice') { $status = $item->get_notice_type(); $label = __('Notice', 'wp-ultimo'); if ($status === 'info') { $class = 'wu-bg-blue-200'; } elseif ($status === 'success') { $class = 'wu-bg-green-200'; } elseif ($status === 'warning') { $class = 'wu-bg-orange-200'; } elseif ($status === 'error') { $class = 'wu-bg-red-200'; } } return "{$label}"; } /** * Displays the name of the broadcast. * * @since 2.0.0 * * @param \WP_Ultimo\Models\Broadcast $item The broadcast object. */ public function column_the_content($item): string { $title = sprintf('%s', $item->get_title()); // phpcs:ignore $content = wp_trim_words(wp_strip_all_tags($item->get_content()), 7); $url_atts = array( 'id' => $item->get_id(), 'slug' => $item->get_slug(), 'model' => 'broadcast', ); $actions = array( 'edit' => sprintf('%s', wu_network_admin_url('wp-ultimo-edit-broadcast', $url_atts), __('Edit', 'wp-ultimo')), 'delete' => sprintf('%s', __('Delete', 'wp-ultimo'), wu_get_form_url('delete_modal', $url_atts), __('Delete', 'wp-ultimo')), ); return $title . $content . $this->row_actions($actions); } /** * Displays the target customers of the broadcast. * * @since 2.0.0 * * @param \WP_Ultimo\Models\Broadcast $item The broadcast object. * @return string */ public function column_target_customers($item) { $targets = wu_get_broadcast_targets($item->get_id(), 'customers'); $targets = array_filter(array_map('wu_get_customer', $targets)); $targets_count = count($targets); $html = '
'; switch ($targets_count) { case 0: $not_found = __('No customer found', 'wp-ultimo'); return "
 
{$not_found}
"; break; case 1: $customer = array_pop($targets); $url_atts = array( 'id' => $customer->get_id(), ); $customer_link = wu_network_admin_url('wp-ultimo-edit-customer', $url_atts); $avatar = get_avatar( $customer->get_user_id(), 32, 'identicon', '', array( 'force_display' => true, 'class' => 'wu-rounded-full wu-border-solid wu-border-1 wu-border-white hover:wu-border-gray-400', ) ); $display_name = $customer->get_display_name(); $id = $customer->get_id(); $email = $customer->get_email_address(); $html = " {$avatar}
{$display_name} (#{$id}) {$email}
"; return $html; break; default: foreach ($targets as $key => $target) { $customer = $target; $tooltip_name = $customer->get_display_name(); $email = $customer->get_email_address(); $avatar = get_avatar( $email, 32, 'identicon', '', array( 'class' => 'wu-rounded-full wu-border-solid wu-border-1 wu-border-white hover:wu-border-gray-400', ) ); $url_atts = array( 'id' => $customer->get_id(), ); $customer_link = wu_network_admin_url('wp-ultimo-edit-customer', $url_atts); $html .= "
{$avatar}
"; } if ($targets_count < 7) { $modal_atts = array( 'action' => 'wu_modal_targets_display', 'object_id' => $item->get_id(), 'width' => '400', 'height' => '360', 'target_type' => 'customers', ); $html .= sprintf( '
%s %s
', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $targets_count, __('Targets', 'wp-ultimo') ); $html .= '
'; return $html; } $modal_atts = array( 'action' => 'wu_modal_targets_display', 'object_id' => $item->get_id(), 'width' => '400', 'height' => '360', 'target_type' => 'customers', ); $html .= sprintf( '
%s %s
', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $targets_count, __('Targets', 'wp-ultimo') ); $html .= ''; return $html; break; } } /** * Displays the target products of the broadcast. * * @since 2.0.0 * * @param \WP_Ultimo\Models\Broadcast $item The broadcast object. * @return string */ public function column_target_products($item) { $targets = wu_get_broadcast_targets($item->get_id(), 'products'); $html = ''; $products = array_filter(array_map('wu_get_product', $targets)); $product_count = count($products); switch ($product_count) { case 0: $not_found = __('No product found', 'wp-ultimo'); $html = "
 
{$not_found}
"; break; case 1: $product = array_pop($products); $image = $product->get_featured_image('thumbnail'); if ($image) { $image = sprintf('', esc_attr($image)); } else { $image = '
'; } $name = $product->get_name(); $id = $product->get_id(); $plan_customers = wu_get_membership_customers($product->get_id()); $customer_count = (int) 0; if ($plan_customers) { $customer_count = count($plan_customers); } $description = sprintf(__('%s customer(s) targeted.', 'wp-ultimo'), $customer_count); $url_atts = array( 'id' => $product->get_id(), ); $product_link = wu_network_admin_url('wp-ultimo-edit-product', $url_atts); $html = " {$image}
{$name} (#{$id}) {$description}
"; break; } if ($html) { return $html; } $html = '
'; foreach ($products as $product) { $url_atts = array( 'id' => $product->get_id(), ); $product_link = wu_network_admin_url('wp-ultimo-edit-product', $url_atts); $product_name = $product->get_name(); $image = $product->get_featured_image('thumbnail'); if ($image) { $image = sprintf('', esc_attr($image)); } else { $image = '
'; } $html .= "
{$image}
"; } if ($product_count > 1 && $product_count < 5) { $modal_atts = array( 'action' => 'wu_modal_targets_display', 'object_id' => $item->get_id(), 'width' => '400', 'height' => '360', 'target_type' => 'products', ); $html .= sprintf( '
%s %s
', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $product_count, __('Targets', 'wp-ultimo') ); $html .= '
'; return $html; } $modal_atts = array( 'action' => 'wu_modal_targets_display', 'object_id' => $item->get_id(), 'width' => '400', 'height' => '360', 'target_type' => 'products', ); $html .= sprintf('
%s %s
', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $product_count, __('Targets', 'wp-ultimo')); $html .= ''; return $html; } /** * Returns the list of columns for this particular List Table. * * @since 2.0.0 * @return array */ public function get_columns() { $columns = array( 'cb' => '', 'type' => __('Type', 'wp-ultimo'), 'the_content' => __('Content', 'wp-ultimo'), 'target_customers' => __('Target Customers', 'wp-ultimo'), 'target_products' => __('Target Products', 'wp-ultimo'), 'date_created' => __('Date', 'wp-ultimo'), 'id' => __('ID', 'wp-ultimo'), ); return $columns; } /** * Returns the filters for this page. * * @since 2.0.0 */ public function get_filters(): array { return array( 'filters' => array( 'type' => array( 'label' => __('Broadcast Type', 'wp-ultimo'), 'options' => array( 'broadcast_notice' => __('Email', 'wp-ultimo'), 'broadcast_email' => __('Notices', 'wp-ultimo'), ), ), 'status' => array( 'label' => __('Notice Type', 'wp-ultimo'), 'options' => array( 'info' => __('Info - Blue', 'wp-ultimo'), 'success' => __('Success - Green', 'wp-ultimo'), 'warning' => __('Warning - Yellow', 'wp-ultimo'), 'error' => __('Error - Red', 'wp-ultimo'), ), ), ), 'date_filters' => array( 'date_created' => array( 'label' => __('Date', 'wp-ultimo'), 'options' => $this->get_default_date_filter_options(), ), ), ); } /** * Registers the necessary scripts and styles for this admin page. * * @since 2.0.0 * @return void */ public function register_scripts() { parent::register_scripts(); } /** * Returns the pre-selected filters on the filter bar. * * @since 2.0.0 * @return array */ public function get_views() { return array( 'all' => array( 'field' => 'status', 'url' => add_query_arg('type', 'all'), 'label' => __('All Broadcasts', 'wp-ultimo'), 'count' => 0, ), 'broadcast_email' => array( 'field' => 'type', 'url' => add_query_arg('type', 'broadcast_email'), 'label' => __('Emails', 'wp-ultimo'), 'count' => 0, ), 'broadcast_notice' => array( 'field' => 'type', 'url' => add_query_arg('type', 'broadcast_notice'), 'label' => __('Notices', 'wp-ultimo'), 'count' => 0, ), ); } }