GFExactTargetData

The Gravity Forms ExactTarget Add-On GFExactTargetData class.

Defined (2)

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

/data.php  
  1. class GFExactTargetData{ 
  2.  
  3. public static function update_table() { 
  4. global $wpdb; 
  5. $table_name = self::get_exacttarget_table_name(); 
  6.  
  7. if ( ! empty($wpdb->charset) ) 
  8. $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; 
  9. if ( ! empty($wpdb->collate) ) 
  10. $charset_collate .= " COLLATE $wpdb->collate"; 
  11.  
  12. $sql = "CREATE TABLE $table_name ( 
  13. id mediumint(8) unsigned not null auto_increment,  
  14. form_id mediumint(8) unsigned not null,  
  15. is_active tinyint(1) not null default 1,  
  16. meta longtext,  
  17. PRIMARY KEY (id),  
  18. KEY form_id (form_id) 
  19. )$charset_collate;"; 
  20.  
  21. require_once(ABSPATH . '/wp-admin/includes/upgrade.php'); 
  22. dbDelta($sql); 
  23.  
  24. public static function get_exacttarget_table_name() { 
  25. global $wpdb; 
  26. return $wpdb->prefix . "rg_exacttarget"; 
  27.  
  28. public static function get_feeds() { 
  29. global $wpdb; 
  30. $table_name = self::get_exacttarget_table_name(); 
  31. $form_table_name = RGFormsModel::get_form_table_name(); 
  32. $sql = "SELECT s.id, s.is_active, s.form_id, s.meta, f.title as form_title 
  33. FROM $table_name s 
  34. INNER JOIN $form_table_name f ON s.form_id = f.id"; 
  35.  
  36. $results = $wpdb->get_results($sql, ARRAY_A); 
  37.  
  38. $count = sizeof($results); 
  39. for($i=0; $i<$count; $i++) { 
  40. $results[$i]["meta"] = maybe_unserialize($results[$i]["meta"]); 
  41.  
  42. return $results; 
  43.  
  44. public static function delete_feed($id) { 
  45. global $wpdb; 
  46. $table_name = self::get_exacttarget_table_name(); 
  47. $wpdb->query($wpdb->prepare("DELETE FROM $table_name WHERE id=%s", $id)); 
  48.  
  49. public static function get_feed_by_form($form_id, $only_active = false) { 
  50. global $wpdb; 
  51. $table_name = self::get_exacttarget_table_name(); 
  52. $active_clause = $only_active ? " AND is_active=1" : ""; 
  53. $sql = $wpdb->prepare("SELECT id, form_id, is_active, meta FROM $table_name WHERE form_id=%d $active_clause", $form_id); 
  54. $results = $wpdb->get_results($sql, ARRAY_A); 
  55. if(empty($results)) 
  56. return array(); 
  57.  
  58. //Deserializing meta 
  59. $count = sizeof($results); 
  60. for($i=0; $i<$count; $i++) { 
  61. $results[$i]["meta"] = maybe_unserialize($results[$i]["meta"]); 
  62. return $results; 
  63.  
  64. public static function get_feed($id) { 
  65. global $wpdb; 
  66. $table_name = self::get_exacttarget_table_name(); 
  67. $sql = $wpdb->prepare("SELECT id, form_id, is_active, meta FROM $table_name WHERE id=%d", $id); 
  68. $results = $wpdb->get_results($sql, ARRAY_A); 
  69. if(empty($results)) 
  70. return array(); 
  71.  
  72. $result = $results[0]; 
  73. $result["meta"] = maybe_unserialize($result["meta"]); 
  74. return $result; 
  75.  
  76. public static function update_feed($id, $form_id, $is_active, $setting) { 
  77. global $wpdb; 
  78. $table_name = self::get_exacttarget_table_name(); 
  79. $setting = maybe_serialize($setting); 
  80. if($id == 0) { 
  81. //insert 
  82. $wpdb->insert($table_name, array("form_id" => $form_id, "is_active"=> $is_active, "meta" => $setting), array("%d", "%d", "%s")); 
  83. $id = $wpdb->get_var("SELECT LAST_INSERT_ID()"); 
  84. else{ 
  85. //update 
  86. $wpdb->update($table_name, array("form_id" => $form_id, "is_active"=> $is_active, "meta" => $setting), array("id" => $id), array("%d", "%d", "%s"), array("%d")); 
  87.  
  88. return $id; 
  89.  
  90. public static function drop_tables() { 
  91. global $wpdb; 
  92. $wpdb->query("DROP TABLE IF EXISTS " . self::get_exacttarget_table_name()); 
  1. class GFExactTargetData{ 
  2.  
  3. public static function update_table() { 
  4. global $wpdb; 
  5. $table_name = self::get_exacttarget_table_name(); 
  6.  
  7. if ( ! empty($wpdb->charset) ) 
  8. $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; 
  9. if ( ! empty($wpdb->collate) ) 
  10. $charset_collate .= " COLLATE $wpdb->collate"; 
  11.  
  12. $sql = "CREATE TABLE $table_name ( 
  13. id mediumint(8) unsigned not null auto_increment,  
  14. form_id mediumint(8) unsigned not null,  
  15. is_active tinyint(1) not null default 1,  
  16. meta longtext,  
  17. PRIMARY KEY (id),  
  18. KEY form_id (form_id) 
  19. )$charset_collate;"; 
  20.  
  21. require_once(ABSPATH . '/wp-admin/includes/upgrade.php'); 
  22. dbDelta($sql); 
  23.  
  24. public static function get_exacttarget_table_name() { 
  25. global $wpdb; 
  26. return $wpdb->prefix . "rg_exacttarget"; 
  27.  
  28. public static function get_feeds() { 
  29. global $wpdb; 
  30. $table_name = self::get_exacttarget_table_name(); 
  31. $form_table_name = RGFormsModel::get_form_table_name(); 
  32. $sql = "SELECT s.id, s.is_active, s.form_id, s.meta, f.title as form_title 
  33. FROM $table_name s 
  34. INNER JOIN $form_table_name f ON s.form_id = f.id"; 
  35.  
  36. $results = $wpdb->get_results($sql, ARRAY_A); 
  37.  
  38. $count = sizeof($results); 
  39. for($i=0; $i<$count; $i++) { 
  40. $results[$i]["meta"] = maybe_unserialize($results[$i]["meta"]); 
  41.  
  42. return $results; 
  43.  
  44. public static function delete_feed($id) { 
  45. global $wpdb; 
  46. $table_name = self::get_exacttarget_table_name(); 
  47. $wpdb->query($wpdb->prepare("DELETE FROM $table_name WHERE id=%s", $id)); 
  48.  
  49. public static function get_feed_by_form($form_id, $only_active = false) { 
  50. global $wpdb; 
  51. $table_name = self::get_exacttarget_table_name(); 
  52. $active_clause = $only_active ? " AND is_active=1" : ""; 
  53. $sql = $wpdb->prepare("SELECT id, form_id, is_active, meta FROM $table_name WHERE form_id=%d $active_clause", $form_id); 
  54. $results = $wpdb->get_results($sql, ARRAY_A); 
  55. if(empty($results)) 
  56. return array(); 
  57.  
  58. //Deserializing meta 
  59. $count = sizeof($results); 
  60. for($i=0; $i<$count; $i++) { 
  61. $results[$i]["meta"] = maybe_unserialize($results[$i]["meta"]); 
  62. return $results; 
  63.  
  64. public static function get_feed($id) { 
  65. global $wpdb; 
  66. $table_name = self::get_exacttarget_table_name(); 
  67. $sql = $wpdb->prepare("SELECT id, form_id, is_active, meta FROM $table_name WHERE id=%d", $id); 
  68. $results = $wpdb->get_results($sql, ARRAY_A); 
  69. if(empty($results)) 
  70. return array(); 
  71.  
  72. $result = $results[0]; 
  73. $result["meta"] = maybe_unserialize($result["meta"]); 
  74. return $result; 
  75.  
  76. public static function update_feed($id, $form_id, $is_active, $setting) { 
  77. global $wpdb; 
  78. $table_name = self::get_exacttarget_table_name(); 
  79. $setting = maybe_serialize($setting); 
  80. if($id == 0) { 
  81. //insert 
  82. $wpdb->insert($table_name, array("form_id" => $form_id, "is_active"=> $is_active, "meta" => $setting), array("%d", "%d", "%s")); 
  83. $id = $wpdb->get_var("SELECT LAST_INSERT_ID()"); 
  84. else{ 
  85. //update 
  86. $wpdb->update($table_name, array("form_id" => $form_id, "is_active"=> $is_active, "meta" => $setting), array("id" => $id), array("%d", "%d", "%s"), array("%d")); 
  87.  
  88. return $id; 
  89.  
  90. public static function drop_tables() { 
  91. global $wpdb; 
  92. $wpdb->query("DROP TABLE IF EXISTS " . self::get_exacttarget_table_name());