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