Skip to content

Commit d8263f7

Browse files
committed
feat: unified search
Signed-off-by: Crisciany Souza <crisciany.souza@librecode.coop>
1 parent 0fb96c0 commit d8263f7

File tree

2 files changed

+26
-36
lines changed

2 files changed

+26
-36
lines changed

lib/Db/SignRequestMapper.php

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -416,19 +416,20 @@ public function getFilesAssociatedFilesWithMeFormatted(
416416
return $return;
417417
}
418418

419-
public function getFilesToSearchProvider(IUser $user, string $term, int $limit, int $offset): array {
419+
public function getFilesToSearchProvider(IUser $user, string $fileName, int $limit, int $offset): array {
420420
$filter = [
421421
'page' => ($offset / $limit) + 1,
422422
'length' => $limit,
423+
'fileName' => $fileName,
423424
];
424425

425-
$qb = $this->getFilesAssociatedFilesWithMeQueryBuilder($user->getUID(), $filter);
426+
$sort = [
427+
'sortBy' => 'created_at',
428+
'sortDirection' => 'desc',
429+
];
430+
431+
$qb = $this->getFilesAssociatedFilesWithMeQueryBuilder($user->getUID(), $filter, false, $sort);
426432

427-
if (!empty($term)) {
428-
$qb->andWhere(
429-
$qb->expr()->like('f.name', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($term) . '%'))
430-
);
431-
}
432433

433434
$qb->orderBy('f.created_at', 'DESC');
434435

@@ -437,16 +438,7 @@ public function getFilesToSearchProvider(IUser $user, string $term, int $limit,
437438

438439
while ($row = $result->fetch()) {
439440
try {
440-
$file = new File();
441-
$file->setId((int)$row['id']);
442-
$file->setUserId($row['user_id']);
443-
$file->setNodeId((int)($row['node_id'] ?? 0));
444-
$file->setSignedNodeId($row['signed_node_id'] ? (int)$row['signed_node_id'] : null);
445-
$file->setName($row['name'] ?? '');
446-
$file->setStatus((int)($row['status'] ?? 0));
447-
$file->setUuid($row['uuid'] ?? '');
448-
$file->setCreatedAt($row['created_at'] ?? '');
449-
441+
$file = File::fromRow($row);
450442

451443
$files[] = $file;
452444
} catch (\Exception $e) {
@@ -530,7 +522,7 @@ public function getMyLibresignFile(string $userId, ?array $filter = []): File {
530522
return $file->fromRow($row);
531523
}
532524

533-
private function getFilesAssociatedFilesWithMeQueryBuilder(string $userId, array $filter = [], bool $count = false): IQueryBuilder {
525+
private function getFilesAssociatedFilesWithMeQueryBuilder(string $userId, array $filter = [], bool $count = false, array $sort = []): IQueryBuilder {
534526
$qb = $this->db->getQueryBuilder();
535527
$qb->from('libresign_file', 'f')
536528
->leftJoin('f', 'libresign_sign_request', 'sr', 'sr.file_id = f.id')
@@ -623,17 +615,14 @@ private function getFilesAssociatedFilesWithMeQueryBuilder(string $userId, array
623615
$qb->expr()->lte('f.created_at', $qb->createNamedParameter($end, IQueryBuilder::PARAM_STR))
624616
);
625617
}
618+
if (!empty($filter['fileName'])) {
619+
$qb->andWhere(
620+
$qb->expr()->like('f.name', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($filter['fileName']) . '%'))
621+
);
622+
}
626623
}
627-
return $qb;
628-
}
629624

630-
private function getFilesAssociatedFilesWithMeStmt(
631-
string $userId,
632-
?array $filter = [],
633-
?array $sort = [],
634-
): Pagination {
635-
$qb = $this->getFilesAssociatedFilesWithMeQueryBuilder($userId, $filter);
636-
if (!empty($sort['sortBy'])) {
625+
if (!empty($sort['sortBy']) && !empty($sort['sortDirection'])) {
637626
switch ($sort['sortBy']) {
638627
case 'name':
639628
case 'status':
@@ -650,6 +639,16 @@ private function getFilesAssociatedFilesWithMeStmt(
650639
}
651640
}
652641

642+
return $qb;
643+
}
644+
645+
private function getFilesAssociatedFilesWithMeStmt(
646+
string $userId,
647+
?array $filter = [],
648+
?array $sort = [],
649+
): Pagination {
650+
$qb = $this->getFilesAssociatedFilesWithMeQueryBuilder($userId, $filter, false, $sort);
651+
653652
$countQb = $this->getFilesAssociatedFilesWithMeQueryBuilder(
654653
userId: $userId,
655654
filter: $filter,

lib/Search/FileSearchProvider.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use OCP\App\IAppManager;
1616
use OCP\Files\IMimeTypeDetector;
1717
use OCP\Files\IRootFolder;
18-
use OCP\IDBConnection;
1918
use OCP\IL10N;
2019
use OCP\IURLGenerator;
2120
use OCP\IUser;
@@ -30,7 +29,6 @@ public function __construct(
3029
private IURLGenerator $urlGenerator,
3130
private IRootFolder $rootFolder,
3231
private IAppManager $appManager,
33-
private IDBConnection $db,
3432
private IMimeTypeDetector $mimeTypeDetector,
3533
private SignRequestMapper $fileMapper,
3634
) {
@@ -81,13 +79,6 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
8179
);
8280
}
8381

84-
/**
85-
* Format a File entity as a SearchResultEntry
86-
*
87-
* @param File $file The file entity to format
88-
* @param IUser $user Current user
89-
* @return SearchResultEntry Formatted search result entry
90-
*/
9182
private function formatResult(File $file, IUser $user): SearchResultEntry {
9283
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
9384
$thumbnailUrl = '';

0 commit comments

Comments
 (0)