-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! feat: allow inviting contact groups
- Loading branch information
1 parent
87da5c2
commit f464833
Showing
5 changed files
with
226 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2014 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Calendar\Service; | ||
|
||
class ContactsService { | ||
|
||
|
||
public function isSystemBook(array $r): bool { | ||
// Information about system users is fetched via DAV nowadays | ||
return (isset($contact['isLocalSystemBook']) && $contact['isLocalSystemBook'] === true); | ||
Check failure on line 15 in lib/Service/ContactsService.php GitHub Actions / static-psalm-analysis dev-masterUndefinedVariable
|
||
} | ||
|
||
public function hasEmail(array $r): bool { | ||
return !isset($r['EMAIL']); | ||
} | ||
|
||
/** | ||
* Extract name from an array containing a contact's information | ||
* | ||
* @param array $r | ||
* @return string | ||
*/ | ||
public function getNameFromContact(array $r): string { | ||
return $r['FN'] ?? ''; | ||
} | ||
|
||
/** | ||
* Get photo uri from contact | ||
* | ||
* @param string $raw | ||
* @return string|null | ||
*/ | ||
public function getPhotoUri(array $r): ?string { | ||
if (!isset($r['PHOTO'])) { | ||
return null; | ||
} | ||
|
||
$raw = $r['PHOTO']; | ||
$uriPrefix = 'VALUE=uri:'; | ||
if (str_starts_with($raw, $uriPrefix)) { | ||
return substr($raw, strpos($raw, 'http')); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function getEmail(array $r): array { | ||
if (\is_string($r['EMAIL'])) { | ||
return [$r['EMAIL']]; | ||
} | ||
return $r['EMAIL']; | ||
} | ||
|
||
public function getTimezoneId(array $r): ?string { | ||
if (!isset($r['TZ'])) { | ||
return null; | ||
} | ||
|
||
if (\is_array($r['TZ'])) { | ||
return $r['TZ'][0]; | ||
} | ||
return $r['TZ']; | ||
} | ||
|
||
public function getLanguageId(array $r): ?string { | ||
if (!isset($r['LANG'])) { | ||
return null; | ||
} | ||
|
||
if (\is_array($r['LANG'])) { | ||
return $r['LANG'][0]; | ||
} | ||
return $r['LANG']; | ||
} | ||
|
||
public function filterGroupsWithCount(array $groups, string $search): array { | ||
//filter to be unique | ||
$categoryMem = []; | ||
foreach ($groups as $group) { | ||
$categoryNames = explode(',', $group['CATEGORIES']); | ||
$categoryMem[] = array_filter($categoryNames, static function ($cat) use ($search) { | ||
return str_contains(strtolower($cat), $search); | ||
}); | ||
} | ||
return array_count_values(array_merge(...$categoryMem)); | ||
} | ||
} |
Oops, something went wrong.