Update the name search
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 11 Oct 2018 19:01:22 +0000 (15:01 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 11 Oct 2018 19:01:22 +0000 (15:01 -0400)
Properly concat the first and last names for searching.
Commenting out and removing some code from members that was not needed.

index.php
models/front/staff/list.php

index 3dca8fc..6b16f28 100644 (file)
--- a/index.php
+++ b/index.php
@@ -3,7 +3,7 @@
  * Plugin Name: GLM Associate - Staff Add-on
  * Plugin URI: http://www.gaslightmedia.com/
  * Description: Staff directory
- * Version: 1.0.2
+ * Version: 1.0.3
  * Author: Gaslight Media
  * Author URI: http://www.gaslightmedia.com/
  * License: GPL2
@@ -19,7 +19,7 @@
  * @package glmMembersStaffAddOn
  * @author Chuck Scott <cscott@gaslightmedia.com>
  * @license http://www.gaslightmedia.com Gaslightmedia
- * @version 1.0.2
+ * @version 1.0.3
  */
 
 // Check that we're being called by WordPress.
@@ -43,7 +43,7 @@ if (!defined('ABSPATH')) {
  *  so that we're sure the other add-ons see an up to date
  *  version from this plugin.
  */
-define('GLM_MEMBERS_STAFF_PLUGIN_VERSION', '1.0.2');
+define('GLM_MEMBERS_STAFF_PLUGIN_VERSION', '1.0.3');
 define('GLM_MEMBERS_STAFF_PLUGIN_DB_VERSION', '0.0.1');
 
 // This is the minimum version of the GLM Members DB plugin require for this plugin.
index f2d805c..f4870c3 100644 (file)
@@ -159,21 +159,21 @@ class GlmMembersFront_staff_list extends GlmDatastaff
         }
 
         // Apply any provided text search to name, description, short description, and street address
-        if (trim($actionData['request']['text-search']) != '') {
-            $textSearch = addslashes(filter_var($actionData['request']['text-search'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES));
-            $where .= $whereSep." (
-                (
-                    SELECT true
-                      FROM ".GLM_MEMBERS_STAFF_PLUGIN_DB_PREFIX."staff
-                     WHERE id = T.id
-                       AND fname LIKE '%$textSearch%'
-                ) OR
-                T.lname LIKE '%$textSearch%' OR
-                T.department LIKE '%$textSearch%' OR
-                T.building LIKE '%$textSearch%'
-            )";
-            $textSearch = stripslashes($textSearch);
-        }
+        // if (trim($actionData['request']['text-search']) != '') {
+        //     $textSearch = addslashes(filter_var($actionData['request']['text-search'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES));
+        //     $where .= $whereSep." (
+        //         (
+        //             SELECT true
+        //               FROM ".GLM_MEMBERS_STAFF_PLUGIN_DB_PREFIX."staff
+        //              WHERE id = T.id
+        //                AND fname LIKE '%$textSearch%'
+        //         ) OR
+        //         T.lname LIKE '%$textSearch%' OR
+        //         T.department LIKE '%$textSearch%' OR
+        //         T.building LIKE '%$textSearch%'
+        //     )";
+        //     $textSearch = stripslashes($textSearch);
+        // }
 
 
         $Buildings = new GlmDataBuildings( $this->wpdb, $this->config );
@@ -184,7 +184,12 @@ class GlmMembersFront_staff_list extends GlmDatastaff
 
         if ( isset( $_REQUEST['filter_name'] ) && trim( $_REQUEST['filter_name'] ) != '' ) {
              $name_search = addslashes(filter_var($_REQUEST['filter_name'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES));
-             $where .= $whereSep." (T.fname like '%$name_search%' OR T.lname like '%$name_search%' OR (T.fname like '%$name_search%' AND T.lname like '%$name_search%')  )";
+             $where .= $whereSep." (
+                T.fname like '%$name_search%'
+                OR
+                T.lname like '%$name_search%'
+                OR (  CONCAT_WS( ' ', T.fname, T.lname) like '%$name_search%')
+                )";
         }
 
         if ( isset( $_REQUEST['filter_departments'] ) && $filter_departments = filter_var( $_REQUEST['filter_departments'], FILTER_VALIDATE_INT ) ) {
@@ -243,7 +248,6 @@ class GlmMembersFront_staff_list extends GlmDatastaff
         $filteredStaffFound = $this->getStats(str_replace('T.', '', $where.$alphaWhere));
 
 
-        $sortOrder = apply_filters( 'glm-member-db-front-search-query-orderby', 'lname' );
         $sortOrder = 'lname';
         ${$resultParam} = $this->getList($where.$alphaWhere, $sortOrder, true, 'id', $start, $limit);