WC_Compare_Data

WooCommerce Compare Fields Data.

Defined (1)

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

/classes/data/class-wc-compare-data.php  
  1. class WC_Compare_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.  
  9. $table_woo_compare_fields = $wpdb->prefix. "woo_compare_fields"; 
  10. if ($wpdb->get_var("SHOW TABLES LIKE '$table_woo_compare_fields'") != $table_woo_compare_fields) { 
  11. $sql = "CREATE TABLE IF NOT EXISTS `{$table_woo_compare_fields}` ( 
  12. `id` int(11) NOT NULL auto_increment,  
  13. `field_name` blob NOT NULL,  
  14. `field_key` varchar(250) NOT NULL,  
  15. `field_type` varchar(250) NOT NULL,  
  16. `default_value` blob NOT NULL,  
  17. `field_unit` blob NOT NULL,  
  18. `field_description` blob NOT NULL,  
  19. `field_order` int(11) NOT NULL,  
  20. PRIMARY KEY (`id`) 
  21. ) $collate; "; 
  22.  
  23. $wpdb->query($sql); 
  24.  
  25.  
  26. public static function get_row($id, $where='', $output_type='OBJECT') { 
  27. global $wpdb; 
  28. $table_name = $wpdb->prefix. "woo_compare_fields"; 
  29. if (trim($where) != '') 
  30. $where = ' AND '.$where; 
  31. $result = $wpdb->get_row("SELECT * FROM {$table_name} WHERE id='$id' {$where}", $output_type); 
  32. return $result; 
  33.  
  34. public static function get_maximum_order($where='') { 
  35. global $wpdb; 
  36. $table_name = $wpdb->prefix . "woo_compare_fields"; 
  37. if (trim($where) != '') 
  38. $where = " WHERE {$where} "; 
  39. $maximum = $wpdb->get_var("SELECT MAX(field_order) FROM {$table_name} {$where}"); 
  40.  
  41. return $maximum; 
  42.  
  43. public static function get_count($where='') { 
  44. global $wpdb; 
  45. $table_name = $wpdb->prefix . "woo_compare_fields"; 
  46. if (trim($where) != '') 
  47. $where = " WHERE {$where} "; 
  48. $count = $wpdb->get_var("SELECT COUNT(id) FROM {$table_name} {$where}"); 
  49.  
  50. return $count; 
  51.  
  52. public static function get_results($where='', $order='', $limit ='', $output_type='OBJECT') { 
  53. global $wpdb; 
  54. $table_name = $wpdb->prefix . "woo_compare_fields"; 
  55. if (trim($where) != '') 
  56. $where = " WHERE {$where} "; 
  57. if (trim($order) != '') 
  58. $order = " ORDER BY {$order} "; 
  59. if (trim($limit) != '') 
  60. $limit = " LIMIT {$limit} "; 
  61. $result = $wpdb->get_results("SELECT * FROM {$table_name} {$where} {$order} {$limit}", $output_type); 
  62. return $result; 
  63.  
  64. public static function insert_row($args) { 
  65. global $wpdb; 
  66. extract($args); 
  67. $table_name = $wpdb->prefix. "woo_compare_fields"; 
  68. $field_name = strip_tags(addslashes($field_name)); 
  69. $default_value = strip_tags(addslashes($default_value)); 
  70. $field_unit = strip_tags(addslashes($field_unit), '<sup>'); 
  71. $field_description = ''; 
  72. $field_order = WC_Compare_Data::get_maximum_order(); 
  73. $field_order++; 
  74. $field_key = ''; 
  75. if (trim($field_key) == '') { 
  76. $query = $wpdb->query("INSERT INTO {$table_name}(field_name, field_key, field_type, default_value, field_unit, field_description, field_order) VALUES('$field_name', '', '$field_type', '$default_value', '$field_unit', '$field_description', '$field_order')"); 
  77. if ($query) { 
  78. $field_id = $wpdb->insert_id; 
  79. $field_key = 'field-'.$field_id; 
  80. WC_Compare_Data::update_field_key($field_id, $field_key); 
  81. return $field_id; 
  82. }else { 
  83. return false; 
  84. }else { 
  85. if (WC_Compare_Data::check_field_key($field_key)) { 
  86. $query = $wpdb->query("INSERT INTO {$table_name}(field_name, field_key, field_type, default_value, field_unit, field_description, field_order) VALUES('$field_name', '$field_key', '$field_type', '$default_value', '$field_unit', '$field_description', '$field_order')"); 
  87. if ($query) { 
  88. $field_id = $wpdb->insert_id; 
  89. return $field_id; 
  90. }else { 
  91. return false; 
  92. }else { 
  93. return false; 
  94.  
  95. public static function update_row($args) { 
  96. global $wpdb; 
  97. extract($args); 
  98. $table_name = $wpdb->prefix. "woo_compare_fields"; 
  99. $field_name = strip_tags(addslashes($field_name)); 
  100. $default_value = strip_tags(addslashes($default_value)); 
  101. $field_unit = strip_tags(addslashes($field_unit), '<sup>'); 
  102. $field_description = ''; 
  103. $query = $wpdb->query("UPDATE {$table_name} SET field_name='$field_name', field_type='$field_type', default_value='$default_value', field_unit='$field_unit', field_description='$field_description' WHERE id='$field_id'"); 
  104. return $query; 
  105.  
  106.  
  107. public static function update_field_key($field_id, $field_key) { 
  108. global $wpdb; 
  109. $table_name = $wpdb->prefix. "woo_compare_fields"; 
  110. $query = $wpdb->query("UPDATE {$table_name} SET field_key='$field_key' WHERE id='$field_id'"); 
  111. return $query; 
  112.  
  113. public static function update_items_order($item_orders=array()) { 
  114. if (is_array($item_orders) && count($item_orders) > 0) { 
  115. foreach ($item_orders as $field_id => $field_order) { 
  116. WC_Compare_Data::update_order($field_id, $field_order); 
  117.  
  118. public static function update_order($field_id, $field_order=0) { 
  119. global $wpdb; 
  120. $table_name = $wpdb->prefix. "woo_compare_fields"; 
  121. $query = $wpdb->query("UPDATE {$table_name} SET field_order='$field_order' WHERE id='$field_id'"); 
  122. return $query; 
  123.  
  124. public static function delete_rows($items=array()) { 
  125. if (is_array($items) && count($items) > 0) { 
  126. foreach ($items as $field_id) { 
  127. WC_Compare_Data::delete_row($field_id); 
  128.  
  129. public static function delete_row($field_id) { 
  130. global $wpdb; 
  131. $table_name = $wpdb->prefix. "woo_compare_fields"; 
  132. $result = $wpdb->query("DELETE FROM {$table_name} WHERE id='{$field_id}'"); 
  133. return $result; 
  134.  
  135. public static function check_field_key($field_key) { 
  136. $count = WC_Compare_Data::get_count("field_key='$field_key'"); 
  137. if ($count > 0) return false; 
  138. else return true; 
  139.  
  140. public static function check_field_key_for_update($field_id, $field_key) { 
  141. $count = WC_Compare_Data::get_count("id!='$field_id' AND field_key='$field_key'"); 
  142. if ($count > 0) return false; 
  143. else return true;