1: <?php
2:
3: namespace Aurora\Modules\Contacts\Models;
4:
5: use Aurora\System\Classes\Model;
6: use Aurora\Modules\Core\Models\User;
7:
8: class Group extends Model
9: {
10: protected $table = 'contacts_groups';
11: protected $foreignModel = User::class;
12: protected $foreignModelIdColumn = 'IdUser'; // Column that refers to an external table
13:
14: public $Events = array();
15:
16: public $GroupContacts = array();
17:
18: protected $fillable = [
19: 'Id',
20: 'IdUser',
21: 'UUID',
22: 'Name',
23: 'IsOrganization',
24: 'Email',
25: 'Company',
26: 'Street',
27: 'City',
28: 'State',
29: 'Zip',
30: 'Country',
31: 'Phone',
32: 'Fax',
33: 'Web',
34: 'Events'
35: ];
36:
37: protected $casts = [
38: 'Properties' => 'array',
39:
40: 'IsOrganization' => 'boolean'
41: ];
42:
43: public function populate($aGroup)
44: {
45: parent::populate($aGroup);
46:
47: if (!empty($aGroup['UUID'])) {
48: $this->UUID = $aGroup['UUID'];
49: } elseif (empty($this->UUID)) {
50: $this->UUID = \Sabre\DAV\UUIDUtil::getUUID();
51: }
52: // $this->GroupContacts = array();
53: // if (isset($aGroup['Contacts']) && is_array($aGroup['Contacts']))
54: // {
55: // $aContactUUIDs = $aGroup['Contacts'];
56: // Contact::whereIn('UUID', $aGroup['Contacts'])->map(function($oContact) {
57: // return $oContact->UUID;
58: // });
59:
60:
61: // foreach ($aContactUUIDs as $sContactUUID)
62: // {
63: // $oGroupContact = new \Aurora\Modules\Contacts\Classes\GroupContact($this->getModule());
64: // $oGroupContact->ContactUUID = $sContactUUID;
65: // $this->GroupContacts[] = $oGroupContact;
66: // }
67: // }
68: }
69:
70: public function Contacts()
71: {
72: return $this->belongsToMany(Contact::class, 'contacts_group_contact', 'GroupId', 'ContactId');
73: }
74: }
75: