11
11
use OCP \AppFramework \Db \QBMapper ;
12
12
use OCP \DB \QueryBuilder \IQueryBuilder ;
13
13
use OCP \IDBConnection ;
14
- use OCP \IUser ;
15
- use OCP \Search \ISearchQuery ;
16
14
use OCP \Share \IShare ;
17
15
18
16
/**
@@ -99,9 +97,10 @@ public function findByHash(string $hash): Form {
99
97
* @param string[] $groups IDs of groups the user is memeber of
100
98
* @param string[] $teams IDs of teams the user is memeber of
101
99
* @param bool $filterShown Set to false to also include forms shared but not visible on sidebar
100
+ * @param string $queryTerm optional: The search query for universal search
102
101
* @return Form[]
103
102
*/
104
- public function findSharedForms (string $ userId , array $ groups = [], array $ teams = [], bool $ filterShown = true ): array {
103
+ public function findSharedForms (string $ userId , array $ groups = [], array $ teams = [], bool $ filterShown = true , ? string $ queryTerm = null ): array {
105
104
$ qbShares = $ this ->db ->getQueryBuilder ();
106
105
$ qbForms = $ this ->db ->getQueryBuilder ();
107
106
@@ -158,16 +157,28 @@ public function findSharedForms(string $userId, array $groups = [], array $teams
158
157
->addOrderBy ('last_updated ' , 'DESC ' )
159
158
->addOrderBy ('created ' , 'DESC ' );
160
159
160
+ if ($ queryTerm ) {
161
+ $ qbForms ->andWhere (
162
+ $ qbForms ->orWhere (
163
+ $ qbForms ->expr ()->like ('title ' , $ qbForms ->createNamedParameter ('% ' . $ queryTerm . '% ' ))
164
+ )
165
+ ->orWhere (
166
+ $ qbForms ->expr ()->like ('description ' , $ qbForms ->createNamedParameter ('% ' . $ queryTerm . '% ' ))
167
+ )
168
+ );
169
+ }
170
+
161
171
// We need to add the parameters from the shared forms IDs select to the final select query
162
172
$ qbForms ->setParameters ($ qbShares ->getParameters (), $ qbShares ->getParameterTypes ());
163
173
164
174
return $ this ->findEntities ($ qbForms );
165
175
}
166
176
167
177
/**
178
+ * @param string $queryTerm optional: The search query for universal search
168
179
* @return Form[]
169
180
*/
170
- public function findAllByOwnerId (string $ ownerId ): array {
181
+ public function findAllByOwnerId (string $ ownerId, ? string $ queryTerm = null ): array {
171
182
$ qb = $ this ->db ->getQueryBuilder ();
172
183
173
184
$ qb ->select ('* ' )
@@ -179,18 +190,17 @@ public function findAllByOwnerId(string $ownerId): array {
179
190
->addOrderBy ('last_updated ' , 'DESC ' )
180
191
->addOrderBy ('created ' , 'DESC ' );
181
192
182
- return $ this ->findEntities ($ qb );
183
- }
193
+ if ($ queryTerm ) {
194
+ $ qb ->andWhere (
195
+ $ qb ->orWhere (
196
+ $ qb ->expr ()->like ('title ' , $ qb ->createNamedParameter ('% ' . $ queryTerm . '% ' ))
197
+ )
198
+ ->orWhere (
199
+ $ qb ->expr ()->like ('description ' , $ qb ->createNamedParameter ('% ' . $ queryTerm . '% ' ))
200
+ )
201
+ );
202
+ }
184
203
185
- /**
186
- * @param IUser $user the user that performs the search
187
- * @param ISearchQuery $query the query to search the forms
188
- * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
189
- * @return Form[] array of Forms
190
- */
191
- public function search (IUser $ user , ISearchQuery $ query ): array {
192
- $ qb = $ this ->db ->getQueryBuilder ();
193
- // TODO: implement search for Query Builder
194
204
return $ this ->findEntities ($ qb );
195
205
}
196
206
0 commit comments