'',
'subject' => esc_html__( 'Subject', 'affi-affiliate-marketing-for-woo' ),
'recipient' => esc_html__( 'Recipient', 'affi-affiliate-marketing-for-woo' ),
'type' => esc_html__( 'Type', 'affi-affiliate-marketing-for-woo' ),
'date_created' => esc_html__( 'Date created', 'affi-affiliate-marketing-for-woo' ),
'status' => esc_html__( 'Status', 'affi-affiliate-marketing-for-woo' ),
);
return $columns;
}
/**
* Column combobox.
*/
public function column_cb( $item ) {
return sprintf( '', $item['id'] ?? 0 );
}
/**
* Display table column
*
* @param array|object $item Item in table data
* @param string $column_name
*
* @return string|void
*/
public function column_default( $item, $column_name ) {
$date_format = get_option( 'date_format' );
$time_format = get_option( 'time_format' );
$gmt_offset = get_option( 'gmt_offset' );
switch ( $column_name ) {
case 'subject':
// return sprintf( '%s
// ',
// esc_attr( $item['id'] ), $item['user_nicename'] . ' (' . $item['user_email'] . ')' );
return sprintf( '%s
',
esc_html( $item['subject'] ),
esc_attr( $item['id'] ),
esc_html__( 'Edit', 'affi-affiliate-marketing-for-woo' ),
esc_html__( 'Delete', 'affi-affiliate-marketing-for-woo' ) );
break;
case 'type':
return esc_html( $item['type'] );
break;
case 'recipient':
$recipient = $item['recipient'];
//format field
return esc_html( $recipient );
break;
case 'date_created':
return esc_html( date_i18n( "{$date_format} {$time_format}", ( $item['date_created'] ) + $gmt_offset * 3600 ) );
break;
case 'status':
return esc_html( $item['status'] ? 'Active' : 'Inactive' );
break;
default:
break;
}
return '';
}
/**
* Get bulk actions.
*
* @return array
*/
public function get_bulk_actions() {
return array(
'enable' => esc_html__( 'Enable', 'affi-affiliate-marketing-for-woo' ),
'disable' => esc_html__( 'Disable', 'affi-affiliate-marketing-for-woo' ),
'delete' => esc_html__( 'Delete', 'affi-affiliate-marketing-for-woo' ),
);
}
/**
* Display tablenav for search
*
* @param $which
*/
public function display_tablenav( $which ) {
// if ( 'top' === $which ) {
// printf( '' );
// $this->search_box( esc_html__( 'Search By User', 'affi-affiliate-marketing-for-woo' ), 'affi-conversation-search' );
// printf( '
' );
// }
printf( '', esc_attr( $which ) );
wp_nonce_field( '_affi_notification_action', '_affi_notification_action' );
if ( $this->has_items() ) {
printf( '
' );
$this->bulk_actions( );
printf( '
' );
}
$this->extra_tablenav( $which );
$this->pagination( $which );
printf( '
' );
}
/**
* Query and prepare data for table
*/
public function prepare_items() {
$per_page = $this->get_items_per_page( 'affi_notification_per_page', 20 );
$current_page = $this->get_pagenum();
$action = $this->current_action();
$where = array();
if ( $action ) {
check_admin_referer( '_affi_notification_action', '_affi_notification_action' );
switch ( $action ) {
case 'delete':
if ( ! affi_current_user_can_manage() ) {
wp_die( esc_html__( 'You do not have permission to delete conversations', 'affi-affiliate-marketing-for-woo' ) );
}
$notifications_id = isset( $_REQUEST['id'] ) ? array_map( 'absint', (array) villatheme_sanitize_fields( wp_unslash( $_REQUEST['id'] ) ) ) : array();// phpcs:ignore WordPress.Security.ValidatedSanitizedInput, WordPress.Security.NonceVerification.Recommended
if ( $notifications_id ) {
foreach ( $notifications_id as $notification_id ) {
AFNotifications::delete_notification( $notification_id );
}
}
break;
case 'disable':
case 'enable':
if ( ! affi_current_user_can_manage() ) {
wp_die( esc_html__( 'You do not have permission to edit conversations', 'affi-affiliate-marketing-for-woo' ) );
}
$status = ( $action == 'enable') ? 1 : 0;
$notifications_ids = isset( $_REQUEST['id'] ) ? array_map( 'absint', (array) villatheme_sanitize_fields( wp_unslash( $_REQUEST['id'] ) ) ) : array();// phpcs:ignore WordPress.Security.ValidatedSanitizedInput, WordPress.Security.NonceVerification.Recommended
if ( $notifications_ids ) {
foreach ( $notifications_ids as $notification_id ) {
AFNotifications::update( [ 'id' => $notification_id, 'status' => $status ] );
}
}
break;
default:
break;
}
}
$args = [
'where' => $where,
'limit' => $per_page,
'offset' => ( $current_page - 1 ) * $per_page
];
$get_affiliates = AFNotifications::get_setting_notifications( $args ) ?? array();
$this->items = $get_affiliates;
if ( ! empty( $this->items ) ) {
$total_items = count( $get_affiliates );
$this->set_pagination_args( array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil( $total_items / $per_page )
) );
}
$columns = $this->get_columns();
$hidden = array();
$sortable = array();
$this->_column_headers = array( $columns, $hidden, $sortable );
}
}