WC_Compare_Categories_Data

WooCommerce Compare Categories Data.

Defined (1)

The class is defined in the following location(s).

/classes/data/class-wc-compare-categories-data.php  
  1. class WC_Compare_Categories_Data  
  2. public static function install_database() { 
  3. global $wpdb; 
  4. $collate = ''; 
  5. if ( $wpdb->has_cap( 'collation' ) ) { 
  6. if( ! empty($wpdb->charset ) ) $collate .= "DEFAULT CHARACTER SET $wpdb->charset"; 
  7. if( ! empty($wpdb->collate ) ) $collate .= " COLLATE $wpdb->collate"; 
  8. $table_compare_categories = $wpdb->prefix. "woo_compare_categories"; 
  9. if ($wpdb->get_var("SHOW TABLES LIKE '$table_compare_categories'") != $table_compare_categories) { 
  10. $sql = "CREATE TABLE IF NOT EXISTS `{$table_compare_categories}` ( 
  11. `id` int(11) NOT NULL auto_increment,  
  12. `category_name` blob NOT NULL,  
  13. `category_order` int(11) NOT NULL,  
  14. PRIMARY KEY (`id`) 
  15. ) $collate; "; 
  16.  
  17. $wpdb->query($sql); 
  18.  
  19. public static function get_row($id, $where='', $output_type='OBJECT') { 
  20. global $wpdb; 
  21. $table_name = $wpdb->prefix. "woo_compare_categories"; 
  22. if (trim($where) != '') 
  23. $where = ' AND '.$where; 
  24. $result = $wpdb->get_row("SELECT * FROM {$table_name} WHERE id='$id' {$where}", $output_type); 
  25. return $result; 
  26.  
  27. public static function get_maximum_order($where='') { 
  28. global $wpdb; 
  29. $table_name = $wpdb->prefix . "woo_compare_categories"; 
  30. if (trim($where) != '') 
  31. $where = " WHERE {$where} "; 
  32. $maximum = $wpdb->get_var("SELECT MAX(category_order) FROM {$table_name} {$where}"); 
  33.  
  34. return $maximum; 
  35.  
  36. public static function get_count($where='') { 
  37. global $wpdb; 
  38. $table_name = $wpdb->prefix . "woo_compare_categories"; 
  39. if (trim($where) != '') 
  40. $where = " WHERE {$where} "; 
  41. $count = $wpdb->get_var("SELECT COUNT(id) FROM {$table_name} {$where}"); 
  42.  
  43. return $count; 
  44.  
  45. public static function get_results($where='', $order='', $limit ='', $output_type='OBJECT') { 
  46. global $wpdb; 
  47. $table_name = $wpdb->prefix . "woo_compare_categories"; 
  48. if (trim($where) != '') 
  49. $where = " WHERE {$where} "; 
  50. if (trim($order) != '') 
  51. $order = " ORDER BY {$order} "; 
  52. if (trim($limit) != '') 
  53. $limit = " LIMIT {$limit} "; 
  54. $result = $wpdb->get_results("SELECT * FROM {$table_name} {$where} {$order} {$limit}", $output_type); 
  55. return $result; 
  56.  
  57. public static function insert_row($args) { 
  58. global $wpdb; 
  59. extract($args); 
  60. $table_name = $wpdb->prefix. "woo_compare_categories"; 
  61. $category_name = strip_tags(addslashes($category_name)); 
  62. $category_order = WC_Compare_Categories_Data::get_maximum_order(); 
  63. $category_order++; 
  64. $query = $wpdb->query("INSERT INTO {$table_name}(category_name, category_order) VALUES('$category_name', '$category_order')"); 
  65. if ($query) { 
  66. $category_id = $wpdb->insert_id; 
  67. return $category_id; 
  68. }else { 
  69. return false; 
  70.  
  71. public static function update_row($args) { 
  72. global $wpdb; 
  73. extract($args); 
  74. $table_name = $wpdb->prefix. "woo_compare_categories"; 
  75. $category_name = strip_tags(addslashes($category_name)); 
  76.  
  77. $query = $wpdb->query("UPDATE {$table_name} SET category_name='$category_name' WHERE id='$category_id'"); 
  78. return $query; 
  79.  
  80.  
  81. public static function update_items_order($item_orders=array()) { 
  82. if (is_array($item_orders) && count($item_orders) > 0) { 
  83. foreach ($item_orders as $category_id => $category_order) { 
  84. WC_Compare_Categories_Data::update_order($category_id, $category_order); 
  85.  
  86. public static function update_order($category_id, $category_order=0) { 
  87. global $wpdb; 
  88. $table_name = $wpdb->prefix. "woo_compare_categories"; 
  89. $query = $wpdb->query("UPDATE {$table_name} SET category_order='$category_order' WHERE id='$category_id'"); 
  90. return $query; 
  91.  
  92. public static function delete_rows($items=array()) { 
  93. if (is_array($items) && count($items) > 0) { 
  94. foreach ($items as $category_id) { 
  95. WC_Compare_Categories_Data::delete_row($category_id); 
  96.  
  97. public static function delete_row($category_id) { 
  98. global $wpdb; 
  99. $table_name = $wpdb->prefix. "woo_compare_categories"; 
  100. $result = $wpdb->query("DELETE FROM {$table_name} WHERE id='{$category_id}'"); 
  101. return $result;