WC_Compare_Categories_Fields_Data

WooCommerce Compare Categories Fields Data.

Defined (1)

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

/classes/data/class-wc-compare-categories-fields-data.php  
  1. class WC_Compare_Categories_Fields_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_fields = $wpdb->prefix. "woo_compare_cat_fields"; 
  9. if ($wpdb->get_var("SHOW TABLES LIKE '$table_compare_categories_fields'") != $table_compare_categories_fields) { 
  10. $sql = "CREATE TABLE IF NOT EXISTS `{$table_compare_categories_fields}` ( 
  11. `cat_id` int(11) NOT NULL,  
  12. `field_id` int(11) NOT NULL,  
  13. `field_order` int(11) NOT NULL 
  14. ) $collate;"; 
  15.  
  16. $wpdb->query($sql); 
  17.  
  18. public static function get_row($cat_id, $field_id, $output_type='OBJECT') { 
  19. global $wpdb; 
  20. $table_name = $wpdb->prefix. "woo_compare_cat_fields"; 
  21. $result = $wpdb->get_row("SELECT * FROM {$table_name} WHERE cat_id='$cat_id' AND field_id='$field_id' ", $output_type); 
  22. return $result; 
  23.  
  24. public static function get_count($where='') { 
  25. global $wpdb; 
  26. $table_name = $wpdb->prefix . "woo_compare_cat_fields"; 
  27. if (trim($where) != '') 
  28. $where = " WHERE {$where} "; 
  29. $count = $wpdb->get_var("SELECT COUNT(*) FROM {$table_name} {$where}"); 
  30.  
  31. return $count; 
  32.  
  33. public static function get_results($where='', $order='', $limit ='', $output_type='OBJECT') { 
  34. global $wpdb; 
  35. $table_name = $wpdb->prefix . "woo_compare_cat_fields"; 
  36. $table_fields = $wpdb->prefix. "woo_compare_fields"; 
  37. if (trim($where) != '') 
  38. $where = " WHERE {$where} "; 
  39. if (trim($order) != '') 
  40. $order = " ORDER BY {$order} "; 
  41. if (trim($limit) != '') 
  42. $limit = " LIMIT {$limit} "; 
  43.  
  44. $result = $wpdb->get_results("SELECT * FROM {$table_name} AS cf INNER JOIN {$table_fields} AS f ON(cf.field_id=f.id) {$where} GROUP BY field_id {$order} {$limit}", $output_type); 
  45. return $result; 
  46.  
  47. public static function get_unavaliable_field_results($order='', $limit ='', $output_type='OBJECT') { 
  48. global $wpdb; 
  49. $table_name = $wpdb->prefix . "woo_compare_cat_fields"; 
  50. $table_fields = $wpdb->prefix. "woo_compare_fields"; 
  51. if (trim($order) != '') 
  52. $order = " ORDER BY {$order} "; 
  53. if (trim($limit) != '') 
  54. $limit = " LIMIT {$limit} "; 
  55.  
  56. $result = $wpdb->get_results("SELECT f.* FROM {$table_fields} AS f WHERE f.id NOT IN(SELECT DISTINCT cf.field_id FROM {$table_name} AS cf WHERE cf.cat_id > 0) {$order} {$limit}", $output_type); 
  57. return $result; 
  58.  
  59. public static function get_maximum_order($where='') { 
  60. global $wpdb; 
  61. $table_name = $wpdb->prefix . "woo_compare_cat_fields"; 
  62. if (trim($where) != '') 
  63. $where = " WHERE {$where} "; 
  64. $maximum = $wpdb->get_var("SELECT MAX(field_order) FROM {$table_name} {$where}"); 
  65.  
  66. return $maximum; 
  67.  
  68. public static function update_items_order($cat_id=0, $item_orders=array()) { 
  69. if (is_array($item_orders) && count($item_orders) > 0) { 
  70. foreach ($item_orders as $field_id => $field_order) { 
  71. WC_Compare_Categories_Fields_Data::update_order($cat_id, $field_id, $field_order); 
  72.  
  73. public static function update_order($cat_id, $field_id, $field_order=0) { 
  74. global $wpdb; 
  75. $table_name = $wpdb->prefix. "woo_compare_cat_fields"; 
  76. $query = $wpdb->query("UPDATE {$table_name} SET field_order='$field_order' WHERE field_id='$field_id' AND cat_id='$cat_id'"); 
  77. return $query; 
  78.  
  79. public static function get_catid_results($field_id, $where='', $order='', $limit ='') { 
  80. global $wpdb; 
  81. $table_name = $wpdb->prefix . "woo_compare_cat_fields"; 
  82. $table_fields = $wpdb->prefix. "woo_compare_fields"; 
  83. if (trim($where) != '') 
  84. $where = ' AND '.$where; 
  85. if (trim($order) != '') 
  86. $order = " ORDER BY {$order} "; 
  87. if (trim($limit) != '') 
  88. $limit = " LIMIT {$limit} "; 
  89. $result = $wpdb->get_col("SELECT DISTINCT cf.cat_id FROM {$table_name} AS cf INNER JOIN {$table_fields} AS f ON(cf.field_id=f.id) WHERE field_id='$field_id' {$where} {$order} {$limit}"); 
  90. return $result; 
  91.  
  92. public static function get_fieldid_results($cat_id, $where='', $order='', $limit ='') { 
  93. global $wpdb; 
  94. $table_name = $wpdb->prefix . "woo_compare_cat_fields"; 
  95. $table_fields = $wpdb->prefix. "woo_compare_fields"; 
  96. if (trim($where) != '') 
  97. $where = ' AND '.$where; 
  98. if (trim($order) != '') 
  99. $order = " ORDER BY {$order} "; 
  100. if (trim($limit) != '') 
  101. $limit = " LIMIT {$limit} "; 
  102. $result = $wpdb->get_col("SELECT DISTINCT cf.field_id FROM {$table_name} AS cf INNER JOIN {$table_fields} AS f ON(cf.field_id=f.id) WHERE cat_id='$cat_id' {$where} {$order} {$limit}"); 
  103. return $result; 
  104.  
  105. public static function insert_row($cat_id, $field_id) { 
  106. global $wpdb; 
  107. $table_name = $wpdb->prefix. "woo_compare_cat_fields"; 
  108. $field_order = WC_Compare_Categories_Fields_Data::get_maximum_order("cat_id='".$cat_id."'"); 
  109. $field_order++; 
  110. $query = $wpdb->query("INSERT INTO {$table_name}(cat_id, field_id, field_order) VALUES('$cat_id', '$field_id', '$field_order')"); 
  111. if ($query) { 
  112. return true; 
  113. }else { 
  114. return false; 
  115.  
  116. public static function delete_row($where) { 
  117. global $wpdb; 
  118. $table_name = $wpdb->prefix. "woo_compare_cat_fields"; 
  119. $result = $wpdb->query("DELETE FROM {$table_name} WHERE {$where}"); 
  120. return $result;