diff options
author | dartcafe <github@dartcafe.de> | 2020-12-28 14:27:48 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2020-12-28 14:27:48 +0300 |
commit | 7238356261e222114c13401600517cd5f5f35c02 (patch) | |
tree | b78350061076e37cab829c08857bdc68aa448289 /lib/Model | |
parent | a6b02781605896695d1dc9aaf3cf286e7ca21a50 (diff) |
code maintenance
Diffstat (limited to 'lib/Model')
-rw-r--r-- | lib/Model/Circle.php | 5 | ||||
-rw-r--r-- | lib/Model/Contact.php | 51 | ||||
-rw-r--r-- | lib/Model/ContactGroup.php | 39 | ||||
-rw-r--r-- | lib/Model/Group.php | 24 | ||||
-rw-r--r-- | lib/Model/User.php | 4 |
5 files changed, 65 insertions, 58 deletions
diff --git a/lib/Model/Circle.php b/lib/Model/Circle.php index 795fb017..e5b082f6 100644 --- a/lib/Model/Circle.php +++ b/lib/Model/Circle.php @@ -26,13 +26,14 @@ namespace OCA\Polls\Model; use OCP\App\IAppManager; use OCA\Circles\Api\v1\Circles; - +use \OCA\Circles\Model\Circle as CirclesCircle; use OCA\Polls\Exceptions\CirclesNotEnabledException; class Circle extends UserGroupClass { public const TYPE = 'circle'; public const ICON = 'icon-circles'; + /** @var CirclesCircle */ private $circle; public function __construct( @@ -59,7 +60,7 @@ class Circle extends UserGroupClass { public static function search(string $query = '', $skip = []): array { $circles = []; if (self::isEnabled()) { - foreach (Circles::listCircles(\OCA\Circles\Model\Circle::CIRCLES_ALL, $query) as $circle) { + foreach (Circles::listCircles(CirclesCircle::CIRCLES_ALL, $query) as $circle) { if (!in_array($circle->getUniqueId(), $skip)) { $circles[] = new self($circle->getUniqueId()); } diff --git a/lib/Model/Contact.php b/lib/Model/Contact.php index 031cf541..9a8ddd36 100644 --- a/lib/Model/Contact.php +++ b/lib/Model/Contact.php @@ -39,10 +39,15 @@ class Contact extends UserGroupClass { $id ) { parent::__construct($id, self::TYPE); - $this->icon = self::ICON; - $this->getContact(); + if (self::isEnabled()) { + $this->icon = self::ICON; + $this->getContact(); + } else { + throw new ContactsNotEnabledExceptions(); + } } + /** * * must use displayName for contact's user id, because contact id * * is not accessable outside the owners's scope @@ -82,36 +87,32 @@ class Contact extends UserGroupClass { } private function getContact(): void { - if (\OC::$server->getAppManager()->isEnabledForUser('contacts')) { - $this->resolveContactId(); - $this->loadContact(); + $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']) : []; + $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']); - } else { - $this->categories = []; - } + if (isset($this->contact['CATEGORIES'])) { + $this->categories = explode(',', $this->contact['CATEGORIES']); + } else { + $this->categories = []; + } - $description = $this->categories; + $description = $this->categories; - if (isset($this->contact['ORG'])) { - array_unshift($description, $this->organisation); - } + if (isset($this->contact['ORG'])) { + array_unshift($description, $this->organisation); + } - if (count($description) > 0) { - $this->description = implode(", ", $description); - } else { - $this->description = \OC::$server->getL10N('polls')->t('Contact'); - } + if (count($description) > 0) { + $this->description = implode(", ", $description); } else { - throw new ContactsNotEnabledExceptions(); + $this->description = \OC::$server->getL10N('polls')->t('Contact'); } } diff --git a/lib/Model/ContactGroup.php b/lib/Model/ContactGroup.php index f8923ef4..ac04a8fc 100644 --- a/lib/Model/ContactGroup.php +++ b/lib/Model/ContactGroup.php @@ -35,8 +35,12 @@ class ContactGroup extends UserGroupClass { $id ) { parent::__construct($id, self::TYPE); - $this->icon = self::ICON; - $this->description = \OC::$server->getL10N('polls')->t('Contact group'); + if (self::isEnabled()) { + $this->icon = self::ICON; + $this->description = \OC::$server->getL10N('polls')->t('Contact group'); + } else { + throw new ContactsNotEnabledExceptions(); + } } /** @@ -49,6 +53,22 @@ class ContactGroup extends UserGroupClass { return $this->displayName; } + /** + * Get a list of contacts group members + * @return Contact[] + */ + public function getMembers() { + $contacts = []; + + foreach (self::getContainer()->query(IContactsManager::class)->search($this->id, ['CATEGORIES']) as $contact) { + if (array_key_exists('EMAIL', $contact)) { + $contacts[] = new Contact($contact['UID']); + } + } + + return $contacts; + } + public static function isEnabled(): bool { return self::getContainer()->query(IAppManager::class)->isEnabledForUser('contacts'); } @@ -77,19 +97,4 @@ class ContactGroup extends UserGroupClass { return $contactGroups; } - /** - * Get a list of contacts group members - * @return Contact[] - */ - public function getMembers() { - $contacts = []; - if (self::isEnabled()->isEnabled()) { - foreach (self::getContainer()->query(IContactsManager::class)->search($this->id, ['CATEGORIES']) as $contact) { - if (array_key_exists('EMAIL', $contact)) { - $contacts[] = new Contact($contact['UID']); - } - } - } - return $contacts; - } } diff --git a/lib/Model/Group.php b/lib/Model/Group.php index 83796477..6fb35a20 100644 --- a/lib/Model/Group.php +++ b/lib/Model/Group.php @@ -51,6 +51,18 @@ class Group extends UserGroupClass { } /** + * @return User[] + */ + public function getMembers(): array { + $members = []; + + foreach (array_keys(self::getContainer()->query(IGroupManager::class)->displayNamesInGroup($this->id)) as $member) { + $members[] = new User($member); + } + return $members; + } + + /** * @return Group[] * * @psalm-return list<Group> @@ -65,16 +77,4 @@ class Group extends UserGroupClass { } return $groups; } - - /** - * @return User[] - */ - public function getMembers(): array { - $members = []; - - foreach (array_keys(self::getContainer()->query(IGroupManager::class)->displayNamesInGroup($this->id)) as $member) { - $members[] = new User($member); - } - return $members; - } } diff --git a/lib/Model/User.php b/lib/Model/User.php index 8df96e5b..e7806dab 100644 --- a/lib/Model/User.php +++ b/lib/Model/User.php @@ -25,13 +25,13 @@ namespace OCA\Polls\Model; use OCP\IUserManager; -use OCP\Collaboration\Collaborators\ISearch; -use OCP\Share\IShare; +use OCP\IUser; class User extends UserGroupClass { public const TYPE = 'user'; public const ICON = 'icon-user'; + /** @var IUser */ private $user; public function __construct( |