1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | namespace Aurora\Modules\DavContacts; |
9: | |
10: | use Afterlogic\DAV\Constants; |
11: | use Aurora\Api; |
12: | use Aurora\Modules\Contacts\Enums\Access; |
13: | use Aurora\Modules\Contacts\Enums\StorageType; |
14: | use Aurora\Modules\Contacts\Models\AddressBook; |
15: | use Aurora\Modules\Contacts\Models\Contact; |
16: | use Aurora\Modules\Contacts\Models\Group; |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | class Module extends \Aurora\System\Module\AbstractModule |
28: | { |
29: | public $oManager = null; |
30: | |
31: | protected $aRequireModules = [ |
32: | 'Contacts' |
33: | ]; |
34: | |
35: | protected $_oldGroup = null; |
36: | |
37: | protected $__LOCK_AFTER_CREATE_CONTACT_SUBSCRIBE__ = false; |
38: | protected $__LOCK_AFTER_UPDATE_CONTACT_SUBSCRIBE__ = false; |
39: | |
40: | public function getManager() |
41: | { |
42: | if ($this->oManager === null) { |
43: | $this->oManager = new Manager($this); |
44: | } |
45: | |
46: | return $this->oManager; |
47: | } |
48: | |
49: | public function init() |
50: | { |
51: | $this->subscribeEvent('Contacts::CreateContact::after', array($this, 'onAfterCreateContact')); |
52: | $this->subscribeEvent('Contacts::UpdateContact::after', array($this, 'onAfterUpdateContact')); |
53: | $this->subscribeEvent('Contacts::DeleteContacts::before', array($this, 'onBeforeDeleteContacts')); |
54: | |
55: | $this->subscribeEvent('Contacts::CreateGroup::after', array($this, 'onAfterCreateGroup')); |
56: | |
57: | $this->subscribeEvent('Contacts::UpdateGroup::before', array($this, 'onBeforeUpdateGroup')); |
58: | $this->subscribeEvent('Contacts::UpdateGroup::after', array($this, 'onAfterUpdateGroup')); |
59: | |
60: | $this->subscribeEvent('Contacts::DeleteGroup::before', array($this, 'onBeforDeleteGroup')); |
61: | |
62: | |
63: | $this->subscribeEvent('Contacts::AddContactsToGroup::after', array($this, 'onAfterAddContactsToGroup')); |
64: | $this->subscribeEvent('Contacts::RemoveContactsFromGroup::after', array($this, 'onAfterRemoveContactsFromGroup')); |
65: | $this->subscribeEvent('Core::DeleteUser::after', array($this, 'onAfterDeleteUser')); |
66: | $this->subscribeEvent('Contacts::UpdateSharedContacts::after', array($this, 'onAfterUpdateSharedContacts'), 90); |
67: | |
68: | $this->subscribeEvent('MobileSync::GetInfo', array($this, 'onGetMobileSyncInfo')); |
69: | |
70: | $this->subscribeEvent('Contacts::GetContactAsVCF::before', array($this, 'onBeforeGetContactAsVCF')); |
71: | |
72: | $this->subscribeEvent('Contacts::CreateAddressBook::after', array($this, 'onAfterCreateAddressBook')); |
73: | $this->subscribeEvent('Contacts::UpdateAddressBook::after', array($this, 'onAfterUpdateAddressBook')); |
74: | $this->subscribeEvent('Contacts::DeleteAddressBook::before', array($this, 'onBeforeDeleteAddressBook')); |
75: | } |
76: | |
77: | |
78: | |
79: | |
80: | |
81: | protected function getContact($iUserId, $sStorage, $sUID) |
82: | { |
83: | return Contact::where('IdUser', $iUserId)->where('Storage', $sStorage)->where('Properties->' . self::GetName() . '::UID', $sUID)->first(); |
84: | } |
85: | |
86: | |
87: | |
88: | |
89: | |
90: | protected function getGroup($iUserId, $sUID) |
91: | { |
92: | return Group::where('IdUser', $iUserId)->where('Properties->' . self::GetName() . '::UID', $sUID)->first(); |
93: | } |
94: | |
95: | protected function getStorage($sStorage) |
96: | { |
97: | $sResult = \Afterlogic\DAV\Constants::ADDRESSBOOK_DEFAULT_NAME; |
98: | if ($sStorage === StorageType::Personal) { |
99: | $sResult = \Afterlogic\DAV\Constants::ADDRESSBOOK_DEFAULT_NAME; |
100: | } elseif ($sStorage === StorageType::Shared) { |
101: | $sResult = \Afterlogic\DAV\Constants::ADDRESSBOOK_SHARED_WITH_ALL_NAME; |
102: | } elseif ($sStorage === StorageType::Collected) { |
103: | $sResult = \Afterlogic\DAV\Constants::ADDRESSBOOK_COLLECTED_NAME; |
104: | } elseif ($sStorage === StorageType::Team) { |
105: | $sResult = 'gab'; |
106: | } |
107: | |
108: | return $sResult; |
109: | } |
110: | |
111: | |
112: | |
113: | |
114: | |
115: | |
116: | |
117: | |
118: | public function CreateContact($UserId, $VCard, $UID, $Storage = StorageType::Personal) |
119: | { |
120: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
121: | |
122: | $oVCard = \Sabre\VObject\Reader::read($VCard, \Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES); |
123: | $oContactsDecorator = \Aurora\Modules\Contacts\Module::Decorator(); |
124: | |
125: | $bIsAuto = false; |
126: | if ($Storage === StorageType::Collected) { |
127: | $bIsAuto = true; |
128: | $Storage = StorageType::Personal; |
129: | } |
130: | |
131: | $aContactData = \Aurora\Modules\Contacts\Classes\VCard\Helper::GetContactDataFromVcard($oVCard); |
132: | $aContactData['Storage'] = $Storage; |
133: | |
134: | $this->__LOCK_AFTER_CREATE_CONTACT_SUBSCRIBE__ = true; |
135: | $mResult = $oContactsDecorator->CreateContact($aContactData, $UserId); |
136: | if ($mResult) { |
137: | $oContact = \Aurora\Modules\Contacts\Module::getInstance()->GetContact($mResult['UUID'], $UserId); |
138: | |
139: | if ($oContact instanceof Contact) { |
140: | $oContact->Auto = $bIsAuto; |
141: | $oContact->setExtendedProp(self::GetName() . '::UID', $UID); |
142: | $oContact->setExtendedProp(self::GetName() . '::VCardUID', \str_replace('urn:uuid:', '', (string) $oVCard->UID)); |
143: | $aStorageParts = \explode('-', $oContact->Storage); |
144: | if (isset($aStorageParts[0]) && $aStorageParts[0] === StorageType::AddressBook) { |
145: | $oContact->Storage = StorageType::AddressBook; |
146: | } |
147: | $oContact->save(); |
148: | } |
149: | } |
150: | |
151: | $this->__LOCK_AFTER_CREATE_CONTACT_SUBSCRIBE__ = false; |
152: | |
153: | return $mResult; |
154: | } |
155: | |
156: | |
157: | |
158: | |
159: | |
160: | |
161: | |
162: | |
163: | public function CreateGroup($UserId, $VCard, $UUID) |
164: | { |
165: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
166: | |
167: | $oVCard = \Sabre\VObject\Reader::read($VCard, \Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES); |
168: | |
169: | $aGroupData = \Aurora\Modules\Contacts\Classes\VCard\Helper::GetGroupDataFromVcard($oVCard, $UUID); |
170: | |
171: | if (isset($aGroupData['Contacts']) && is_array($aGroupData['Contacts']) && count($aGroupData['Contacts']) > 0) { |
172: | $aGroupData['Contacts'] = Contact::whereIn('Properties->DavContacts::VCardUID', $aGroupData['Contacts']) |
173: | ->get('UUID') |
174: | ->map(function ($oContact) { |
175: | return $oContact->UUID; |
176: | })->toArray(); |
177: | } |
178: | |
179: | if (isset($UUID)) { |
180: | $aGroupData['DavContacts::UID'] = $UUID; |
181: | } |
182: | |
183: | $mResult = \Aurora\Modules\Contacts\Module::getInstance()->CreateGroup($aGroupData, $UserId); |
184: | |
185: | return $mResult; |
186: | } |
187: | |
188: | |
189: | |
190: | |
191: | |
192: | |
193: | |
194: | public function UpdateContact($UserId, $VCard, $UUID, $Storage = 'personal') |
195: | { |
196: | $mResult = false; |
197: | |
198: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
199: | |
200: | $oVCard = \Sabre\VObject\Reader::read($VCard, \Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES); |
201: | $aContactData = \Aurora\Modules\Contacts\Classes\VCard\Helper::GetContactDataFromVcard($oVCard); |
202: | |
203: | $this->__LOCK_AFTER_UPDATE_CONTACT_SUBSCRIBE__ = true; |
204: | |
205: | $oContact = $this->getContact($UserId, $Storage, $UUID); |
206: | |
207: | if ($oContact) { |
208: | $bIsAuto = false; |
209: | if ($Storage === StorageType::Collected) { |
210: | $bIsAuto = true; |
211: | $Storage = StorageType::Personal; |
212: | } |
213: | |
214: | $oContact->populate($aContactData); |
215: | $oContact->Storage = $Storage; |
216: | $oContact->Auto = $bIsAuto; |
217: | $mResult = $oContact->save(); |
218: | } |
219: | $this->__LOCK_AFTER_UPDATE_CONTACT_SUBSCRIBE__ = false; |
220: | |
221: | return $mResult; |
222: | } |
223: | |
224: | |
225: | |
226: | |
227: | |
228: | |
229: | |
230: | |
231: | public function UpdateGroup($UserId, $VCard, $UUID) |
232: | { |
233: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
234: | |
235: | $oVCard = \Sabre\VObject\Reader::read($VCard, \Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES); |
236: | |
237: | $aGroupData = \Aurora\Modules\Contacts\Classes\VCard\Helper::GetGroupDataFromVcard($oVCard, $UUID); |
238: | |
239: | if (is_array($aGroupData['Contacts']) && count($aGroupData['Contacts']) > 0) { |
240: | $aGroupData['Contacts'] = Contact::whereIn('Properties->DavContacts::VCardUID', $aGroupData['Contacts']) |
241: | ->get('UUID') |
242: | ->map(function ($oContact) { |
243: | return $oContact->UUID; |
244: | })->toArray(); |
245: | } else { |
246: | $aGroupData['Contacts'] = []; |
247: | } |
248: | |
249: | $oGroupDb = $this->getGroup($UserId, $UUID); |
250: | |
251: | $aGroupData['UUID'] = $oGroupDb->UUID; |
252: | |
253: | $mResult = \Aurora\Modules\Contacts\Module::getInstance()->UpdateGroup($UserId, $aGroupData); |
254: | |
255: | return $mResult; |
256: | } |
257: | |
258: | |
259: | |
260: | |
261: | |
262: | public function onAfterCreateContact(&$aArgs, &$aResult) |
263: | { |
264: | if (!$this->__LOCK_AFTER_CREATE_CONTACT_SUBSCRIBE__ && isset($aArgs["Contact"]["Storage"])) { |
265: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
266: | $sUUID = isset($aResult) && isset($aResult['UUID']) ? $aResult['UUID'] : false; |
267: | if ($sUUID) { |
268: | $oContact = \Aurora\Modules\Contacts\Module::getInstance()->GetContact($sUUID, $aArgs['UserId']); |
269: | if ($oContact instanceof \Aurora\Modules\Contacts\Models\Contact) { |
270: | $oContact->setExtendedProp(self::GetName() . '::UID', $sUUID); |
271: | $oContact->setExtendedProp(self::GetName() . '::VCardUID', $sUUID); |
272: | |
273: | $aStorageParts = \explode('-', $oContact->Storage); |
274: | if (isset($aStorageParts[0]) && $aStorageParts[0] === StorageType::AddressBook) { |
275: | $oContact->Storage = StorageType::AddressBook; |
276: | } |
277: | $oContact->save(); |
278: | if (!$this->getManager()->createContact($oContact)) { |
279: | $aResult = false; |
280: | } else { |
281: | foreach ($oContact->GroupsContacts as $oGroupContact) { |
282: | $oGroup = \Aurora\Modules\Contacts\Module::getInstance()->GetGroup( |
283: | $aArgs['UserId'], |
284: | $oGroupContact->GroupUUID |
285: | ); |
286: | if ($oGroup) { |
287: | $this->getManager()->updateGroup($oGroup); |
288: | } |
289: | } |
290: | } |
291: | } |
292: | } |
293: | } |
294: | } |
295: | |
296: | |
297: | |
298: | |
299: | |
300: | public function onAfterUpdateContact(&$aArgs, &$aResult) |
301: | { |
302: | if (!$this->__LOCK_AFTER_CREATE_CONTACT_SUBSCRIBE__) { |
303: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
304: | |
305: | if ($aResult && is_array($aArgs['Contact']) && isset($aArgs['Contact']['UUID'])) { |
306: | $UserId = $aArgs['UserId']; |
307: | $oContact = \Aurora\Modules\Contacts\Module::Decorator()->GetContact($aArgs['Contact']['UUID'], $UserId); |
308: | if ($oContact instanceof \Aurora\Modules\Contacts\Models\Contact) { |
309: | $sContactStorage = $aArgs['Contact']['Storage']; |
310: | if ($sContactStorage === StorageType::Personal && isset($aArgs['Contact']['Auto']) && $aArgs['Contact']['Auto'] === true) { |
311: | $sContactStorage = StorageType::Collected; |
312: | } |
313: | $sStorage = $this->getStorage($sContactStorage); |
314: | |
315: | $aStorageParts = \explode('-', $sContactStorage); |
316: | if (isset($aStorageParts[0]) && $aStorageParts[0] === StorageType::AddressBook) { |
317: | $oAddressBook = AddressBook::where('Id', $oContact->AddressBookId) |
318: | ->where('UserId', $UserId) |
319: | ->first(); |
320: | if ($oAddressBook) { |
321: | $sStorage = $oAddressBook->UUID; |
322: | } else { |
323: | $sUserPrincipalUri = Constants::PRINCIPALS_PREFIX . API::getUserPublicIdById($UserId); |
324: | $dBPrefix = Api::GetSettings()->DBPrefix; |
325: | $stmt = Api::GetPDO()->prepare("select sa.* from ".$dBPrefix."adav_shared_addressbooks sa |
326: | left join ".$dBPrefix."adav_addressbooks da on sa.addressbook_id = da.id |
327: | right join ".$dBPrefix."contacts_addressbooks ca on da.uri = ca.UUID where ca.Id = ? and sa.principaluri = ?"); |
328: | $stmt->execute([$oContact->AddressBookId, $sUserPrincipalUri]); |
329: | $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); |
330: | if (is_array($res) && count($res) > 0) { |
331: | $sStorage = $res[0]['addressbookuri']; |
332: | } |
333: | } |
334: | } |
335: | $oDavContact = $this->getManager()->getContactById( |
336: | $UserId, |
337: | $oContact->{self::GetName() . '::UID'}, |
338: | $sStorage |
339: | ); |
340: | |
341: | if ($oDavContact) { |
342: | $aStorageParts = \explode('-', $oContact->Storage); |
343: | if (isset($aStorageParts[0]) && $aStorageParts[0] === StorageType::AddressBook) { |
344: | $oContact->Storage = StorageType::AddressBook; |
345: | } |
346: | if (!$this->getManager()->updateContact($oContact)) { |
347: | $aResult = false; |
348: | } else { |
349: | foreach ($oContact->GroupsContacts as $oGroupsContact) { |
350: | $oGroup = \Aurora\Modules\Contacts\Module::Decorator()->GetGroup($UserId, $oGroupsContact->GroupUUID); |
351: | if ($oGroup instanceof \Aurora\Modules\Contacts\Models\Group) { |
352: | $this->getManager()->updateGroup($oGroup); |
353: | } |
354: | } |
355: | } |
356: | } else { |
357: | if (!$this->getManager()->createContact($oContact)) { |
358: | $aResult = false; |
359: | } |
360: | } |
361: | } |
362: | } |
363: | } |
364: | } |
365: | |
366: | |
367: | |
368: | |
369: | |
370: | public function onBeforeDeleteContacts(&$aArgs, &$aResult) |
371: | { |
372: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
373: | |
374: | Api::CheckAccess($aArgs['UserId']); |
375: | $oUser = \Aurora\System\Api::getUserById($aArgs['UserId']); |
376: | |
377: | if (isset($aArgs['UUIDs'])) { |
378: | $aEntities = Contact::whereIn('UUID', \array_unique($aArgs['UUIDs']))->get(); |
379: | |
380: | $aUIDs = []; |
381: | $sStorage = $sContactStorage = StorageType::Personal; |
382: | $bIsAuto = false; |
383: | $iAddressBookId = 0; |
384: | foreach ($aEntities as $oContact) { |
385: | if (\Aurora\Modules\Contacts\Module::Decorator()->CheckAccessToObject($oUser, $oContact, Access::Write)) { |
386: | $aUIDs[] = $oContact->{'DavContacts::UID'}; |
387: | $sStorage = $sContactStorage = $oContact->Storage; |
388: | $bIsAuto = $oContact->Auto; |
389: | |
390: | $iAddressBookId = $oContact->AddressBookId; |
391: | } |
392: | } |
393: | if ($sStorage !== StorageType::Team) { |
394: | $sStorage = $this->getStorage($sStorage); |
395: | $aStorageParts = \explode('-', $sContactStorage); |
396: | if (isset($aStorageParts[0]) && $aStorageParts[0] === StorageType::AddressBook) { |
397: | $oAddressBook = AddressBook::where('Id', $iAddressBookId) |
398: | ->where('UserId', $aArgs['UserId'])->first(); |
399: | |
400: | if ($oAddressBook) { |
401: | $sStorage = $oAddressBook->UUID; |
402: | } |
403: | } |
404: | if ($bIsAuto) { |
405: | $sStorage = $this->getStorage(StorageType::Collected); |
406: | } |
407: | if (!$this->getManager()->deleteContacts( |
408: | $aArgs['UserId'], |
409: | $aUIDs, |
410: | $sStorage |
411: | ) |
412: | ) { |
413: | $aResult = false; |
414: | } |
415: | } |
416: | } |
417: | } |
418: | |
419: | |
420: | |
421: | |
422: | |
423: | public function onAfterCreateGroup(&$aArgs, &$aResult) |
424: | { |
425: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
426: | |
427: | $sUUID = $aResult; |
428: | if ($sUUID) { |
429: | $oGroup = \Aurora\Modules\Contacts\Module::getInstance()->GetGroup($aArgs['UserId'], $sUUID); |
430: | if ($oGroup instanceof \Aurora\Modules\Contacts\Models\Group) { |
431: | $oGroup->setExtendedProp(self::GetName() . '::UID', $sUUID); |
432: | $oGroup->save(); |
433: | if (!$this->getManager()->createGroup($oGroup)) { |
434: | $aResult = false; |
435: | } |
436: | } |
437: | } |
438: | } |
439: | |
440: | |
441: | |
442: | |
443: | |
444: | public function onAfterUpdateGroup(&$aArgs, &$aResult) |
445: | { |
446: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
447: | $sUUID = isset($aArgs['Group']) && isset($aArgs['Group']['UUID']) ? $aArgs['Group']['UUID'] : false; |
448: | if ($sUUID) { |
449: | $oGroup = \Aurora\Modules\Contacts\Module::getInstance()->GetGroup($aArgs['UserId'], $sUUID); |
450: | if ($oGroup instanceof \Aurora\Modules\Contacts\Models\Group) { |
451: | if (!$this->getManager()->updateGroup($oGroup)) { |
452: | $aResult = false; |
453: | } |
454: | } |
455: | } |
456: | } |
457: | |
458: | |
459: | |
460: | |
461: | |
462: | public function onBeforDeleteGroup(&$aArgs, &$mResult) |
463: | { |
464: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
465: | |
466: | $oGroup = \Aurora\Modules\Contacts\Module::getInstance()->GetGroup( |
467: | $aArgs['UserId'], |
468: | $aArgs['UUID'] |
469: | ); |
470: | |
471: | if ($oGroup instanceof \Aurora\Modules\Contacts\Models\Group) { |
472: | $mResult = $this->getManager()->deleteGroup($aArgs['UserId'], $oGroup->{$this->GetName() . '::UID'}); |
473: | } |
474: | } |
475: | |
476: | |
477: | |
478: | |
479: | |
480: | public function onAfterAddContactsToGroup(&$aArgs, &$aResult) |
481: | { |
482: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
483: | |
484: | $oGroup = \Aurora\Modules\Contacts\Module::Decorator()->GetGroup($aArgs['UserId'], $aArgs['GroupUUID']); |
485: | if ($oGroup) { |
486: | $this->getManager()->updateGroup($oGroup); |
487: | } |
488: | } |
489: | |
490: | |
491: | |
492: | |
493: | |
494: | public function onAfterRemoveContactsFromGroup(&$aArgs, &$aResult) |
495: | { |
496: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
497: | |
498: | $oGroup = \Aurora\Modules\Contacts\Module::Decorator()->GetGroup($aArgs['UserId'], $aArgs['GroupUUID']); |
499: | if ($oGroup) { |
500: | $this->getManager()->updateGroup($oGroup); |
501: | } |
502: | } |
503: | |
504: | public function onAfterDeleteUser(&$aArgs, &$mResult) |
505: | { |
506: | $this->getManager()->clearAllContactsAndGroups($aArgs['UserId']); |
507: | } |
508: | |
509: | public function onAfterUpdateSharedContacts($aArgs, &$mResult) |
510: | { |
511: | $oContacts = \Aurora\Modules\Contacts\Module::Decorator(); |
512: | { |
513: | $aUUIDs = isset($aArgs['UUIDs']) ? $aArgs['UUIDs'] : []; |
514: | foreach ($aUUIDs as $sUUID) { |
515: | $oContact = $oContacts->GetContact($sUUID, $aArgs['UserId']); |
516: | if ($oContact) { |
517: | $fromStorage = $toStorage = null; |
518: | if ($oContact->Storage === StorageType::Shared) { |
519: | $fromStorage = \Afterlogic\DAV\Constants::ADDRESSBOOK_SHARED_WITH_ALL_NAME; |
520: | $toStorage = \Afterlogic\DAV\Constants::ADDRESSBOOK_DEFAULT_NAME; |
521: | } elseif ($oContact->Storage === StorageType::Personal) { |
522: | $fromStorage = \Afterlogic\DAV\Constants::ADDRESSBOOK_DEFAULT_NAME; |
523: | $toStorage = \Afterlogic\DAV\Constants::ADDRESSBOOK_SHARED_WITH_ALL_NAME; |
524: | } |
525: | if (isset($fromStorage, $toStorage)) { |
526: | $this->getManager()->copyContact( |
527: | $aArgs['UserId'], |
528: | $oContact->{'DavContacts::UID'}, |
529: | $fromStorage, |
530: | $toStorage |
531: | ); |
532: | } |
533: | } |
534: | } |
535: | } |
536: | } |
537: | |
538: | public function onGetMobileSyncInfo($aArgs, &$mResult) |
539: | { |
540: | $oDavModule = \Aurora\Modules\Dav\Module::Decorator(); |
541: | |
542: | $sDavServer = $oDavModule->GetServerUrl(); |
543: | |
544: | $mResult['Dav']['Contacts'] = array( |
545: | 'PersonalContactsUrl' => $sDavServer.'addressbooks/'.\Afterlogic\DAV\Constants::ADDRESSBOOK_DEFAULT_NAME, |
546: | 'CollectedAddressesUrl' => $sDavServer.'addressbooks/'.\Afterlogic\DAV\Constants::ADDRESSBOOK_COLLECTED_NAME, |
547: | 'SharedWithAllUrl' => $sDavServer.'addressbooks/'.\Afterlogic\DAV\Constants::ADDRESSBOOK_SHARED_WITH_ALL_NAME, |
548: | 'TeamAddressBookUrl' => $sDavServer.'gab' |
549: | ); |
550: | } |
551: | |
552: | public function onBeforeGetContactAsVCF($aArgs, &$mResult) |
553: | { |
554: | $oContact = $aArgs['Contact']; |
555: | if ($oContact instanceof \Aurora\Modules\Contacts\Models\Contact) { |
556: | $mResult = $this->getManager()->getVCardObjectById($oContact->IdUser, $oContact->{'DavContacts::UID'}, $this->getStorage($oContact->Storage)); |
557: | |
558: | return true; |
559: | } |
560: | } |
561: | |
562: | public function onAfterCreateAddressBook($aArgs, &$mResult) |
563: | { |
564: | if ($mResult) { |
565: | $oAddressBook = AddressBook::where('Id', $mResult) |
566: | ->where('UserId', $aArgs['UserId'])->first(); |
567: | |
568: | if ($oAddressBook) { |
569: | $mResult = $this->getManager()->createAddressBook( |
570: | $aArgs['UserId'], |
571: | $oAddressBook->UUID, |
572: | $oAddressBook->Name |
573: | ); |
574: | } |
575: | } |
576: | |
577: | return true; |
578: | } |
579: | |
580: | public function onAfterUpdateAddressBook($aArgs, &$mResult) |
581: | { |
582: | if ($mResult) { |
583: | $oAddressBook = AddressBook::where('Id', $aArgs['EntityId']) |
584: | ->where('UserId', $aArgs['UserId'])->first(); |
585: | |
586: | if ($oAddressBook) { |
587: | $mResult = $this->getManager()->updateAddressBook( |
588: | $aArgs['UserId'], |
589: | $oAddressBook->UUID, |
590: | $aArgs['AddressBookName'] |
591: | ); |
592: | } |
593: | } |
594: | } |
595: | |
596: | public function onBeforeDeleteAddressBook($aArgs, &$mResult) |
597: | { |
598: | $oAddressBook = AddressBook::where('Id', $aArgs['EntityId']) |
599: | ->where('UserId', $aArgs['UserId'])->first(); |
600: | |
601: | if ($oAddressBook) { |
602: | $mResult = $this->getManager()->deleteAddressBook( |
603: | $aArgs['UserId'], |
604: | $oAddressBook->UUID |
605: | ); |
606: | } |
607: | } |
608: | } |
609: | |