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/Model
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Model')
-rw-r--r--lib/Model/Contact.php92
-rw-r--r--lib/Model/ContactGroup.php36
-rw-r--r--lib/Model/Email.php19
-rw-r--r--lib/Model/GenericUser.php55
-rw-r--r--lib/Model/UserGroupClass.php37
5 files changed, 178 insertions, 61 deletions
diff --git a/lib/Model/Contact.php b/lib/Model/Contact.php
index 478515f2..3d0187f9 100644
--- a/lib/Model/Contact.php
+++ b/lib/Model/Contact.php
@@ -31,42 +31,76 @@ class Contact extends UserGroupClass {
public const ICON = 'icon-mail';
/** @var Array */
- private $contact;
+ private $contact =[];
/**
- * User constructor.
+ * Contact constructor.
* @param $id
* @param $displayName
*/
public function __construct(
- $id,
- $displayName = ''
+ $id
) {
- parent::__construct($id, self::TYPE, $displayName);
+ parent::__construct($id, self::TYPE);
$this->icon = self::ICON;
+ $this->getContact();
+ }
+ /**
+ * isEnabled
+ * @NoAdminRequired
+ * @return Boolean
+ */
+ public static function isEnabled() {
+ return \OC::$server->getAppManager()->isEnabledForUser('contacts');
+ }
+
+ /**
+ * resolveContact
+ * We just need the contact's UID, so make sure, the any prefix is removed
+ * @NoAdminRequired
+ */
+ private function resolveContactId() {
+ $parts = explode(":", $this->id);
+ $this->id = end($parts);
+ }
+
+ /**
+ * loadContact
+ * @NoAdminRequired
+ * The contacts app just provides a search, so we have to load the contact
+ * after searching via the contact's id and use the first contact.
+ *
+ * Currently only the contact's first email address is supported
+ *
+ * From Version 1.5 on:
+ * For compatibility reasons, we have to search for the contacts name too.
+ * Before this implementation contacts where stored with their FN property.
+ *
+ * TODO: Remove FN as search range for loading a contact in a polls version
+ * later than 1.6.
+ */
+ private function loadContact() {
+ $contacts = self::listRaw($this->id, ['UID', 'FN']);
+
+ if (count($contacts) > 1) {
+ throw new MultipleContactsFound('Multiple contacts found for id ' . $this->id);
+ }
+
+ $this->contact = $contacts[0];
+ }
+
+ private function getContact() {
if (\OC::$server->getAppManager()->isEnabledForUser('contacts')) {
- $this->contact = [];
-
- $parts = explode(":", $this->id);
- $this->id = end($parts);
-
- // Search for UID and FN
- // Before this implementation contacts where stored with their FN property
- // From now on, the contact's UID is used as identifier
- // TODO: Remove FN as search range for loading a contact in a polls version later than 1.6
- $contacts = \OC::$server->getContactsManager()->search($this->id, ['UID', 'FN']);
-
- if (count($contacts) === 1) {
- $this->contact = $contacts[0];
- $this->id = $this->contact['UID'];
- $this->displayName = isset($this->contact['FN']) ? $this->contact['FN'] : $this->displayName;
- $this->emailAddress = isset($this->contact['EMAIL'][0]) ? $this->contact['EMAIL'][0] : $this->emailAddress;
- } elseif (count($contacts) > 1) {
- throw new MultipleContactsFound('Multiple contacts found for id ' . $this->id);
- }
+ $this->resolveContactId();
+ $this->loadContact();
+ $this->id = $this->contact['UID'];
+ $this->displayName = isset($this->contact['FN']) ? $this->contact['FN'] : $this->displayName;
+ $this->emailAddress = isset($this->contact['EMAIL'][0]) ? $this->contact['EMAIL'][0] : $this->emailAddress;
$this->organisation = isset($this->contact['ORG']) ? $this->contact['ORG'] : '';
+ $this->categories = isset($this->contact['CATEGORIES']) ? explode(',', $this->contact['CATEGORIES']) : [];
+
if (isset($this->contact['CATEGORIES'])) {
$this->categories = explode(',', $this->contact['CATEGORIES']);
@@ -88,20 +122,14 @@ class Contact extends UserGroupClass {
} else {
throw new ContactsNotEnabled();
}
- }
- /**
- * isEnabled
- * @NoAdminRequired
- * @return Boolean
- */
- public static function isEnabled() {
- return \OC::$server->getAppManager()->isEnabledForUser('contacts');
}
/**
* listRaw
* @NoAdminRequired
+ * List all contacts with email adresses
+ * excluding contacts from localSystemBook
* @param string $query
* @return Array
*/
diff --git a/lib/Model/ContactGroup.php b/lib/Model/ContactGroup.php
index a72fea2e..a3cf26e1 100644
--- a/lib/Model/ContactGroup.php
+++ b/lib/Model/ContactGroup.php
@@ -31,18 +31,28 @@ class ContactGroup extends UserGroupClass {
/**
* Group constructor.
* @param $id
- * @param $displayName
*/
public function __construct(
- $id,
- $displayName = ''
+ $id
) {
- parent::__construct($id, self::TYPE, $id);
+ parent::__construct($id, self::TYPE);
$this->icon = self::ICON;
$this->description = \OC::$server->getL10N('polls')->t('Contact group');
}
/**
+ * getDisplayName
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getDisplayName() {
+ if (!$this->displayName) {
+ return $this->id;
+ }
+ return $this->displayName;
+ }
+
+ /**
* listRaw
* @NoAdminRequired
* @param string $query
@@ -99,22 +109,4 @@ class ContactGroup extends UserGroupClass {
return [];
}
-
- /**
- * @return array
- */
- public function jsonSerialize(): array {
- return [
- 'id' => $this->id,
- 'user' => $this->id,
- 'type' => $this->getType(),
- 'displayName' => $this->getDisplayName(),
- 'organisation' => $this->getOrganisation(),
- 'emailAddress' => $this->getEmailAddress(),
- 'desc' => $this->getDescription(),
- 'icon' => $this->getIcon(),
- 'isNoUser' => true,
- 'isGuest' => true,
- ];
- }
}
diff --git a/lib/Model/Email.php b/lib/Model/Email.php
index f05a82f5..08184d0c 100644
--- a/lib/Model/Email.php
+++ b/lib/Model/Email.php
@@ -34,12 +34,25 @@ class Email extends UserGroupClass {
* @param $displayName
*/
public function __construct(
- $id,
- $displayName = ''
+ $id
) {
- parent::__construct($id, self::TYPE, $displayName);
+ parent::__construct($id, self::TYPE);
$this->description = \OC::$server->getL10N('polls')->t('External Email');
$this->icon = self::ICON;
$this->emailAddress = $id;
}
+
+ /**
+ * getDisplayName
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getDisplayName() {
+ if (!$this->displayName) {
+ return $this->id;
+ }
+ return $this->displayName;
+ }
+
+
}
diff --git a/lib/Model/GenericUser.php b/lib/Model/GenericUser.php
new file mode 100644
index 00000000..18820452
--- /dev/null
+++ b/lib/Model/GenericUser.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ *
+ * @author René Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OCA\Polls\Model;
+
+class GenericUser extends UserGroupClass {
+ public const TYPE = 'external';
+ public const ICON_DEFAULT = 'icon-share';
+ public const ICON_PUBLIC = 'icon-public';
+
+ /**
+ * Email constructor.
+ * @param $id
+ * @param $displayName
+ */
+ public function __construct(
+ $id,
+ $type = self::TYPE,
+ $displayName = '',
+ $emailAddress = ''
+ ) {
+ parent::__construct($id, $type);
+ $this->displayName = $displayName;
+ $this->emailAddress = $emailAddress;
+
+ if ($type === UserGroupClass::TYPE_PUBLIC) {
+ $this->icon = self::ICON_PUBLIC;
+ $this->description = \OC::$server->getL10N('polls')->t('Public link');
+ } else {
+ $this->description = \OC::$server->getL10N('polls')->t('External user');
+ $this->icon = self::ICON_DEFAULT;
+ }
+ }
+}
diff --git a/lib/Model/UserGroupClass.php b/lib/Model/UserGroupClass.php
index 3855c973..5ccc280b 100644
--- a/lib/Model/UserGroupClass.php
+++ b/lib/Model/UserGroupClass.php
@@ -123,10 +123,7 @@ class UserGroupClass implements \JsonSerializable {
* @return String
*/
public function getDisplayName() {
- if ($this->displayName) {
- return $this->displayName;
- }
- return $this->id;
+ return $this->displayName;
}
/**
@@ -258,6 +255,37 @@ class UserGroupClass implements \JsonSerializable {
return [];
}
+ public static function getUserGroupChild($type, $id, $displayName = '', $emailAddress = '') {
+ switch ($type) {
+ case Group::TYPE:
+ return new Group($id);
+ break;
+ case Circle::TYPE:
+ return new Circle($id);
+ break;
+ case Contact::TYPE:
+ return new Contact($id);
+ break;
+ case ContactGroup::TYPE:
+ return new ContactGroup($id);
+ break;
+ case User::TYPE:
+ return new User($id);
+ break;
+ case Email::TYPE:
+ return new Email($id);
+ break;
+ case self::TYPE_PUBLIC:
+ return new GenericUser($id,self::TYPE_PUBLIC);
+ break;
+ case self::TYPE_EXTERNAL:
+ return new GenericUser($id, self::TYPE_EXTERNAL, $displayName, $emailAddress);
+ break;
+ default:
+ throw new InvalidShareType('Invalid share type (' . $type . ')');
+ }
+ }
+
/**
* @return array
*/
@@ -265,6 +293,7 @@ class UserGroupClass implements \JsonSerializable {
return [
'id' => $this->getId(),
'user' => $this->getId(),
+ 'userId' => $this->getId(),
'type' => $this->getType(),
'displayName' => $this->getDisplayName(),
'organisation' => $this->getOrganisation(),