Skip to content

Commit

Permalink
feat(search): allow contacts person search
Browse files Browse the repository at this point in the history
Signed-off-by: hamza221 <hamzamahjoubi221@gmail.com>
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
hamza221 authored and ChristophWurst committed Nov 14, 2023
1 parent 8b5d85a commit 19c21f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ public function searchPrincipalUri(string $principalUri,
* wildcard?: bool,
* since?: DateTimeFilter|null,
* until?: DateTimeFilter|null,
* person?: string
* } $options
* @return array
*/
Expand Down Expand Up @@ -1182,6 +1183,9 @@ private function searchByAddressBookIds(array $addressBookIds,
$query2->setFirstResult($options['offset']);
}

if (isset($options['person'])) {
$query2->andWhere($query2->expr()->ilike('cp.value', $query2->createNamedParameter('%' . $this->db->escapeLikeParameter($options['person']) . '%')));
}
if (isset($options['since']) || isset($options['until'])) {
$query2->join('cp', $this->dbCardsPropertiesTable, 'cp_bday', 'cp.cardid = cp_bday.cardid');
$query2->andWhere($query2->expr()->eq('cp_bday.name', $query2->createNamedParameter('BDAY')));
Expand Down
10 changes: 9 additions & 1 deletion apps/dav/lib/Search/ContactsSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
namespace OCA\DAV\Search;

use OC\Search\Filter\UserFilter;
use OCA\DAV\CardDAV\CardDavBackend;
use OCP\App\IAppManager;
use OCP\IL10N;
Expand Down Expand Up @@ -110,7 +111,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
'offset' => $query->getCursor(),
'since' => $query->getFilter('since'),
'until' => $query->getFilter('until'),
'person' => $query->getFilter('person'),
'person' => $this->getPersonDisplayName($query->getFilter('person')),
'company' => $query->getFilter('company'),
],
);
Expand All @@ -137,6 +138,13 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
$query->getCursor() + count($formattedResults)
);
}
private function getPersonDisplayName(?UserFilter $person): ?string{
$user = $person?->get();
if ($user instanceof IUser) {
return $user->getDisplayName();
}
return null;
}

protected function getDavUrlForContact(
string $principalUri,
Expand Down

0 comments on commit 19c21f2

Please sign in to comment.