get_columns(); $hidden = $this->get_hidden_columns(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array( $columns, $hidden, $sortable ); $query = $this->table_data(); if ( is_wp_error( $query ) ) { $this->items = []; return; } $this->set_pagination_args( [ 'total_items' => $query->pagination->count, 'per_page' => $this->get_items_per_page( 'coupons' ), ] ); $this->items = $query->data; } /** * Search form. * * @return void */ public function search() { ?>
'', 'name' => __( 'Name', 'surecart' ), 'promotion_code' => __( 'Code', 'surecart' ), 'price' => __( 'Price', 'surecart' ), 'usage' => __( 'Usage', 'surecart' ), 'date' => __( 'Date', 'surecart' ), ], parent::get_columns() ); } /** * Displays the checkbox column. * * @param Product $product The product model. */ public function column_cb( $product ) { ?> array( 'title', false ) ); } /** * Get the table data * * @return Object */ private function table_data() { return Coupon::where( [ 'archived' => $this->getArchiveStatus(), 'query' => $this->get_search_query(), ] )->with( [ 'promotions' ] ) ->paginate( [ 'per_page' => $this->get_items_per_page( 'coupons' ), 'page' => $this->get_pagenum(), ] ); } /** * Handle the price column. * * @param \SureCart\Models\Coupon $coupon Coupon model. * * @return string */ public function column_price( $coupon ) { ob_start(); // phpcs:ignore echo $this->get_price_string( $coupon ?? false ); // this is already escaped. ?>' . sanitize_text_field( $coupon->promotions->data[0]->code ) . ' ' . $and;
}
/**
* Toggle archive action link and text.
*
* @param \SureCart\Models\Product $product Product model.
* @return string
*/
public function action_toggle_archive( $coupon ) {
$text = $coupon->archived ? __( 'Un-Archive', 'surecart' ) : __( 'Archive', 'surecart' );
$confirm_message = $coupon->archived ? __( 'Are you sure you want to restore this coupon? This will be be available to purchase.', 'surecart' ) : __( 'Are you sure you want to archive this coupon? This will be unavailable for purchase.', 'surecart' );
$link = \SureCart::getUrl()->toggleArchive( 'coupon', $coupon->id );
return sprintf(
'%4s',
esc_attr( $confirm_message ),
esc_url( $link ),
esc_attr__( 'Toggle Coupon Archive', 'surecart' ),
esc_html( $text )
);
}
/**
* Allows you to sort the data by the variables set in the $_GET.
*
* @return Mixed
*/
private function sort_data( $a, $b ) {
// Set defaults.
$orderby = 'title';
$order = 'asc';
// If orderby is set, use this as the sort column.
if ( ! empty( $_GET['orderby'] ) ) {
$orderby = sanitize_text_field( wp_unslash( $_GET['orderby'] ) );
}
// If order is set use this as the order.
if ( ! empty( $_GET['order'] ) ) {
$order = sanitize_text_field( wp_unslash( $_GET['order'] ) );
}
$result = strcmp( $a[ $orderby ], $b[ $orderby ] );
if ( 'asc' === $order ) {
return $result;
}
return -$result;
}
/**
* @global string $comment_status
*
* @return array
*/
protected function get_bulk_actions() {
return false;
global $comment_status;
$actions = array();
if ( in_array( $comment_status, array( 'all', 'approved' ), true ) ) {
$actions['unapprove'] = __( 'Unapprove', 'surecart' );
}
if ( in_array( $comment_status, array( 'all', 'moderated' ), true ) ) {
$actions['approve'] = __( 'Approve', 'surecart' );
}
if ( in_array( $comment_status, array( 'all', 'moderated', 'approved', 'trash' ), true ) ) {
$actions['spam'] = _x( 'Mark as spam', 'comment', 'surecart' );
}
if ( 'trash' === $comment_status ) {
$actions['untrash'] = __( 'Restore', 'surecart' );
} elseif ( 'spam' === $comment_status ) {
$actions['unspam'] = _x( 'Not spam', 'comment', 'surecart' );
}
if ( in_array( $comment_status, array( 'trash', 'spam' ), true ) || ! EMPTY_TRASH_DAYS ) {
$actions['delete'] = __( 'Delete permanently', 'surecart' );
} else {
$actions['trash'] = __( 'Move to Trash', 'surecart' );
}
return $actions;
}
}