diff options
author | Arne Hamann <git@arne.email> | 2022-06-16 13:07:51 +0300 |
---|---|---|
committer | Arne Hamann <git@arne.email> | 2022-06-16 13:07:51 +0300 |
commit | 382d9c3e7eb976f7a9ce17106c22b5108bed657b (patch) | |
tree | 15023acd3384becb9e29b788e3cea8a63f704e0b /lib | |
parent | 693e7a34b15d93a82322ea18e12e634eb84a6bfc (diff) |
Added translation and typeDeclaration to ContactsController
Signed-off-by: Arne Hamann <git@arne.email>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/ContactsController.php | 195 |
1 files changed, 122 insertions, 73 deletions
diff --git a/lib/Controller/ContactsController.php b/lib/Controller/ContactsController.php index 715eba59..c2e5ea19 100644 --- a/lib/Controller/ContactsController.php +++ b/lib/Controller/ContactsController.php @@ -50,11 +50,13 @@ class ContactsController extends Controller { $this->cdBackend = $cdBackend; } - /** - * get contacts with coordinates - * @NoAdminRequired - */ - public function getContacts() { + /** + * get contacts with coordinates + * + * @NoAdminRequired + * @return DataResponse + */ + public function getContacts(): DataResponse { $contacts = $this->contactsManager->search('', ['GEO','ADR'], ['types'=>false]); $addressBooks = $this->contactsManager->getUserAddressBooks(); $result = []; @@ -70,21 +72,21 @@ class ContactsController extends Controller { if (key_exists('GEO', $c)) { $geo = $c['GEO']; if (strlen($geo) > 1) { - array_push($result, [ - 'FN' => $c['FN'] ?? $this->N2FN($c['N']) ?? '???', - 'URI' => $c['URI'], - 'UID' => $c['UID'], - 'ADR' => '', - 'ADRTYPE' => '', - 'HAS_PHOTO' => (isset($c['PHOTO']) && $c['PHOTO'] !== null), - 'BOOKID' => $c['addressbook-key'], - 'BOOKURI' => $addressBookUri, - 'GEO' => $geo, - 'GROUPS' => $c['CATEGORIES'] ?? null - ]); + $result[] = [ + 'FN' => $c['FN'] ?? $this->N2FN($c['N']) ?? '???', + 'URI' => $c['URI'], + 'UID' => $c['UID'], + 'ADR' => '', + 'ADRTYPE' => '', + 'HAS_PHOTO' => (isset($c['PHOTO']) && $c['PHOTO'] !== null), + 'BOOKID' => $c['addressbook-key'], + 'BOOKURI' => $addressBookUri, + 'GEO' => $geo, + 'GROUPS' => $c['CATEGORIES'] ?? null + ]; } elseif (count($geo)>0) { foreach ($geo as $g) { - array_push($result, [ + $result[] = [ 'FN' => $c['FN'] ?? $this->N2FN($c['N']) ?? '???', 'URI' => $c['URI'], 'UID' => $c['UID'], @@ -95,7 +97,7 @@ class ContactsController extends Controller { 'BOOKURI' => $addressBookUri, 'GEO' => $g, 'GROUPS' => $c['CATEGORIES'] ?? null - ]); + ]; } } } @@ -112,18 +114,18 @@ class ContactsController extends Controller { $adrtype = $adr->parameters()['TYPE']->getValue(); } if (strlen($geo) > 1) { - array_push($result, [ - 'FN' => $c['FN'] ?? $this->N2FN($c['N']) ?? '???', - 'URI' => $c['URI'], - 'UID' => $c['UID'], - 'ADR' => $adr->getValue(), - 'ADRTYPE' => $adrtype, - 'HAS_PHOTO' => (isset($c['PHOTO']) && $c['PHOTO'] !== null), - 'BOOKID' => $c['addressbook-key'], - 'BOOKURI' => $addressBookUri, - 'GEO' => $geo, - 'GROUPS' => $c['CATEGORIES'] ?? null, - ]); + $result[] = [ + 'FN' => $c['FN'] ?? $this->N2FN($c['N']) ?? '???', + 'URI' => $c['URI'], + 'UID' => $c['UID'], + 'ADR' => $adr->getValue(), + 'ADRTYPE' => $adrtype, + 'HAS_PHOTO' => (isset($c['PHOTO']) && $c['PHOTO'] !== null), + 'BOOKID' => $c['addressbook-key'], + 'BOOKURI' => $addressBookUri, + 'GEO' => $geo, + 'GROUPS' => $c['CATEGORIES'] ?? null, + ]; } } } @@ -133,7 +135,11 @@ class ContactsController extends Controller { return new DataResponse($result); } - private function N2FN(string $n) { + /** + * @param string $n + * @return string|null + */ + private function N2FN(string $n): ?string { if ($n) { $spl = explode($n, ';'); if (count($spl) >= 4) { @@ -148,10 +154,13 @@ class ContactsController extends Controller { } } - /** - * get all contacts - * @NoAdminRequired - */ + /** + * get all contacts + * + * @NoAdminRequired + * @param string $query + * @return DataResponse + */ public function searchContacts(string $query = ''): DataResponse { $contacts = $this->contactsManager->search($query, ['FN'], ['types'=>false]); $booksReadOnly = $this->getAddressBooksReadOnly(); @@ -165,25 +174,39 @@ class ContactsController extends Controller { strcmp($uid, $userid) !== 0 ) { $addressBookUri = $addressBooks[$c['addressbook-key']]->getUri(); - array_push($result, [ - 'FN' => $c['FN'] ?? $this->N2FN($c['N']) ?? '???', - 'URI' => $c['URI'], - 'UID' => $c['UID'], - 'BOOKID' => $c['addressbook-key'], - 'READONLY' => $booksReadOnly[$c['addressbook-key']], - 'BOOKURI' => $addressBookUri, - 'HAS_PHOTO' => (isset($c['PHOTO']) && $c['PHOTO'] !== null), - 'HAS_PHOTO2' => (isset($c['PHOTO']) && $c['PHOTO'] !== null && $c['PHOTO'] !== ''), - ]); + $result[] = [ + 'FN' => $c['FN'] ?? $this->N2FN($c['N']) ?? '???', + 'URI' => $c['URI'], + 'UID' => $c['UID'], + 'BOOKID' => $c['addressbook-key'], + 'READONLY' => $booksReadOnly[$c['addressbook-key']], + 'BOOKURI' => $addressBookUri, + 'HAS_PHOTO' => (isset($c['PHOTO']) && $c['PHOTO'] !== null), + 'HAS_PHOTO2' => (isset($c['PHOTO']) && $c['PHOTO'] !== null && $c['PHOTO'] !== ''), + ]; } } return new DataResponse($result); } - /** - * @NoAdminRequired - */ - public function placeContact($bookid, $uri, $uid, $lat, $lng, $attraction, $house_number, $road, $postcode, $city, $state, $country, $type) { + /** + * @NoAdminRequired + * @param $bookid + * @param $uri + * @param $uid + * @param $lat + * @param $lng + * @param $attraction + * @param $house_number + * @param $road + * @param $postcode + * @param $city + * @param $state + * @param $country + * @param $type + * @return DataResponse + */ + public function placeContact($bookid, $uri, $uid, $lat, $lng, $attraction, $house_number, $road, $postcode, $city, $state, $country, $type): DataResponse { // do not edit 'user' contact even myself if (strcmp($uri, 'Database:'.$uid.'.vcf') === 0 or strcmp($uid, $this->userId) === 0 @@ -228,17 +251,24 @@ class ContactsController extends Controller { } } - private function addressBookIsReadOnly($bookid) { + /** + * @param $bookId + * @return bool + */ + private function addressBookIsReadOnly($bookId): bool { $userBooks = $this->cdBackend->getAddressBooksForUser('principals/users/'.$this->userId); foreach ($userBooks as $book) { - if ($book['id'] === $bookid) { + if ($book['id'] === $bookId) { return (isset($book['{http://owncloud.org/ns}read-only']) and $book['{http://owncloud.org/ns}read-only']); } } return true; } - private function getAddressBooksReadOnly() { + /** + * @return array + */ + private function getAddressBooksReadOnly(): array { $booksReadOnly = []; $userBooks = $this->cdBackend->getAddressBooksForUser('principals/users/'.$this->userId); foreach ($userBooks as $book) { @@ -248,6 +278,14 @@ class ContactsController extends Controller { return $booksReadOnly; } + /** + * @param $lat + * @param $lng + * @param $adr + * @param $uri + * @return void + * @throws \OCP\DB\Exception + */ private function setAddressCoordinates($lat, $lng, $adr, $uri) { $qb = $this->qb; $adr_norm = strtolower(preg_replace('/\s+/', '', $adr)); @@ -269,8 +307,7 @@ class ContactsController extends Controller { ->set('looked_up', $qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL)) ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_STR))); $req = $qb->execute(); - $qb = $qb->resetQueryParts(); - } + } else { $qb->insert('maps_address_geo') ->values([ @@ -283,33 +320,45 @@ class ContactsController extends Controller { ]); $req = $qb->execute(); $id = $qb->getLastInsertId(); - $qb = $qb->resetQueryParts(); - } - } + } + $qb = $qb->resetQueryParts(); + } - /** - * get contacts with coordinates - * @NoAdminRequired - * @NoCSRFRequired - */ - public function getContactLetterAvatar($name) { + /** + * get contacts with coordinates + * + * @NoAdminRequired + * @NoCSRFRequired + * @param $name + * @return DataDisplayResponse + * @throws \OCP\Files\NotFoundException + * @throws \OCP\Files\NotPermittedException + */ + public function getContactLetterAvatar($name): DataDisplayResponse { $av = $this->avatarManager->getGuestAvatar($name); $avatarContent = $av->getFile(64)->getContent(); return new DataDisplayResponse($avatarContent); } - /** - * removes the address from the vcard - * and delete corresponding entry in the DB - * @NoAdminRequired - */ - public function deleteContactAddress($bookid, $uri, $uid, $adr, $geo) { + /** + * removes the address from the vcard + * and delete corresponding entry in the DB + * + * @NoAdminRequired + * @param $bookId + * @param $uri + * @param $uid + * @param $adr + * @param $geo + * @return DataResponse + */ + public function deleteContactAddress($bookId, $uri, $uid, $adr, $geo): DataResponse { // vcard - $card = $this->cdBackend->getContact($bookid, $uri); + $card = $this->cdBackend->getContact($bookId, $uri); if ($card) { $vcard = Reader::read($card['carddata']); //$bookId = $card['addressbookid']; - if (!$this->addressBookIsReadOnly($bookid)) { + if (!$this->addressBookIsReadOnly($bookId)) { foreach ($vcard->children() as $property) { if ($property->name === 'ADR') { $cardAdr = $property->getValue(); @@ -325,7 +374,7 @@ class ContactsController extends Controller { } } } - $this->cdBackend->updateCard($bookid, $uri, $vcard->serialize()); + $this->cdBackend->updateCard($bookId, $uri, $vcard->serialize()); // no need to cleanup db here, it will be done when catching vcard change hook return new DataResponse('DELETED'); } |