Skip to content

Commit 063c5a1

Browse files
author
Harm Akkerman
committed
Fixed client search and enabled fuzzy search
1 parent 283fe8d commit 063c5a1

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

lib/Controller/AjaxController.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ public function index() {
152152

153153
}
154154

155+
/**
156+
* @NoAdminRequired
157+
*/
155158
public function addCost($id)
156159
{
157160
$wi = $this->workIntervalMapper->find($id);
@@ -561,12 +564,16 @@ public function deleteClient($id) {
561564
* @NoCSRFRequired
562565
*/
563566
public function getClients(){
564-
$clients = $this->clientMapper->findAll($this->userId);
565-
return new JSONResponse(["Clients" => json_decode(json_encode($clients), true)]);
566-
}
567-
567+
$clientName = $this->request->term ?? null;
568568

569+
if ($clientName) {
570+
$clients = $this->clientMapper->searchByName($this->userId, $clientName);
571+
} else {
572+
$clients = $this->clientMapper->findAll($this->userId);
573+
}
569574

575+
return new JSONResponse(["Clients" => json_decode(json_encode($clients), true)]);
576+
}
570577

571578
/**
572579
*

lib/Db/ClientMapper.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ public function __construct(IDBConnection $db) {
1616
public function findByName($name) {
1717
$sql = 'SELECT * FROM `*PREFIX*timetracker_client` ' .
1818
'WHERE upper(`name`) = ?';
19-
19+
2020
try {
2121
$e = $this->findEntity($sql, [strtoupper($name)]);
2222
return $e;
2323
} catch (\OCP\AppFramework\Db\DoesNotExistException $e){
2424
return null;
2525
}
26-
26+
2727
}
2828

2929
/**
@@ -36,11 +36,14 @@ public function find($id) {
3636
return $this->findEntity($sql, [$id]);
3737
}
3838

39-
4039
public function findAll($user){
4140
$sql = 'SELECT tc.* FROM `*PREFIX*timetracker_client` tc left join `*PREFIX*timetracker_user_to_client` uc on uc.client_id = tc.id where uc.user_uid = ? order by tc.name asc';
4241
return $this->findEntities($sql, [$user]);
4342
}
4443

45-
46-
}
44+
public function searchByName($user, $name){
45+
$name = strtoupper($name);
46+
$sql = 'SELECT tc.* FROM `*PREFIX*timetracker_client` tc left join `*PREFIX*timetracker_user_to_client` uc on uc.client_id = tc.id where uc.user_uid = ? and upper(tc.name) LIKE ? order by tc.name asc';
47+
return $this->findEntities($sql, [$user, "%" . $name . "%"]);
48+
}
49+
}

lib/Db/ProjectMapper.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function searchByName($user, string $name) {
3030
$name = strtoupper($name);
3131
$sql = 'SELECT tp.* FROM `*PREFIX*timetracker_project` tp LEFT JOIN `*PREFIX*timetracker_user_to_project` up ON up.project_id = tp.id WHERE up.`user_uid` = ? AND upper(tp.`name`) LIKE ? ORDER BY tp.`name`';
3232

33-
return $this->findEntities($sql, [$user, $name ."%"]);
33+
return $this->findEntities($sql, [$user,"%" . $name ."%"]);
3434
}
3535

3636
/**
@@ -75,8 +75,4 @@ public function delete($project_id) {
7575
}
7676

7777
}
78-
79-
80-
81-
8278
}

0 commit comments

Comments
 (0)