1: <?php
2: /**
3: * This code is licensed under AGPLv3 license or Afterlogic Software License
4: * if commercial version of the product was purchased.
5: * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
6: */
7:
8: namespace Aurora\Modules\Contacts\Models;
9:
10: use Aurora\Modules\Contacts\Enums\StorageType;
11: use Aurora\System\Classes\Model;
12:
13: /**
14: * Aurora\Modules\Contacts\Models\ContactCard
15: *
16: * @property integer $Id
17: * @property integer $CardId
18: * @property integer|null $AddressBookId
19: * @property string $PrimaryEmail
20: * @property string $ViewEmail
21: * @property string $PersonalEmail
22: * @property string $BusinessEmail
23: * @property string $OtherEmail
24: * @property string $BusinessCompany
25: * @property string $FullName
26: * @property string $FirstName
27: * @property string $LastName
28: * @property integer $Frequency
29: * @property bool $IsGroup
30: * @property array|null $Properties
31: *
32: * @property bool $Auto
33: * @property bool $Shared
34: * @property bool $IsTeam
35: *
36: * @property string $UUID
37: * @property string $ETag
38: * @property string $Storage
39: *
40: * @method static \Illuminate\Database\Eloquent\Builder|ContactCard select(mixed ...$args)
41: * @method static \Illuminate\Database\Eloquent\Builder|ContactCard firstWhere(Closure|string|array|\Illuminate\Database\Query\Expression $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')
42: * @method static \Illuminate\Database\Eloquent\Builder|ContactCard whereNotNull(Closure|string|array|\Illuminate\Database\Query\Expression $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')
43: * @method static \Illuminate\Database\Eloquent\Builder|ContactCard where(Closure|string|array|\Illuminate\Database\Query\Expression $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')
44:
45: */
46: class ContactCard extends Model
47: {
48: protected $table = 'contacts_cards';
49:
50: public $timestamps = false;
51:
52: protected $fillable = [
53: 'Id',
54: 'CardId',
55: 'AddressBookId',
56: 'PrimaryEmail',
57: 'ViewEmail',
58: 'PersonalEmail',
59: 'BusinessEmail',
60: 'OtherEmail',
61: 'BusinessCompany',
62: 'FullName',
63: 'FirstName',
64: 'LastName',
65: 'Frequency',
66: 'IsGroup',
67: 'Properties'
68: ];
69:
70: protected $casts = [
71: 'Properties' => 'array',
72: 'Auto' => 'boolean',
73: 'Shared' => 'boolean',
74: 'IsTeam' => 'boolean',
75: ];
76:
77: protected $appends = [
78: 'UUID',
79: 'AgeScore',
80: 'UserId',
81: 'Storage',
82: "DateModified",
83: "ETag",
84: 'ViewEmail',
85: 'Uri',
86: ];
87:
88: public function getUUIDAttribute()
89: {
90: return $this->attributes['UUID'];
91: }
92:
93: public function getAgeScoreAttribute()
94: {
95: return round($this->attributes['AgeScore']);
96: }
97:
98: public function getUserIdAttribute()
99: {
100: return $this->attributes['UserId'];
101: }
102:
103: public function getStorageAttribute()
104: {
105: return $this->attributes['Storage'];
106: }
107:
108: public function getDateModifiedAttribute()
109: {
110: return $this->attributes['DateModified'];
111: }
112:
113: public function getETagAttribute()
114: {
115: return $this->attributes['ETag'];
116: }
117:
118: public function getUriAttribute()
119: {
120: return $this->attributes['Uri'];
121: }
122:
123: /**
124: * Returns value of email that is specified as primary.
125: * @return string
126: */
127: protected function getViewEmailAttribute()
128: {
129: switch ((int) $this->PrimaryEmail) {
130: default:
131: case \Aurora\Modules\Contacts\Enums\PrimaryEmail::Personal:
132: return (string) $this->PersonalEmail;
133: case \Aurora\Modules\Contacts\Enums\PrimaryEmail::Business:
134: return (string) $this->BusinessEmail;
135: case \Aurora\Modules\Contacts\Enums\PrimaryEmail::Other:
136: return (string) $this->OtherEmail;
137: }
138: }
139: }
140: