Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- * Description of ManufactureListTable'
- *
- * @author j
- */
- if (!class_exists('WP_List_Table')) {
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
- }
- class version extends WP_List_Table {
- //put your code here
- //GET TABLE DATA
- private $TABLE_DATA = array();
- private $TABLE = '';
- private $PER_PAGE = 20;
- private $TB_VERSION;
- private $FOUND_DATA;
- private $TB_ENGINES;
- Private $TB_BODY_TYPE;
- public function __construct() {
- array(
- 'singular' => 'attachment', //singular name of the listed records
- 'plural' => 'attachments', //plural name of the listed records
- 'ajax' => true //false //does this table support ajax?
- );
- //Insert data
- global $wpdb;
- $this->TABLE = $wpdb->prefix . PREFIX . 'version'; //set table name
- $this->TB_VERSION = $wpdb->prefix . PREFIX . 'models'; //set table name
- $this->TB_ENGINES = $wpdb->prefix . PREFIX . 'engines'; //set table name
- $this->TB_BODY_TYPE = $wpdb->prefix . PREFIX . 'body_type'; //set table name
- //Get data
- $this->getData();
- }
- private function getData(){
- global $wpdb;
- $query = "SELECT v.`vid`, v.`version`, v.`mod_id`, m.`model`,v.`eng_id`,v.`body_type_id`,e.`eng_name`,b.`body_type` "
- . "FROM $this->TABLE v INNER JOIN $this->TB_VERSION m ON v.`mod_id` = m.`mod_id` "
- . "INNER JOIN $this->TB_ENGINES e ON v.`eng_id` = e.`eng_id` "
- . "INNER JOIN $this->TB_BODY_TYPE b ON v.`body_type_id` = b.`body_type_id` "
- . "WHERE v.`isDel` = (0)";
- $this->TABLE_DATA = $wpdb->get_results($query, ARRAY_A);
- }
- //put your code here
- function get_columns() {
- $columns = array(
- 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
- 'vid' => 'Id',
- 'version' => 'Name',
- 'mod_id' => 'mod_Id',
- 'eng_id' => 'eng_id',
- 'eng_name' => 'Engine Name',
- 'body_type_id' => 'body_type_id',
- 'body_type' =>'Body Type',
- 'model' => 'Model',
- 'edit' => '<a></a>',
- );
- return $columns;
- }
- /**
- * Define which columns are hidden
- *
- * @return Array
- */
- public function get_hidden_columns() {
- return array('isDel', 'vid','mod_id','eng_id','body_type_id');
- }
- /**
- * Define the sortable columns
- *
- * @return Array
- */
- public function get_sortable_columns() {
- return array(
- 'version' => array('version', false),
- 'model'=>array('model', FALSE),
- 'eng_name'=>array('eng_name', FALSE),
- 'body_type'=>array('body_type', FALSE)
- );
- }
- /**
- * Prepare the items for the table to process
- *
- * @return Void
- */
- public function prepare_items() {
- $columns = $this->get_columns();
- $hidden = $this->get_hidden_columns();
- $sortable = $this->get_sortable_columns();
- usort($this->TABLE_DATA, array(&$this, 'sort_data'));
- $currentPage = $this->get_pagenum();
- $totalItems = count($this->TABLE_DATA);
- $this->set_pagination_args(array(
- 'total_items' => $totalItems,
- 'per_page' => $this->PER_PAGE
- ));
- $this->FOUND_DATA = array_slice($this->TABLE_DATA, (($currentPage - 1) * $this->PER_PAGE), $this->PER_PAGE);
- $this->_column_headers = array($columns, $hidden, $sortable);
- $this->items = $this->FOUND_DATA;
- /* Handle our bulk actions */
- $this->process_bulk_action();
- }
- /**
- * Define what data to show on each column of the table
- *
- * @param Array $item Data
- * @param String $column_name - Current column name
- *
- * @return Mixed
- */
- public function column_default($item, $column_name) {
- switch ($column_name) {
- case 'vid':
- case 'version':
- case 'mod_id':
- case 'model':
- case 'eng_id':
- case 'eng_name':
- case 'body_type_id':
- case 'body_type':
- case 'isDel':
- return $item[$column_name];
- default:
- return print_r($item, true);
- }
- }
- /**
- * 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 = $_GET['orderby'];
- }
- // If order is set use this as the order
- if (!empty($_GET['order'])) {
- $order = $_GET['order'];
- }
- $result = strnatcmp($a[$orderby], $b[$orderby]);
- if ($order === 'asc') {
- return $result;
- }
- return $result;
- }
- /**
- * Define our bulk actions
- *
- * @since 1.2
- * @returns array() $actions Bulk actions
- */
- function get_bulk_actions() {
- $actions = array(
- 'delete' => __('Delete', 'visual-form-builder')
- );
- return $actions;
- }
- /**
- * Process our bulk actions
- *
- * @since 1.2
- */
- function process_bulk_action() {
- $entry_id = ( is_array($_REQUEST['id']) ) ? $_REQUEST['id'] : array($_REQUEST['id']);
- if ('delete' === $this->current_action()) {
- global $wpdb;
- $data = implode($entry_id, ',');
- $query = "UPDATE $this->TABLE SET `isDel` = 1 WHERE `vid` in ($data)";
- $wpdb->query($query);
- echo '<script>alert("Data has been deleted successfully.");location.reload();</script>';
- }
- }
- /**
- * [REQUIRED] this is how checkbox column renders
- *
- * @param $item - row (key, value array)
- * @return HTML
- */
- function column_cb($item) {
- return sprintf(
- '<input type="checkbox" name="id[]" value="%s" />', $item['vid']
- );
- }
- function column_edit($item) {
- return sprintf(
- '<a href="admin.php?page=ebs-version&type=edit&id=%s" >Edit</a>', $item['vid']
- );
- }
- function extra_tablenav( $which ) {
- global $wpdb, $testiURL, $tablename, $tablet;
- $move_on_url = '&cat-filter=';
- if ( $which == "top" ){
- ?>
- <div class="alignleft actions bulkactions">
- <?php
- $cats = $wpdb->get_results('select * from '.$tablename.' order by title asc', ARRAY_A);
- if( $cats ){
- ?>
- <select name="cat-filter" class="ewc-filter-cat">
- <option value="">Filter by Category</option>
- <?php
- foreach( $cats as $cat ){
- $selected = '';
- if( $_GET['cat-filter'] == $cat['id'] ){
- $selected = ' selected = "selected"';
- }
- $has_testis = false;
- $chk_testis = $wpdb->get_row("select id from ".$tablet." where banner_id=".$cat['id'], ARRAY_A);
- if( $chk_testis['id'] > 0 ){
- ?>
- <option value="<?php echo $move_on_url . $cat['id']; ?>" <?php echo $selected; ?>><?php echo $cat['title']; ?></option>
- <?php
- }
- }
- ?>
- </select>
- <?php
- }
- ?>
- </div>
- <?php
- }
- if ( $which == "bottom" ){
- //The code that goes after the table is there
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement