Skip to content

Commit

Permalink
Merge pull request #232 from Chrisincr/handle-Þ-in-member-search
Browse files Browse the repository at this point in the history
Member search handles Þ in name branch and email
  • Loading branch information
jhandel authored Oct 16, 2024
2 parents 32cc54e + c0ea1b7 commit d217b9e
Showing 1 changed file with 42 additions and 7 deletions.
49 changes: 42 additions & 7 deletions app/src/Controller/MembersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,35 @@ public function index()
]);
// if there is a search term, filter the query
if ($search) {
//detect th and replace with Þ
$nsearch = $search;
if (preg_match("/th/", $search)) {
$nsearch = str_replace("th", "Þ", $search);
}
//detect Þ and replace with th
$usearch = $search;
if (preg_match("/Þ/", $search)) {
$usearch = str_replace("Þ", "th", $search);
}
$query = $query->where([
"OR" => [
"Members.sca_name LIKE" => "%" . $search . "%",
"Members.first_name LIKE" => "%" . $search . "%",
"Members.last_name LIKE" => "%" . $search . "%",
"Members.email_address LIKE" => "%" . $search . "%",
"Branches.name LIKE" => "%" . $search . "%",

["Members.membership_number LIKE" => "%" . $search . "%"],
["Members.sca_name LIKE" => "%" . $search . "%"],
["Members.sca_name LIKE" => "%" . $nsearch . "%"],
["Members.sca_name LIKE" => "%" . $usearch . "%"],
["Members.first_name LIKE" => "%" . $search . "%"],
["Members.last_name LIKE" => "%" . $search . "%"],
["Members.email_address LIKE" => "%" . $search . "%"],
["Branches.name LIKE" => "%" . $search . "%"],
["Members.first_name LIKE" => "%" . $nsearch . "%"],
["Members.last_name LIKE" => "%" . $nsearch . "%"],
["Members.email_address LIKE" => "%" . $nsearch . "%"],
["Branches.name LIKE" => "%" . $nsearch . "%"],
["Members.first_name LIKE" => "%" . $usearch . "%"],
["Members.last_name LIKE" => "%" . $usearch . "%"],
["Members.email_address LIKE" => "%" . $usearch . "%"],
["Branches.name LIKE" => "%" . $usearch . "%"],
],
]);
}
Expand Down Expand Up @@ -623,12 +645,25 @@ public function editAdditionalInfo($id = null)
public function searchMembers()
{
$q = $this->request->getQuery("q");
//detect th and replace with Þ
$nq = $q;
if (preg_match("/th/", $q)) {
$nq = str_replace("th", "Þ", $q);
}
//detect Þ and replace with th
$uq = $q;
if (preg_match("/Þ/", $q)) {
$uq = str_replace("Þ", "th", $q);
}
$this->Authorization->skipAuthorization();
$this->request->allowMethod(["get"]);
$this->viewBuilder()->setClassName("Ajax");
$query = $this->Members
->find("all")
->where(["sca_name LIKE" => "%$q%"])
->where([
'status <>' => Member::STATUS_DEACTIVATED,
'OR' => [["sca_name LIKE" => "%$q%"], ["sca_name LIKE" => "%$nq%"], ["sca_name LIKE" => "%$uq%"]]
])
->select(["id", "sca_name"])
->limit(10);
//$query = $this->Authorization->applyScope($query);
Expand Down Expand Up @@ -1259,4 +1294,4 @@ protected function _addRolesSelectAndContain(SelectQuery $q)
]);
}
#endregion
}
}

0 comments on commit d217b9e

Please sign in to comment.