1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | namespace Aurora\Modules\CorporateCalendar; |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | class Module extends \Aurora\System\Module\AbstractLicensedModule |
16: | { |
17: | public $oManager = null; |
18: | |
19: | public function getManager() |
20: | { |
21: | if ($this->oManager === null) { |
22: | $this->oManager = new \Aurora\Modules\Calendar\Manager($this); |
23: | } |
24: | |
25: | return $this->oManager; |
26: | } |
27: | |
28: | public function init() |
29: | { |
30: | $this->subscribeEvent('Calendar::GetCalendars::after', array($this, 'onAfterGetCalendars')); |
31: | } |
32: | |
33: | public function GetSettings() |
34: | { |
35: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
36: | |
37: | return array( |
38: | 'AllowShare' => $this->getConfig('AllowShare', true) |
39: | ); |
40: | } |
41: | |
42: | |
43: | |
44: | |
45: | |
46: | |
47: | |
48: | |
49: | |
50: | |
51: | |
52: | public function UpdateCalendarShare($UserId, $Id, $IsPublic, $Shares, $ShareToAll = false, $ShareToAllAccess = \Aurora\Modules\Calendar\Enums\Permission::Read) |
53: | { |
54: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
55: | $sUserPublicId = \Aurora\System\Api::getUserPublicIdById($UserId); |
56: | $aShares = json_decode($Shares, true) ; |
57: | |
58: | |
59: | if ($ShareToAll) { |
60: | $aShares[] = array( |
61: | 'email' => $this->getManager()->getTenantUser(), |
62: | 'access' => $ShareToAllAccess |
63: | ); |
64: | } else { |
65: | $aShares[] = array( |
66: | 'email' => $this->getManager()->getTenantUser(), |
67: | 'access' => \Aurora\Modules\Calendar\Enums\Permission::RemovePermission |
68: | ); |
69: | } |
70: | |
71: | |
72: | if ($IsPublic) { |
73: | $aShares[] = array( |
74: | 'email' => $this->getManager()->getPublicUser(), |
75: | 'access' => \Aurora\Modules\Calendar\Enums\Permission::Read |
76: | ); |
77: | } |
78: | return $this->getManager()->updateCalendarShares($sUserPublicId, $Id, $aShares); |
79: | } |
80: | |
81: | public function onAfterGetCalendars($aData, &$oResult) |
82: | { |
83: | if (isset($aData['UserId']) && isset($oResult['Calendars'])) { |
84: | $oUser = \Aurora\System\Api::getUserById($aData['UserId']); |
85: | if ($oUser) { |
86: | $mCalendars = $this->getManager()->getSharedCalendars($oUser->PublicId); |
87: | if (is_array($mCalendars)) { |
88: | foreach ($mCalendars as $CalendarKey => $oCalendar) { |
89: | foreach ($oCalendar->Shares as $ShareKey => $aShare) { |
90: | if ($aShare['email'] === $this->getManager()->getTenantUser()) { |
91: | if (!$oCalendar->SharedToAll) { |
92: | $mCalendars[$CalendarKey]->Shared = true; |
93: | $mCalendars[$CalendarKey]->SharedToAll = true; |
94: | } elseif ($oUser->PublicId === $oCalendar->Owner) { |
95: | unset($mCalendars[$CalendarKey]); |
96: | } |
97: | unset($oCalendar->Shares[$ShareKey]); |
98: | } |
99: | } |
100: | } |
101: | $oResult['Calendars'] = array_merge($oResult['Calendars'], $mCalendars); |
102: | } |
103: | } |
104: | } |
105: | } |
106: | } |
107: | |