/** * Defines predefines filters for this list table. * * @since 1.0.0 * @return array */ public function get_views() { $views = array(); $base_url = remove_query_arg(array('state', 'id', 'invoice')); $views['all'] = array('label' => __('All', 'membership2'), 'url' => $base_url, 'count' => MS_Model_Transactionlog::get_item_count()); $views['ok'] = array('label' => __('Successful', 'membership2'), 'url' => add_query_arg('state', 'ok', $base_url), 'count' => MS_Model_Transactionlog::get_item_count(array('state' => 'ok'))); $views['err'] = array('label' => __('Failed', 'membership2'), 'url' => add_query_arg('state', 'err', $base_url), 'count' => MS_Model_Transactionlog::get_item_count(array('state' => 'err'))); $views['ignore'] = array('label' => __('Ignored', 'membership2'), 'url' => add_query_arg('state', 'ignore', $base_url), 'count' => MS_Model_Transactionlog::get_item_count(array('state' => 'ignore'))); return apply_filters('ms_helper_listtable_transactionlog_views', $views); }
/** * Loads the items that are displayed on the current list page. * * @since 1.0.1.2 */ public function prepare_items() { $this->_column_headers = array($this->get_columns(), $this->get_hidden_columns(), $this->get_sortable_columns()); $current_page = $this->get_pagenum(); $args = array('posts_per_page' => -1, 'offset' => 0); if (!empty($_GET['source']) && !empty($_GET['source_id'])) { $this->matching_type = $_GET['source']; $this->matching_type_id = $_GET['source_id']; $args['state'] = array('err', 'ignore'); $args['source'] = array($this->matching_type_id, $this->matching_type); $total_items = MS_Model_Transactionlog::get_item_count($args); $this->items = apply_filters('ms_helper_listtable_transactionmatching_items', MS_Model_Transactionlog::get_items($args)); $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page)); } }
/** * Loads the items that are displayed on the current list page. * * @since 1.0.0 */ public function prepare_items() { $this->_column_headers = array($this->get_columns(), $this->get_hidden_columns(), $this->get_sortable_columns()); $per_page = $this->get_items_per_page('transactionlog_per_page', self::DEFAULT_PAGE_SIZE); $current_page = $this->get_pagenum(); $args = array('posts_per_page' => $per_page, 'offset' => ($current_page - 1) * $per_page); if (!empty($_GET['state'])) { $args['state'] = $_GET['state']; } if (!empty($_GET['gateway_id'])) { $args['meta_query'] = array('gateway_id' => array('key' => '_gateway_id', 'value' => $_GET['gateway_id'])); } $total_items = MS_Model_Transactionlog::get_item_count($args); $this->items = apply_filters('ms_helper_listtable_transactionlog_items', MS_Model_Transactionlog::get_items($args)); $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page)); }
/** * Create view output. * * @since 1.0.0 * * @return string */ public function to_html() { $this->check_simulation(); $buttons = array(); // Count invalid transactions. $args = array('state' => 'err'); $error_count = MS_Model_Transactionlog::get_item_count($args); if ($error_count && (empty($_GET['state']) || 'err' != $_GET['state'])) { if (1 == $error_count) { $message = __('One transaction failed. Please %2$sreview the logs%3$s and decide if you want to ignore the transaction or manually assign it to an invoice.', MS_TEXT_DOMAIN); } else { $message = __('%1$s transactions failed. Please %2$sreview the logs%3$s and decide if you want to ignore the transaction or manually assign it to an invoice.', MS_TEXT_DOMAIN); } $review_url = MS_Controller_Plugin::get_admin_url('billing', array('show' => 'logs', 'state' => 'err')); lib2()->ui->admin_message(sprintf($message, $error_count, '<a href="' . $review_url . '">', '</a>'), 'err'); } if (isset($_GET['show']) && 'logs' == $_GET['show']) { $title = __('Transaction Logs', MS_TEXT_DOMAIN); $listview = MS_Factory::create('MS_Helper_ListTable_TransactionLog'); $listview->prepare_items(); $buttons[] = array('type' => MS_Helper_Html::TYPE_HTML_LINK, 'url' => MS_Controller_Plugin::get_admin_url('billing'), 'value' => __('Show Invoices', MS_TEXT_DOMAIN), 'class' => 'button'); } else { $title = __('Billing', MS_TEXT_DOMAIN); $listview = MS_Factory::create('MS_Helper_ListTable_Billing'); $listview->prepare_items(); $buttons[] = array('id' => 'add_new', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'url' => MS_Controller_Plugin::get_admin_url('billing', array('action' => MS_Controller_Billing::ACTION_EDIT, 'invoice_id' => 0)), 'value' => __('Create new Invoice', MS_TEXT_DOMAIN), 'class' => 'button'); $buttons[] = array('type' => MS_Helper_Html::TYPE_HTML_LINK, 'url' => MS_Controller_Plugin::get_admin_url('billing', array('show' => 'logs')), 'value' => __('Show Transaction Logs', MS_TEXT_DOMAIN), 'class' => 'button'); if (!empty($_GET['gateway_id'])) { $gateway = MS_Model_Gateway::factory($_GET['gateway_id']); if ($gateway->name) { $title .= ' - ' . $gateway->name; } } } ob_start(); ?> <div class="wrap ms-wrap ms-billing"> <?php MS_Helper_Html::settings_header(array('title' => $title, 'title_icon_class' => 'wpmui-fa wpmui-fa-credit-card')); ?> <div> <?php foreach ($buttons as $button) { MS_Helper_Html::html_element($button); } ?> </div> <?php $listview->views(); $listview->search_box(__('User', MS_TEXT_DOMAIN), 'search'); ?> <form action="" method="post"> <?php $listview->display(); ?> </form> </div> <?php $html = ob_get_clean(); return apply_filters('ms_view_billing_list', $html, $this); }
/** * Create view output. * * @since 1.0.0 * * @return string */ public function to_html() { $this->check_simulation(); $buttons = array(); $module = 'billing'; if (isset($_GET['show'])) { $module = $_GET['show']; } if (!$module) { // Show a message if there are error-state transactions. $args = array('state' => 'err'); $error_count = MS_Model_Transactionlog::get_item_count($args); if ($error_count) { if (1 == $error_count) { $message = __('One transaction failed. Please %2$sreview the logs%3$s and decide if you want to ignore the transaction or manually assign it to an invoice.', 'membership2'); } else { $message = __('%1$s transactions failed. Please %2$sreview the logs%3$s and decide if you want to ignore the transaction or manually assign it to an invoice.', 'membership2'); } $review_url = MS_Controller_Plugin::get_admin_url('billing', array('show' => 'logs', 'state' => 'err')); lib3()->ui->admin_message(sprintf($message, $error_count, '<a href="' . $review_url . '">', '</a>'), 'err'); } } // Decide which list to display in the Billings page. switch ($module) { // Transaction logs. case 'logs': $title = __('Transaction Logs', 'membership2'); $listview = MS_Factory::create('MS_Helper_ListTable_TransactionLog'); $listview->prepare_items(); $buttons[] = array('type' => MS_Helper_Html::TYPE_HTML_LINK, 'url' => MS_Controller_Plugin::get_admin_url('billing'), 'value' => __('Show Invoices', 'membership2'), 'class' => 'button'); break; // M1 Migration matching. // M1 Migration matching. case 'matching': $title = __('Automatic Transaction Matching', 'membership2'); $listview = MS_Factory::create('MS_Helper_ListTable_TransactionMatching'); $listview->prepare_items(); $buttons[] = array('type' => MS_Helper_Html::TYPE_HTML_LINK, 'url' => MS_Controller_Plugin::get_admin_url('billing'), 'value' => __('Show Invoices', 'membership2'), 'class' => 'button'); $buttons[] = array('type' => MS_Helper_Html::TYPE_HTML_LINK, 'url' => MS_Controller_Plugin::get_admin_url('billing', array('show' => 'logs')), 'value' => __('Show Transaction Logs', 'membership2'), 'class' => 'button'); break; // Default billings list. // Default billings list. case 'billing': default: $title = __('Billing', 'membership2'); $listview = MS_Factory::create('MS_Helper_ListTable_Billing'); $listview->prepare_items(); $buttons[] = array('id' => 'add_new', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'url' => MS_Controller_Plugin::get_admin_url('billing', array('action' => MS_Controller_Billing::ACTION_EDIT, 'invoice_id' => 0)), 'value' => __('Create new Invoice', 'membership2'), 'class' => 'button'); $buttons[] = array('type' => MS_Helper_Html::TYPE_HTML_LINK, 'url' => MS_Controller_Plugin::get_admin_url('billing', array('show' => 'logs')), 'value' => __('Show Transaction Logs', 'membership2'), 'class' => 'button'); if (!empty($_GET['gateway_id'])) { $gateway = MS_Model_Gateway::factory($_GET['gateway_id']); if ($gateway->name) { $title .= ' - ' . $gateway->name; } } break; } if ('matching' != $module) { if (MS_Model_Import::can_match()) { $btn_label = __('Setup automatic matching', 'membership2'); $btn_class = 'button'; } else { $btn_label = '(' . __('Setup automatic matching', 'membership2') . ')'; $btn_class = 'button button-link'; } $buttons[] = array('type' => MS_Helper_Html::TYPE_HTML_LINK, 'url' => MS_Controller_Plugin::get_admin_url('billing', array('show' => 'matching')), 'value' => $btn_label, 'class' => $btn_class); } // Default list view part - dislay prepared values from above. ob_start(); ?> <div class="wrap ms-wrap ms-billing"> <?php MS_Helper_Html::settings_header(array('title' => $title, 'title_icon_class' => 'wpmui-fa wpmui-fa-credit-card')); ?> <div> <?php foreach ($buttons as $button) { MS_Helper_Html::html_element($button); } ?> </div> <?php $listview->views(); $listview->search_box(__('User', 'membership2'), 'search'); ?> <form action="" method="post"> <?php $listview->display(); ?> </form> </div> <?php $html = ob_get_clean(); return apply_filters('ms_view_billing_list', $html, $this); }