|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net> |
| 4 | + * |
| 5 | + * @author Julius Härtl <jus@bitgrid.net> |
| 6 | + * @author Maxence Lange <maxence@artificial-owl.com> |
| 7 | + * |
| 8 | + * @license GNU AGPL version 3 or any later version |
| 9 | + * |
| 10 | + * This program is free software: you can redistribute it and/or modify |
| 11 | + * it under the terms of the GNU Affero General Public License as |
| 12 | + * published by the Free Software Foundation, either version 3 of the |
| 13 | + * License, or (at your option) any later version. |
| 14 | + * |
| 15 | + * This program is distributed in the hope that it will be useful, |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | + * GNU Affero General Public License for more details. |
| 19 | + * |
| 20 | + * You should have received a copy of the GNU Affero General Public License |
| 21 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | + * |
| 23 | + */ |
| 24 | + |
| 25 | +namespace OCA\Deck\Service; |
| 26 | + |
| 27 | +use OCA\Deck\Activity\ActivityManager; |
| 28 | +use OCA\Deck\Activity\ChangeSet; |
| 29 | +use OCA\Deck\Db\Acl; |
| 30 | +use OCA\Deck\Db\AclMapper; |
| 31 | +use OCA\Deck\Db\AssignedUsersMapper; |
| 32 | +use OCA\Deck\Db\ChangeHelper; |
| 33 | +use OCA\Deck\Db\IPermissionMapper; |
| 34 | +use OCA\Deck\Db\CardMapper; |
| 35 | +use OCA\Deck\Db\Label; |
| 36 | +use OCA\Deck\Db\Stack; |
| 37 | +use OCA\Deck\Db\StackMapper; |
| 38 | +use OCA\Deck\NoPermissionException; |
| 39 | +use OCA\Deck\Notification\NotificationHelper; |
| 40 | +use OCP\AppFramework\Db\DoesNotExistException; |
| 41 | +use OCP\IGroupManager; |
| 42 | +use OCP\IL10N; |
| 43 | +use OCA\Deck\Db\Board; |
| 44 | +use OCA\Deck\Db\BoardMapper; |
| 45 | +use OCA\Deck\Db\LabelMapper; |
| 46 | +use OCP\IUserManager; |
| 47 | +use OCA\Deck\BadRequestException; |
| 48 | +use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
| 49 | +use Symfony\Component\EventDispatcher\GenericEvent; |
| 50 | + |
| 51 | +class DashboardService { |
| 52 | + private $boardMapper; |
| 53 | + private $stackMapper; |
| 54 | + private $labelMapper; |
| 55 | + private $aclMapper; |
| 56 | + private $cardMapper; |
| 57 | + private $l10n; |
| 58 | + private $permissionService; |
| 59 | + private $notificationHelper; |
| 60 | + private $assignedUsersMapper; |
| 61 | + private $userManager; |
| 62 | + private $groupManager; |
| 63 | + private $userId; |
| 64 | + private $activityManager; |
| 65 | + /** @var EventDispatcherInterface */ |
| 66 | + private $eventDispatcher; |
| 67 | + private $changeHelper; |
| 68 | + |
| 69 | + public function __construct( |
| 70 | + BoardMapper $boardMapper, |
| 71 | + StackMapper $stackMapper, |
| 72 | + IL10N $l10n, |
| 73 | + LabelMapper $labelMapper, |
| 74 | + AclMapper $aclMapper, |
| 75 | + CardMapper $cardMapper, |
| 76 | + PermissionService $permissionService, |
| 77 | + NotificationHelper $notificationHelper, |
| 78 | + AssignedUsersMapper $assignedUsersMapper, |
| 79 | + IUserManager $userManager, |
| 80 | + IGroupManager $groupManager, |
| 81 | + ActivityManager $activityManager, |
| 82 | + EventDispatcherInterface $eventDispatcher, |
| 83 | + ChangeHelper $changeHelper, |
| 84 | + $userId |
| 85 | + ) { |
| 86 | + $this->boardMapper = $boardMapper; |
| 87 | + $this->stackMapper = $stackMapper; |
| 88 | + $this->labelMapper = $labelMapper; |
| 89 | + $this->aclMapper = $aclMapper; |
| 90 | + $this->cardMapper = $cardMapper; |
| 91 | + $this->l10n = $l10n; |
| 92 | + $this->permissionService = $permissionService; |
| 93 | + $this->notificationHelper = $notificationHelper; |
| 94 | + $this->assignedUsersMapper = $assignedUsersMapper; |
| 95 | + $this->userManager = $userManager; |
| 96 | + $this->groupManager = $groupManager; |
| 97 | + $this->activityManager = $activityManager; |
| 98 | + $this->eventDispatcher = $eventDispatcher; |
| 99 | + $this->changeHelper = $changeHelper; |
| 100 | + $this->userId = $userId; |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Set a different user than the current one, e.g. when no user is available in occ |
| 105 | + * |
| 106 | + * @param string $userId |
| 107 | + */ |
| 108 | + public function setUserId(string $userId): void { |
| 109 | + $this->userId = $userId; |
| 110 | + } |
| 111 | + |
| 112 | + |
| 113 | + /** |
| 114 | + * @return array |
| 115 | + */ |
| 116 | + public function findAllWithDue($userId) { |
| 117 | + $userInfo = $this->getBoardPrerequisites(); |
| 118 | + $userBoards = $this->findAllBoardsFromUser($userInfo); |
| 119 | + $allDueCards = []; |
| 120 | + foreach ($userBoards as $userBoard) { |
| 121 | + $allDueCards[] = $this->cardMapper->findAllWithDue($userBoard->getId()); |
| 122 | + } |
| 123 | + return $allDueCards; |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * @return array |
| 128 | + */ |
| 129 | + private function findAllBoardsFromUser($userInfo, $since = -1) { |
| 130 | + $userBoards = $this->boardMapper->findAllByUser($userInfo['user'], null, null, $since); |
| 131 | + $groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups'],null, null, $since); |
| 132 | + $circleBoards = $this->boardMapper->findAllByCircles($userInfo['user'], null, null, $since); |
| 133 | + return array_merge($userBoards, $groupBoards, $circleBoards); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * @return array |
| 138 | + */ |
| 139 | + private function getBoardPrerequisites() { |
| 140 | + $groups = $this->groupManager->getUserGroupIds( |
| 141 | + $this->userManager->get($this->userId) |
| 142 | + ); |
| 143 | + return [ |
| 144 | + 'user' => $this->userId, |
| 145 | + 'groups' => $groups |
| 146 | + ]; |
| 147 | + } |
| 148 | + |
| 149 | + |
| 150 | +} |
0 commit comments