Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. * To change this license header, choose License Headers in Project Properties.
  5. * To change this template file, choose Tools | Templates
  6. * and open the template in the editor.
  7. */
  8.  
  9. /**
  10. * Description of ManufactureListTable'
  11. *
  12. * @author j
  13. */
  14. if (!class_exists('WP_List_Table')) {
  15. require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
  16. }
  17.  
  18. class version extends WP_List_Table {
  19. //put your code here
  20. //GET TABLE DATA
  21. private $TABLE_DATA = array();
  22. private $TABLE = '';
  23. private $PER_PAGE = 20;
  24. private $TB_VERSION;
  25. private $FOUND_DATA;
  26. private $TB_ENGINES;
  27. Private $TB_BODY_TYPE;
  28.  
  29.  
  30. public function __construct() {
  31. array(
  32. 'singular' => 'attachment', //singular name of the listed records
  33. 'plural' => 'attachments', //plural name of the listed records
  34. 'ajax' => true //false //does this table support ajax?
  35. );
  36. //Insert data
  37. global $wpdb;
  38. $this->TABLE = $wpdb->prefix . PREFIX . 'version'; //set table name
  39. $this->TB_VERSION = $wpdb->prefix . PREFIX . 'models'; //set table name
  40. $this->TB_ENGINES = $wpdb->prefix . PREFIX . 'engines'; //set table name
  41. $this->TB_BODY_TYPE = $wpdb->prefix . PREFIX . 'body_type'; //set table name
  42. //Get data
  43. $this->getData();
  44. }
  45.  
  46. private function getData(){
  47. global $wpdb;
  48. $query = "SELECT v.`vid`, v.`version`, v.`mod_id`, m.`model`,v.`eng_id`,v.`body_type_id`,e.`eng_name`,b.`body_type` "
  49. . "FROM $this->TABLE v INNER JOIN $this->TB_VERSION m ON v.`mod_id` = m.`mod_id` "
  50. . "INNER JOIN $this->TB_ENGINES e ON v.`eng_id` = e.`eng_id` "
  51. . "INNER JOIN $this->TB_BODY_TYPE b ON v.`body_type_id` = b.`body_type_id` "
  52. . "WHERE v.`isDel` = (0)";
  53.  
  54. $this->TABLE_DATA = $wpdb->get_results($query, ARRAY_A);
  55. }
  56.  
  57.  
  58. //put your code here
  59. function get_columns() {
  60. $columns = array(
  61. 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
  62. 'vid' => 'Id',
  63. 'version' => 'Name',
  64. 'mod_id' => 'mod_Id',
  65. 'eng_id' => 'eng_id',
  66. 'eng_name' => 'Engine Name',
  67. 'body_type_id' => 'body_type_id',
  68. 'body_type' =>'Body Type',
  69. 'model' => 'Model',
  70. 'edit' => '<a></a>',
  71. );
  72. return $columns;
  73. }
  74.  
  75. /**
  76. * Define which columns are hidden
  77. *
  78. * @return Array
  79. */
  80. public function get_hidden_columns() {
  81. return array('isDel', 'vid','mod_id','eng_id','body_type_id');
  82. }
  83.  
  84. /**
  85. * Define the sortable columns
  86. *
  87. * @return Array
  88. */
  89. public function get_sortable_columns() {
  90. return array(
  91. 'version' => array('version', false),
  92. 'model'=>array('model', FALSE),
  93. 'eng_name'=>array('eng_name', FALSE),
  94. 'body_type'=>array('body_type', FALSE)
  95.  
  96. );
  97. }
  98.  
  99. /**
  100. * Prepare the items for the table to process
  101. *
  102. * @return Void
  103. */
  104. public function prepare_items() {
  105. $columns = $this->get_columns();
  106. $hidden = $this->get_hidden_columns();
  107. $sortable = $this->get_sortable_columns();
  108.  
  109. usort($this->TABLE_DATA, array(&$this, 'sort_data'));
  110.  
  111. $currentPage = $this->get_pagenum();
  112. $totalItems = count($this->TABLE_DATA);
  113.  
  114. $this->set_pagination_args(array(
  115. 'total_items' => $totalItems,
  116. 'per_page' => $this->PER_PAGE
  117. ));
  118.  
  119. $this->FOUND_DATA = array_slice($this->TABLE_DATA, (($currentPage - 1) * $this->PER_PAGE), $this->PER_PAGE);
  120.  
  121. $this->_column_headers = array($columns, $hidden, $sortable);
  122. $this->items = $this->FOUND_DATA;
  123.  
  124. /* Handle our bulk actions */
  125. $this->process_bulk_action();
  126. }
  127.  
  128. /**
  129. * Define what data to show on each column of the table
  130. *
  131. * @param Array $item Data
  132. * @param String $column_name - Current column name
  133. *
  134. * @return Mixed
  135. */
  136. public function column_default($item, $column_name) {
  137. switch ($column_name) {
  138. case 'vid':
  139. case 'version':
  140. case 'mod_id':
  141. case 'model':
  142. case 'eng_id':
  143. case 'eng_name':
  144. case 'body_type_id':
  145. case 'body_type':
  146. case 'isDel':
  147.  
  148. return $item[$column_name];
  149.  
  150. default:
  151. return print_r($item, true);
  152. }
  153. }
  154.  
  155. /**
  156. * Allows you to sort the data by the variables set in the $_GET
  157. *
  158. * @return Mixed
  159. */
  160. private function sort_data($a, $b) {
  161. // Set defaults
  162. $orderby = 'title';
  163. $order = 'asc';
  164.  
  165. // If orderby is set, use this as the sort column
  166. if (!empty($_GET['orderby'])) {
  167. $orderby = $_GET['orderby'];
  168. }
  169.  
  170. // If order is set use this as the order
  171. if (!empty($_GET['order'])) {
  172. $order = $_GET['order'];
  173. }
  174.  
  175. $result = strnatcmp($a[$orderby], $b[$orderby]);
  176.  
  177. if ($order === 'asc') {
  178. return $result;
  179. }
  180.  
  181. return $result;
  182. }
  183.  
  184. /**
  185. * Define our bulk actions
  186. *
  187. * @since 1.2
  188. * @returns array() $actions Bulk actions
  189. */
  190. function get_bulk_actions() {
  191. $actions = array(
  192. 'delete' => __('Delete', 'visual-form-builder')
  193. );
  194.  
  195. return $actions;
  196. }
  197.  
  198. /**
  199. * Process our bulk actions
  200. *
  201. * @since 1.2
  202. */
  203. function process_bulk_action() {
  204. $entry_id = ( is_array($_REQUEST['id']) ) ? $_REQUEST['id'] : array($_REQUEST['id']);
  205.  
  206. if ('delete' === $this->current_action()) {
  207. global $wpdb;
  208.  
  209. $data = implode($entry_id, ',');
  210. $query = "UPDATE $this->TABLE SET `isDel` = 1 WHERE `vid` in ($data)";
  211. $wpdb->query($query);
  212. echo '<script>alert("Data has been deleted successfully.");location.reload();</script>';
  213. }
  214. }
  215.  
  216. /**
  217. * [REQUIRED] this is how checkbox column renders
  218. *
  219. * @param $item - row (key, value array)
  220. * @return HTML
  221. */
  222. function column_cb($item) {
  223. return sprintf(
  224. '<input type="checkbox" name="id[]" value="%s" />', $item['vid']
  225. );
  226. }
  227.  
  228. function column_edit($item) {
  229. return sprintf(
  230. '<a href="admin.php?page=ebs-version&type=edit&id=%s" >Edit</a>', $item['vid']
  231. );
  232. }
  233.  
  234.  
  235.  
  236. function extra_tablenav( $which ) {
  237. global $wpdb, $testiURL, $tablename, $tablet;
  238. $move_on_url = '&cat-filter=';
  239. if ( $which == "top" ){
  240. ?>
  241. <div class="alignleft actions bulkactions">
  242. <?php
  243. $cats = $wpdb->get_results('select * from '.$tablename.' order by title asc', ARRAY_A);
  244. if( $cats ){
  245. ?>
  246. <select name="cat-filter" class="ewc-filter-cat">
  247. <option value="">Filter by Category</option>
  248. <?php
  249. foreach( $cats as $cat ){
  250. $selected = '';
  251. if( $_GET['cat-filter'] == $cat['id'] ){
  252. $selected = ' selected = "selected"';
  253. }
  254. $has_testis = false;
  255. $chk_testis = $wpdb->get_row("select id from ".$tablet." where banner_id=".$cat['id'], ARRAY_A);
  256. if( $chk_testis['id'] > 0 ){
  257. ?>
  258. <option value="<?php echo $move_on_url . $cat['id']; ?>" <?php echo $selected; ?>><?php echo $cat['title']; ?></option>
  259. <?php
  260. }
  261. }
  262. ?>
  263. </select>
  264. <?php
  265. }
  266. ?>
  267. </div>
  268. <?php
  269. }
  270. if ( $which == "bottom" ){
  271. //The code that goes after the table is there
  272.  
  273. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement