From db66a161950e8ca5ccd9671001739184340fb941 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 11 Oct 2018 15:01:22 -0400 Subject: [PATCH] Update the name search Properly concat the first and last names for searching. Commenting out and removing some code from members that was not needed. --- index.php | 6 +++--- models/front/staff/list.php | 38 ++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/index.php b/index.php index 3dca8fc..6b16f28 100644 --- 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 * @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. diff --git a/models/front/staff/list.php b/models/front/staff/list.php index f2d805c..f4870c3 100644 --- a/models/front/staff/list.php +++ b/models/front/staff/list.php @@ -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); -- 2.17.1