File tree Expand file tree Collapse file tree 2 files changed +20
-7
lines changed
Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Original file line number Diff line number Diff 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 )) {
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments