From: Steve Sutton Date: Sun, 10 Jul 2016 11:57:13 +0000 (-0400) Subject: WIP for the search form. X-Git-Tag: v1.0.0^2~32 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=9f68fa2d36a36e15987dd13b47ac187e6f857ecd;p=WP-Plugins%2Fglm-member-db-leads.git WIP for the search form. I have the search form searching for company and contact. Need to work on the Contact search to better match one of the words. Need to also include the interests into the search. I have the form holding the searched parameters. --- diff --git a/models/admin/leads/index.php b/models/admin/leads/index.php index fb6847d..8ccd66d 100644 --- a/models/admin/leads/index.php +++ b/models/admin/leads/index.php @@ -83,13 +83,48 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry public function modelAction($actionData = false) { + $search = filter_var( $_REQUEST['search'], FILTER_VALIDATE_BOOLEAN); if ( isset( $search ) && $search ) { - $leads = $this->getList(); + $search_params = filter_var_array( + $_POST, + array( + 'company' => FILTER_SANITIZE_STRING, + 'contact' => FILTER_SANITIZE_STRING, + 'from_date' => array( + 'filter' => FILTER_VALIDATE_REGEXP, + 'options' => array( + 'regexp' => '%([0-9]{2})/([0-9]{2})/([0-9]{4})%' + ) + ), + 'to_date' => array( + 'filter' => FILTER_VALIDATE_REGEXP, + 'options' => array( + 'regexp' => '%([0-9]{2})/([0-9]{2})/([0-9]{4})%' + ) + ), + 'interests' => array( + 'filter' => FILTER_VALIDATE_BOOLEAN, + 'flags' => FILTER_FORCE_ARRAY + ) + ) + ); + + // build the $where part + $where_parts = array(); + if ( $search_params['company'] ) { + $where_parts[] = "org = '" . esc_sql( $search_params['company'] ) . "'"; + } + if ( $search_params['contact'] ) { + $where_parts[] = "SOUNDEX(CONCAT_WS(' ', fname, lname)) = SOUNDEX( '" . esc_sql( $search_params['contact'] ) . "')"; + } + $where = implode( ' AND ', $where_parts ); + echo '
$where: ' . print_r( $where, true ) . '
'; + $order = "T.lname, T.fname"; + $leads = $this->getList( $where, $order ); } else { $leads = ''; } - $leads = $this->getList(); $groupData = new GlmDataInterestGroups( $this->wpdb, $this->config ); $groups = $groupData->getList(); @@ -98,17 +133,28 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry if ( $groups ) { foreach ( $groups as $group ) { - $intData = new GlmDataInterests( $this->wpdb, $this->config ); - $grouped_interests[$group['title']] = $intData->getList( - "group_id = " . $group['id'], - 'title' - ); + $intData = new GlmDataInterests( $this->wpdb, $this->config ); + $group_parts = explode( '_', $group['title'] ); + $group_parts = array_map( function($item){ return ucfirst( $item ); }, $group_parts ); + $group_title = implode( ' ', $group_parts ); + $grouped_interests[$group_title] = $intData->getList( "group_id = " . $group['id'], 'title' ); + } + if ( $grouped_interests ) { + foreach ( $grouped_interests as $group_name => &$interests ) { + foreach ( $interests as $key => &$interest ) { + $grouped_interests[$group_name][$key]['selected'] + = ( $search_params['interests'][$key] ) ? 1 : 0; + } + } } } - echo '
$grouped_interests: ' . print_r($grouped_interests, true) . '
'; + // Compile template data $templateData = array( - 'leads' => $leads, + 'search_params' => $search_params, + 'request' => print_r( $_REQUEST, true ), + 'leads' => $leads, + 'grouped_interests' => $grouped_interests, ); // Return status, any suggested view, and any data to controller diff --git a/setup/frontHooks.php b/setup/frontHooks.php index 3f73913..7cbecd2 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -172,6 +172,7 @@ add_action( 'gform_after_submission', function( $entry, $form ){ if ( !$lead_id ) { return; } + echo '
$glm_leads_entry: ' . print_r( $glm_leads_entry, true ) . '
'; // create the lead entry $lead_entry = $this->wpdb->insert( GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_entry', // table @@ -225,17 +226,12 @@ add_action( 'gform_after_submission', function( $entry, $form ){ $ints[$interest['id']] = $interest['title']; } } - //echo '
$interests: ' . print_r($interests, true) . '
'; - //echo '
$ints: ' . print_r($ints, true) . '
'; - //echo '
$leads_fields: ' . print_r($leads_fields, true) . '
'; // create the lead to interest entries // using $leads_fields // first delete any they current have - //echo '
$leads_fields: ' . print_r($leads_fields, true) . '
'; if ( is_array( $leads_fields) && !empty( $leads_fields ) ) { foreach ( $leads_fields as $interest_val ) { $int_key = array_search( $interest_val, $ints ); - //echo '
$int_key: ' . print_r($int_key, true) . '
'; if ( $int_key ) { $this->wpdb->insert( GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_interests', // table diff --git a/views/admin/leads/index.html b/views/admin/leads/index.html index c2148df..f2e5d42 100644 --- a/views/admin/leads/index.html +++ b/views/admin/leads/index.html @@ -1,11 +1,41 @@ {include file='admin/leads/header.html'} -
-
-
-
-
- + + + + + + + + + + + + + + + + + + + + + + + {foreach $grouped_interests as $group_name => $group} + + + + + {/foreach} + + + +
Date Range
From
To
{$group_name} + {foreach $group as $interest} + + {/foreach} +
{if $leads} @@ -24,4 +54,5 @@ {/foreach} {/if} + {include file='admin/footer.html'}