Skip to content

Commit

Permalink
support multiple qp as an OR query
Browse files Browse the repository at this point in the history
  • Loading branch information
killua-eu committed Jan 24, 2024
1 parent b95fb6a commit c1d10f4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions glued/Controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,25 @@ public function contacts_r1(Request $request, Response $response, array $args =
$wq = "";
$data = [];
$object = $args['uuid'] ?? false;
$q = $request->getQueryParams()['q'] ?? false;
if ($object) { $wq .= " AND c_uuid = uuid_to_bin(?, true)"; $data[] = $object; }
if ($q) { $wq .= " AND c_ft LIKE CONCAT('%',?,'%')"; $data[] = $q; }
foreach ($request->getQueryParams() as $qp) {
if (is_array($qp)) {
foreach ($qp as $item) {
$st[] = "c_ft LIKE CONCAT('%',?,'%')";
$data[] = $item;
}
} else {
$st[] = "c_ft LIKE CONCAT('%',?,'%')";
$data[] = $qp;
}
}
if (count($request->getQueryParams())>0) {
$wq .= " AND " . implode(" OR ", $st);
}

$q = "SELECT JSON_ARRAYAGG(JSON_INSERT(c_data, '$.uuid', bin_to_uuid(c_uuid, true))) AS data
FROM t_contacts_objects
WHERE 1=1 $wq
";
WHERE 1=1 $wq";

$result = $this->mysqli->execute_query($q, $data);
$obj = null;
Expand Down

0 comments on commit c1d10f4

Please sign in to comment.