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
diff options
context:
space:
mode:
authordartcafe <github@dartcafe.de>2021-11-13 14:38:57 +0300
committerdartcafe <github@dartcafe.de>2021-11-26 11:23:42 +0300
commit0f6fc28619a6b05eff888f10a83134e8ff912772 (patch)
treedeaef596cdebe55235998148862c2bdd8f075722 /lib/Service/ShareService.php
parent6e28c2b57ed45723a37c235f7388ba1068029687 (diff)
Sort shares by type
Signed-off-by: dartcafe <github@dartcafe.de>
Diffstat (limited to 'lib/Service/ShareService.php')
-rw-r--r--lib/Service/ShareService.php23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php
index 4fdbffa9..a5891cc5 100644
--- a/lib/Service/ShareService.php
+++ b/lib/Service/ShareService.php
@@ -71,6 +71,9 @@ class ShareService {
/** @var Share */
private $share;
+ /** @var array */
+ private $shares = [];
+
/** @var MailService */
private $mailService;
@@ -118,23 +121,34 @@ class ShareService {
public function list(int $pollId): array {
try {
$this->acl->setPollId($pollId, Acl::PERMISSION_POLL_EDIT);
- $shares = $this->shareMapper->findByPoll($pollId);
+ $this->shares = $this->shareMapper->findByPoll($pollId);
} catch (NotAuthorizedException $e) {
return [];
} catch (DoesNotExistException $e) {
return [];
}
+ $this->sortByCategory();
+ return $this->shares;
+ }
- return $shares;
+ private function sortByCategory() : void {
+ $sortedShares = [];
+ foreach (Share::TYPE_SORT_ARRAY as $shareType) {
+ $filteredShares = array_filter($this->shares, function($share) use ($shareType) {
+ return $share->getType() === $shareType;
+ });
+ $sortedShares = array_merge($sortedShares, $filteredShares);
+ }
+ $this->shares = $sortedShares;
}
/**
* Validate share
*/
- private function validate():void {
+ private function validate() : void {
switch ($this->share->getType()) {
case Share::TYPE_PUBLIC:
- // public shares are alway valid
+ // public shares are always valid
break;
case Share::TYPE_USER:
if ($this->share->getUserId() !== $this->userId) {
@@ -156,7 +170,6 @@ class ShareService {
if (!$this->groupManager->isInGroup($this->share->getUserId(), $this->userId)) {
throw new NotAuthorizedException;
}
-
break;
case Share::TYPE_EMAIL:
break;