'Title' * * @since 3.1.0 * @access public * * @return array */ public function getColumns() { $columns = [ 'cb' => '', 'image' => 'Thumb', 'title' => 'Title', 'external_id' => 'Alibaba SKU', 'user_schedule_time' => 'Shedule time' ]; return $columns; } /** * Prepares the list of items for displaying. * @uses WP_List_Table::set_pagination_args() * * @since 3.1.0 * @access public */ public function prepareItems() { $current_page = $this->getPagenum(); $db = WordpressDb::getInstance()->getDb(); $sql = 'SELECT count(*) FROM ' . $db->prefix . AEIDN_TABLE_GOODS_ARCHIVE . ' where user_schedule_time is not null and user_schedule_time <> "0000-00-00 00:00:00" '; $total = $db->get_var($sql); $sql = 'SELECT ' . $db->prefix . AEIDN_TABLE_GOODS_ARCHIVE . '.* FROM ' . $db->prefix . AEIDN_TABLE_GOODS_ARCHIVE . ' where user_schedule_time is not null and user_schedule_time <> "0000-00-00 00:00:00" order by %s limit ' . (($current_page - 1) * 20) . ',20'; $this->items = $db->get_results( $db->prepare( $sql, (isset($_GET['orderby']) ? sanitize_text_field($_GET['orderby']) . ' ' . sanitize_text_field($_GET['order']) : 'title desc') ) ); $this->setPagination(['total_items' => $total, 'per_page' => 20]); $this->initTable(); } public function columnCb($item) { return sprintf( '', $item->external_id ); } /** * @return array * @override */ public function getBulkActions() { $actions = [ 'unshedule' => 'Remove from shedule' ]; return $actions; } public function needLoadMoreDetail($item) { foreach (get_object_vars($item) as $f => $val) { if (!is_array($val) && (string)$val === '#needload#') { return true; } } return false; } public function getId($item) { return 'aliexpress#' . $item->external_id; } /** * Get a list of sortable columns. The format is: * 'internal-name' => 'orderby' * or * 'internal-name' => array( 'orderby', true ) * * The second format will make the initial sorting order be descending * * @since 3.1.0 * @access protected * * @return array */ protected function getSortableColumns() { return [ 'external_id' => ['external_id', false], 'title' => ['title', false], 'user_schedule_time' => ['user_schedule_time', false] ]; } protected function columnImage($item) { return ''; } protected function columnTitle($item) { $actions = []; $goods = new AEIDN_Goods("aliexpress#" . $item->external_id); $goods->load(); $actions['id'] = 'Product page' . "seller_url ? "" : "style='display:none'") . "> | Seller page"; // $actions['import'] = $goods->post_id ? 'Posted' : 'Post to Woocommerce'; $actions['load_more_detail'] = $goods->needLoadMoreDetail() ? 'Load more details' : 'Details loaded'; $actions['schedule_import'] = 'Schedule Post'; // $cat_name = ""; // foreach ($this->link_categories as $c) { // if ($c['term_id'] === $item->link_category_id) { // $cat_name = $c['name']; // break; // } // } $html = AEIDN_DashboardPage::putField($goods, "title", true, "edit", "Title", "") . AEIDN_DashboardPage::putField($goods, 'subtitle', true, "edit", "Subtitle", "subtitle-block") . AEIDN_DashboardPage::putField($goods, 'keywords', true, "edit", "Keywords", "subtitle-block") . AEIDN_DashboardPage::putDescriptionEdit($goods); // $html .= $item->title . ''; $html .= $this->rowActions($actions); return $html; } }