Skip to content

Commit

Permalink
Merge pull request mtierltd#1 from Hawiak/fix/163_fix-project-search
Browse files Browse the repository at this point in the history
Implemented searchByName method to be used when searching for a proje…
  • Loading branch information
Hawiak authored Jun 14, 2022
2 parents be5d3ed + 6de6233 commit 5d436f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
8 changes: 7 additions & 1 deletion lib/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,13 @@ public function deleteProjectWithData($id) {
* @NoAdminRequired
*/
public function getProjects(){
$projects = $this->projectMapper->findAll($this->userId);
$projectName = $this->request->term ?? null;

if ($projectName) {
$projects = $this->projectMapper->searchByName($this->userId, $projectName);
} else {
$projects = $this->projectMapper->findAll($this->userId);
}
$parray = json_decode(json_encode($projects), true);
foreach($parray as $pi => $pv){
if (isset($pv->id)) {
Expand Down
19 changes: 13 additions & 6 deletions lib/Db/ProjectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ public function __construct(IDBConnection $db) {
public function findByName($name) {
$sql = 'SELECT * FROM `*PREFIX*timetracker_project` ' .
'WHERE upper(`name`) = ?';

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


}

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 ."%"]);
}

/**
Expand Down Expand Up @@ -59,17 +66,17 @@ public function findAllAdmin($getArchived = 0){
public function delete($project_id) {
$sql = 'delete FROM `*PREFIX*timetracker_project` ' .
' where id = ?';

try {
$this->execute($sql, [$project_id]);
return;
} catch (\OCP\AppFramework\Db\DoesNotExistException $e){
return;
}

}



}

}

0 comments on commit 5d436f0

Please sign in to comment.