From 63dd85bdf497bea20a34828fe5e9f5cb4baaa826 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 20 Jul 2016 16:45:21 -0400 Subject: [PATCH] WIP for gravity form lead import Working on the member lead import from gravity forms working out which fields to pull from the gravity leads. I have a form to set these up based on the field setup from gravity form. --- defines.php | 1 + models/admin/management/leads.php | 93 +++++++++++++++++++++++++++-- views/admin/management/leads.html | 99 ++++++++++++++++++++++++++++++- 3 files changed, 186 insertions(+), 7 deletions(-) diff --git a/defines.php b/defines.php index f0f79dd..afd677d 100644 --- a/defines.php +++ b/defines.php @@ -10,6 +10,7 @@ define('GLM_MEMBERS_LEADS_PLUGIN_NAME', 'Gaslight Media Members Database Leads'); define('GLM_MEMBERS_LEADS_PLUGIN_SHORT_NAME', 'Leads'); define('GLM_MEMBERS_LEADS_PLUGIN_SLUG', 'glm-member-db-leads'); +define('GLM_MEMBERS_LEADS_PLUGIN_IMPORT_OPTION', 'glm_member_db_leads_import_option'); // Database table prefixes - change if using add-on tables global $wpdb; diff --git a/models/admin/management/leads.php b/models/admin/management/leads.php index 0a67547..2675e96 100644 --- a/models/admin/management/leads.php +++ b/models/admin/management/leads.php @@ -115,6 +115,16 @@ class GlmMembersAdmin_management_leads // extends GlmDataLeadsManagement */ public function modelAction($actionData = false) { + $forms = false; + $form = false; + $result = false; + $sources = false; + $option2 = false; + $option = false; + $form_id = false; + $import_fields = false; + $importing = false; + // Grab data from the Sources table $sources = $this->wpdb->get_results( "SELECT * @@ -130,19 +140,92 @@ class GlmMembersAdmin_management_leads // extends GlmDataLeadsManagement $option2 = $_REQUEST['option2']; } - switch( $option ) { + if ( isset( $_REQUEST['form_id'] ) ) { + $form_id = filter_var( $_REQUEST['form_id'], FILTER_VALIDATE_INT ); + } + + if ( isset( $_REQUEST['importing'] ) ) { + $importing = filter_var( $_REQUEST['importing'], FILTER_VALIDATE_BOOLEAN ); + } + + + switch( $option2 ) { case 'import': - $result = '
$_REQUEST: ' . print_r($_REQUEST, true) . '
'; + if ( isset( $_REQUEST['form_id'] ) ) { + $form_id = filter_var( $_REQUEST['form_id'], FILTER_VALIDATE_INT ); + $result = '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + } + if ( $form_id ) { + $form = GFAPI::get_form( $form_id ); + $result = '
$form: ' . print_r( $form, true ) . '
'; + //$result = '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + } + if ( $importing ) { + /* + * If they import-fields are being posted then save as + * wordpress option. Using update_option here incase the option + * already exists. + */ + update_option( GLM_MEMBERS_LEADS_PLUGIN_IMPORT_OPTION, serialize( $_REQUEST['import_fields'] ) ); + + // try to get import fields options + $import_fields = unserialize( get_option( GLM_MEMBERS_LEADS_PLUGIN_IMPORT_OPTION, false ) ); + + // go through the $import_fields array and find all fields + // that are needed for the import + $import_fields = array_filter( $import_fields ); + + + $search_criteria = array( 'status' => 'active' ); + $sorting = array(); + $paging = array( 'offset' => 0, 'page_size' => 100 ); + $total_count = 0; + $entries = GFAPI::get_entries( $form_id, $search_criteria, $sorting, $paging, $total_count ); + $result = '
$import_fields: ' . print_r( $import_fields, true ) . '
'; + $result .= '

Total County: ' . $total_count . '

'; + $result .= '
$entries: ' . print_r( $entries, true ) . '
'; + if ( $entries ) { + foreach ( $entries as $entry ) { + $lead_entry = array( + 'fname' => '', + 'lname' => '', + 'org' => '', + 'addr1' => '', + 'addr2' => '', + 'city' => '', + 'state' => '', + 'zip' => '', + 'country' => '', + 'email' => '', + 'phone' => '', + 'phone2' => '', + 'fax' => '', + 'mail_ok' => '', + 'member_ok' => '' + ); + } + } + } else { + // try to get import fields options + $import_fields = unserialize( get_option( GLM_MEMBERS_LEADS_PLUGIN_IMPORT_OPTION, false ) ); + } break; + default: + $forms = GFAPI::get_forms(); + $result = '
$forms: ' . print_r( $forms, true ) . '
'; break; } // Compile template data $templateData = array( - 'sources' => $sources, - 'option2' => $option2, - 'result' => $result, + 'import_fields' => $import_fields, + 'importing' => $importing, + 'form' => $form, + 'forms' => $forms, + 'sources' => $sources, + 'option2' => $option2, + 'result' => $result, ); // Return status, suggested view, and data to controller diff --git a/views/admin/management/leads.html b/views/admin/management/leads.html index aae776c..c773042 100644 --- a/views/admin/management/leads.html +++ b/views/admin/management/leads.html @@ -7,7 +7,7 @@ Gravity Forms - +
@@ -22,16 +22,111 @@ {/foreach}
Form Id Source Name
+
+ + + + + + {if $forms} - + + {/if} + {if $form && !$importing} + + + + + + + {/if} + {if $import_fields} + {php} + echo '
' . print_r( $import_fields, true ) . '
'; + {/php} + {/if} {if $result} {/if}
Import Gravity Form + + + + + + + + {foreach $forms as $form_list} + + + + + + {/foreach} + +
Form IdTitleversion
{$form_list.id} {$form_list.title} {$form_list.version}
+
+ + + + + + + + + + + + {foreach $form.fields as $field} + + + + + + + + {/foreach} + +
Field IdTypeLabelImport Name 
{$field.id}{$field.type}{$field.label}{if !$fields.inputs.0.id}{else} {/if} + {if $field.inputs} + + + {foreach $field.inputs as $input} + {if !$input.isHidden} + + + + {/if} + {/foreach} + +
+
+ +
+ {/if} + {if $field.choices && $field.type == 'checkbox'} + + + + + + + + {foreach $field.choices as $choice} + + + + {/foreach} + +
Choices
{$choice.text}
+ {/if} +
+
{$result}
+