Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordartcafe <github@dartcafe.de>2020-10-04 18:29:40 +0300
committerdartcafe <github@dartcafe.de>2020-10-04 18:29:40 +0300
commite7c85c8c53b8874364ece750e4cfe659c1e4fb32 (patch)
tree7c4558d81d4ccd9f55a480503077bdc7ee53bc68 /lib
parent3d280825d63e8469beefa6d89a6a3c265ec2a4af (diff)
polish
Diffstat (limited to 'lib')
-rw-r--r--lib/Model/Contact.php2
-rw-r--r--lib/Service/MailService.php89
-rw-r--r--lib/Service/ShareService.php29
3 files changed, 63 insertions, 57 deletions
diff --git a/lib/Model/Contact.php b/lib/Model/Contact.php
index ee5cd164..691ba4dc 100644
--- a/lib/Model/Contact.php
+++ b/lib/Model/Contact.php
@@ -183,7 +183,7 @@ class Contact implements \JsonSerializable, IUserObj {
$this->contact = $contacts[0];
$this->id = $this->contact['UID'];
} elseif (count($contacts) > 1) {
- throw new MultipleContactsFound('Multiple contacts found for id '. $this->id);
+ throw new MultipleContactsFound('Multiple contacts found for id ' . $this->id);
}
} else {
throw new ContactsNotEnabled();
diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php
index 4f1239f9..04fd63e3 100644
--- a/lib/Service/MailService.php
+++ b/lib/Service/MailService.php
@@ -202,49 +202,9 @@ class MailService {
)
);
- if ($share->getType() === Share::TYPE_USER) {
- $user = new User($share->getUserId());
- $recipients[] = [
- 'userId' => $user->getId(),
- 'eMailAddress' => $user->getEmailAddress(),
- 'displayName' => $user->getDisplayName(),
- 'language' => $user->getLanguage(),
- 'link' => $internalLink,
- ];
- } elseif ($share->getType() === Share::TYPE_EMAIL) {
- $user = new Email($share->getUserId());
-
- $recipients[] = [
- 'userId' => $user->getId(),
- 'eMailAddress' => $user->getEmailAddress(),
- 'displayName' => $user->getDisplayName(),
- 'language' => $defaultLang,
- 'link' => $tokenLink,
- ];
- } elseif ($share->getType() === Share::TYPE_CONTACT) {
- $user = new Contact($share->getUserId());
-
- $recipients[] = [
- 'userId' => $user->getId(),
- 'eMailAddress' => $user->getEmailAddress(),
- 'displayName' => $user->getDisplayname(),
- 'language' => $defaultLang,
- 'link' => $tokenLink,
- ];
- } elseif ($share->getType() === Share::TYPE_EXTERNAL) {
- $recipients[] = [
- 'userId' => $share->getUserId(),
- 'eMailAddress' => $share->getUserEmail(),
- 'displayName' => $share->getUserId(),
- 'language' => $defaultLang,
- 'link' => $tokenLink,
- ];
- } elseif ($share->getType() === Share::TYPE_GROUP) {
- foreach ((new Group($share->getUserId()))->getMembers() as $user) {
- if ($skipUser === $user->getId() || !$user->getUserIsDisabled()) {
- continue;
- }
-
+ switch ($share->getType()) {
+ case Share::TYPE_USER:
+ $user = new User($share->getUserId());
$recipients[] = [
'userId' => $user->getId(),
'eMailAddress' => $user->getEmailAddress(),
@@ -252,7 +212,48 @@ class MailService {
'language' => $user->getLanguage(),
'link' => $internalLink,
];
- }
+ case Share::TYPE_EMAIL:
+ $user = new Email($share->getUserId());
+
+ $recipients[] = [
+ 'userId' => $user->getId(),
+ 'eMailAddress' => $user->getEmailAddress(),
+ 'displayName' => $user->getDisplayName(),
+ 'language' => $defaultLang,
+ 'link' => $tokenLink,
+ ];
+ case Share::TYPE_CONTACT:
+ $user = new Contact($share->getUserId());
+
+ $recipients[] = [
+ 'userId' => $user->getId(),
+ 'eMailAddress' => $user->getEmailAddress(),
+ 'displayName' => $user->getDisplayname(),
+ 'language' => $defaultLang,
+ 'link' => $tokenLink,
+ ];
+ case Share::TYPE_EXTERNAL:
+ $recipients[] = [
+ 'userId' => $share->getUserId(),
+ 'eMailAddress' => $share->getUserEmail(),
+ 'displayName' => $share->getUserId(),
+ 'language' => $defaultLang,
+ 'link' => $tokenLink,
+ ];
+ case Share::TYPE_GROUP:
+ foreach ((new Group($share->getUserId()))->getMembers() as $user) {
+ if ($skipUser === $user->getId() || !$user->getUserIsDisabled()) {
+ continue;
+ }
+
+ $recipients[] = [
+ 'userId' => $user->getId(),
+ 'eMailAddress' => $user->getEmailAddress(),
+ 'displayName' => $user->getDisplayName(),
+ 'language' => $user->getLanguage(),
+ 'link' => $internalLink,
+ ];
+ }
}
return $recipients;
}
diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php
index a4e301e2..969ab310 100644
--- a/lib/Service/ShareService.php
+++ b/lib/Service/ShareService.php
@@ -114,23 +114,28 @@ class ShareService {
* @param array $user
* @return Share
* @throws NotAuthorizedException
+ * @throws InvalidShareType
*/
public function add($pollId, $type, $userId, $emailAddress = '') {
if (!$this->acl->set($pollId)->getAllowEdit()) {
throw new NotAuthorizedException;
}
- if ($type === Group::TYPE) {
- $share = new Group($userId);
- } elseif ($type === Circle::TYPE) {
- $share = new Circle($userId);
- } elseif ($type === Contact::TYPE) {
- $share = new Contact($userId);
- } elseif ($type === ContactGroup::TYPE) {
- $share = new ContactGroup($userId);
- } elseif ($type === User::TYPE) {
- $share = new User($userId);
- } elseif ($type === Email::TYPE) {
- $share = new Email($userId, $emailAddress);
+
+ switch ($type) {
+ case Group::TYPE:
+ $share = new Group($userId);
+ case Circle::TYPE:
+ $share = new Circle($userId);
+ case Contact::TYPE:
+ $share = new Contact($userId);
+ case ContactGroup::TYPE:
+ $share = new ContactGroup($userId);
+ case User::TYPE:
+ $share = new User($userId);
+ case Email::TYPE:
+ $share = new Email($userId, $emailAddress);
+ default:
+ throw new InvalidShareType('Invalid share type (' . $type . ')');
}
$this->share = new Share();