1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://flipboxfactory.com/software/domains/license |
6
|
|
|
* @link https://www.flipboxfactory.com/software/domains/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\craft\domains\records; |
10
|
|
|
|
11
|
|
|
use Craft; |
12
|
|
|
use flipbox\craft\ember\helpers\ModelHelper; |
13
|
|
|
use flipbox\craft\ember\records\ActiveRecord; |
14
|
|
|
use flipbox\craft\ember\records\ElementAttributeTrait; |
15
|
|
|
use flipbox\craft\ember\records\FieldAttributeTrait; |
16
|
|
|
use flipbox\craft\ember\records\SiteAttributeTrait; |
17
|
|
|
use flipbox\craft\ember\records\SortableTrait; |
18
|
|
|
use flipbox\craft\domains\queries\DomainsQuery; |
19
|
|
|
use flipbox\craft\domains\fields\Domains; |
20
|
|
|
use flipbox\craft\domains\validators\DomainValidator; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author Flipbox Factory <[email protected]> |
24
|
|
|
* @since 1.0.0 |
25
|
|
|
* |
26
|
|
|
* @property string $domain |
27
|
|
|
* @property string $status |
28
|
|
|
* @property int $sortOrder |
29
|
|
|
*/ |
30
|
|
|
class Domain extends ActiveRecord |
31
|
|
|
{ |
32
|
|
|
use SiteAttributeTrait, |
33
|
|
|
ElementAttributeTrait, |
34
|
|
|
FieldAttributeTrait, |
35
|
|
|
SortableTrait; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @inheritdoc |
39
|
|
|
*/ |
40
|
|
|
const TABLE_ALIAS = 'domains'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @inheritdoc |
44
|
|
|
*/ |
45
|
|
|
protected $getterPriorityAttributes = ['fieldId', 'elementId', 'siteId']; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @noinspection PhpDocMissingThrowsInspection |
49
|
|
|
* @return DomainsQuery |
50
|
|
|
*/ |
51
|
|
|
public static function find(): DomainsQuery |
52
|
|
|
{ |
53
|
|
|
/** @noinspection PhpIncompatibleReturnTypeInspection */ |
54
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */ |
55
|
|
|
return Craft::createObject(DomainsQuery::class, [get_called_class()]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
|
public function rules(): array |
62
|
|
|
{ |
63
|
|
|
return array_merge( |
64
|
|
|
parent::rules(), |
65
|
|
|
$this->siteRules(), |
66
|
|
|
$this->elementRules(), |
67
|
|
|
$this->fieldRules(), |
68
|
|
|
[ |
69
|
|
|
[ |
70
|
|
|
[ |
71
|
|
|
'domain', |
72
|
|
|
'status', |
73
|
|
|
], |
74
|
|
|
'required' |
75
|
|
|
], |
76
|
|
|
[ |
77
|
|
|
'domain', |
78
|
|
|
DomainValidator::class |
79
|
|
|
], |
80
|
|
|
[ |
81
|
|
|
'status', |
82
|
|
|
'in', |
83
|
|
|
'range' => array_keys(Domains::getStatuses()) |
84
|
|
|
], |
85
|
|
|
[ |
86
|
|
|
[ |
87
|
|
|
'domain', |
88
|
|
|
'status', |
89
|
|
|
], |
90
|
|
|
'safe', |
91
|
|
|
'on' => [ |
92
|
|
|
ModelHelper::SCENARIO_DEFAULT |
|
|
|
|
93
|
|
|
] |
94
|
|
|
] |
95
|
|
|
] |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @inheritdoc |
101
|
|
|
*/ |
102
|
|
|
public function beforeSave($insert) |
103
|
|
|
{ |
104
|
|
|
$this->ensureSortOrder( |
105
|
|
|
[ |
106
|
|
|
'elementId' => $this->elementId, |
107
|
|
|
'fieldId' => $this->fieldId, |
108
|
|
|
'siteId' => $this->siteId |
109
|
|
|
] |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
return parent::beforeSave($insert); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @inheritdoc |
117
|
|
|
* @throws \yii\db\Exception |
118
|
|
|
*/ |
119
|
|
|
public function afterSave($insert, $changedAttributes) |
120
|
|
|
{ |
121
|
|
|
$this->autoReOrder( |
122
|
|
|
'domain', |
123
|
|
|
[ |
124
|
|
|
'elementId' => $this->elementId, |
125
|
|
|
'fieldId' => $this->fieldId, |
126
|
|
|
'siteId' => $this->siteId |
127
|
|
|
] |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
parent::afterSave($insert, $changedAttributes); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @inheritdoc |
135
|
|
|
* @throws \yii\db\Exception |
136
|
|
|
*/ |
137
|
|
|
public function afterDelete() |
138
|
|
|
{ |
139
|
|
|
$this->sequentialOrder( |
140
|
|
|
'domain', |
141
|
|
|
[ |
142
|
|
|
'elementId' => $this->elementId, |
143
|
|
|
'fieldId' => $this->fieldId, |
144
|
|
|
'siteId' => $this->siteId |
145
|
|
|
] |
146
|
|
|
); |
147
|
|
|
|
148
|
|
|
parent::afterDelete(); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
This class constant has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.