Skip to content

Commit 5d436f0

Browse files
authored
Merge pull request mtierltd#1 from Hawiak/fix/163_fix-project-search
Implemented searchByName method to be used when searching for a proje…
2 parents be5d3ed + 6de6233 commit 5d436f0

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

lib/Controller/AjaxController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,13 @@ public function deleteProjectWithData($id) {
720720
* @NoAdminRequired
721721
*/
722722
public function getProjects(){
723-
$projects = $this->projectMapper->findAll($this->userId);
723+
$projectName = $this->request->term ?? null;
724+
725+
if ($projectName) {
726+
$projects = $this->projectMapper->searchByName($this->userId, $projectName);
727+
} else {
728+
$projects = $this->projectMapper->findAll($this->userId);
729+
}
724730
$parray = json_decode(json_encode($projects), true);
725731
foreach($parray as $pi => $pv){
726732
if (isset($pv->id)) {

lib/Db/ProjectMapper.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@ public function __construct(IDBConnection $db) {
1616
public function findByName($name) {
1717
$sql = 'SELECT * FROM `*PREFIX*timetracker_project` ' .
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+
27+
}
28+
29+
public function searchByName($user, string $name) {
30+
$name = strtoupper($name);
31+
$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`';
32+
33+
return $this->findEntities($sql, [$user, $name ."%"]);
2734
}
2835

2936
/**
@@ -59,17 +66,17 @@ public function findAllAdmin($getArchived = 0){
5966
public function delete($project_id) {
6067
$sql = 'delete FROM `*PREFIX*timetracker_project` ' .
6168
' where id = ?';
62-
69+
6370
try {
6471
$this->execute($sql, [$project_id]);
6572
return;
6673
} catch (\OCP\AppFramework\Db\DoesNotExistException $e){
6774
return;
6875
}
69-
76+
7077
}
7178

7279

7380

74-
75-
}
81+
82+
}

0 commit comments

Comments
 (0)