Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed client search and enabled fuzzy search
  • Loading branch information
Harm Akkerman committed Jul 26, 2022
commit 063c5a177402cf2e1f8c6b87158c7ffbc8cbb81e
15 changes: 11 additions & 4 deletions lib/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ public function index() {

}

/**
* @NoAdminRequired
*/
public function addCost($id)
{
$wi = $this->workIntervalMapper->find($id);
Expand Down Expand Up @@ -561,12 +564,16 @@ public function deleteClient($id) {
* @NoCSRFRequired
*/
public function getClients(){
$clients = $this->clientMapper->findAll($this->userId);
return new JSONResponse(["Clients" => json_decode(json_encode($clients), true)]);
}

$clientName = $this->request->term ?? null;

if ($clientName) {
$clients = $this->clientMapper->searchByName($this->userId, $clientName);
} else {
$clients = $this->clientMapper->findAll($this->userId);
}

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

/**
*
Expand Down
13 changes: 8 additions & 5 deletions lib/Db/ClientMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public function __construct(IDBConnection $db) {
public function findByName($name) {
$sql = 'SELECT * FROM `*PREFIX*timetracker_client` ' .
'WHERE upper(`name`) = ?';

try {
$e = $this->findEntity($sql, [strtoupper($name)]);
return $e;
} catch (\OCP\AppFramework\Db\DoesNotExistException $e){
return null;
}

}

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


public function findAll($user){
$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';
return $this->findEntities($sql, [$user]);
}


}
public function searchByName($user, $name){
$name = strtoupper($name);
$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';
return $this->findEntities($sql, [$user, "%" . $name . "%"]);
}
}
6 changes: 1 addition & 5 deletions lib/Db/ProjectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function searchByName($user, string $name) {
$name = strtoupper($name);
$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`';

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

/**
Expand Down Expand Up @@ -75,8 +75,4 @@ public function delete($project_id) {
}

}




}