1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://flipboxfactory.com/software/organization/license |
6
|
|
|
* @link https://www.flipboxfactory.com/software/organization/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\organizations\models; |
10
|
|
|
|
11
|
|
|
use craft\base\Model; |
12
|
|
|
use flipbox\craft\ember\helpers\ModelHelper; |
13
|
|
|
use flipbox\craft\ember\helpers\SiteHelper; |
14
|
|
|
use flipbox\craft\ember\models\FieldLayoutAttributeTrait; |
15
|
|
|
use flipbox\craft\ember\validators\ModelValidator; |
16
|
|
|
use flipbox\organizations\elements\Organization; |
17
|
|
|
use flipbox\organizations\Organizations; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Flipbox Factory <[email protected]> |
21
|
|
|
* @since 1.0.0 |
22
|
|
|
*/ |
23
|
|
|
class Settings extends Model |
24
|
|
|
{ |
25
|
|
|
use FieldLayoutAttributeTrait, |
26
|
|
|
SiteSettingAttributeTrait; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var int|null|false |
30
|
|
|
*/ |
31
|
|
|
public $userSidebarTemplate = 'organizations/_components/hooks/users/details'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var int |
35
|
|
|
*/ |
36
|
|
|
private $usersTabOrder = 10; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
private $usersTabLabel = 'Users'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return string |
45
|
|
|
*/ |
46
|
3 |
|
public static function siteSettingsClass(): string |
47
|
|
|
{ |
48
|
3 |
|
return SiteSettings::class; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
protected static function fieldLayoutType(): string |
55
|
|
|
{ |
56
|
|
|
return Organization::class; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
public function getUserStates(): array |
63
|
|
|
{ |
64
|
|
|
return [ |
65
|
|
|
'active' => Organizations::t('Active'), |
66
|
|
|
'pending' => Organizations::t('Pending'), |
67
|
|
|
'inactive' => Organizations::t('InActive') |
68
|
|
|
]; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get the User tab order found on the Organization entry page. |
73
|
|
|
*/ |
74
|
|
|
public function getUsersTabOrder(): int |
75
|
|
|
{ |
76
|
|
|
return $this->usersTabOrder; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Set the User tab order found on the Organization entry page. |
81
|
|
|
* |
82
|
|
|
* @param int $order |
83
|
|
|
* @return $this |
84
|
|
|
*/ |
85
|
|
|
public function setUsersTabOrder(int $order) |
86
|
|
|
{ |
87
|
|
|
$this->usersTabOrder = $order; |
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get the User tab label found on the Organization entry page. |
93
|
|
|
*/ |
94
|
|
|
public function getUsersTabLabel(): string |
95
|
|
|
{ |
96
|
|
|
return $this->usersTabLabel; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Set the User tab label found on the Organization entry page. |
101
|
|
|
* |
102
|
|
|
* @param string $label |
103
|
|
|
* @return $this |
104
|
|
|
*/ |
105
|
|
|
public function setUsersTabLabel(string $label) |
106
|
|
|
{ |
107
|
|
|
$this->usersTabLabel = $label; |
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
public function getDefaultUserState(): string |
115
|
|
|
{ |
116
|
|
|
return 'active'; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @inheritdoc |
121
|
|
|
*/ |
122
|
|
|
public function rules() |
123
|
|
|
{ |
124
|
|
|
return array_merge( |
125
|
|
|
parent::rules(), |
126
|
|
|
$this->fieldLayoutRules(), |
127
|
|
|
[ |
128
|
|
|
[ |
129
|
|
|
[ |
130
|
|
|
'siteSettings' |
131
|
|
|
], |
132
|
|
|
ModelValidator::class |
133
|
|
|
], |
134
|
|
|
[ |
135
|
|
|
[ |
136
|
|
|
'usersTabOrder' |
137
|
|
|
], |
138
|
|
|
'number', |
139
|
|
|
'integerOnly' => true |
140
|
|
|
], |
141
|
|
|
[ |
142
|
|
|
[ |
143
|
|
|
'siteSettings', |
144
|
|
|
'usersTabOrder', |
145
|
|
|
'usersTabLabel' |
146
|
|
|
], |
147
|
|
|
'safe', |
148
|
|
|
'on' => [ |
149
|
|
|
ModelHelper::SCENARIO_DEFAULT |
150
|
|
|
] |
151
|
|
|
] |
152
|
|
|
] |
153
|
|
|
); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @inheritdoc |
158
|
|
|
*/ |
159
|
|
|
public function attributes() |
160
|
|
|
{ |
161
|
|
|
return array_merge( |
162
|
|
|
parent::attributes(), |
163
|
|
|
$this->fieldLayoutAttributes(), |
164
|
|
|
[ |
165
|
|
|
'siteSettings', |
166
|
|
|
'usersTabOrder', |
167
|
|
|
'usersTabLabel', |
168
|
|
|
|
169
|
|
|
] |
170
|
|
|
); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @inheritdoc |
175
|
|
|
*/ |
176
|
|
|
public function attributeLabels() |
177
|
|
|
{ |
178
|
|
|
return array_merge( |
179
|
|
|
parent::attributeLabels(), |
180
|
|
|
$this->fieldLayoutAttributeLabels(), |
181
|
|
|
[ |
182
|
|
|
'siteSettings' => Organizations::t('Site Settings'), |
183
|
|
|
'usersTabOrder' => Organizations::t('User\'s Tab Order'), |
184
|
|
|
'usersTabLabel' => Organizations::t('User\'s Tab Label') |
185
|
|
|
] |
186
|
|
|
); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
/******************************************* |
191
|
|
|
* STATES |
192
|
|
|
*******************************************/ |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return $this |
196
|
|
|
* @deprecated |
197
|
|
|
*/ |
198
|
|
|
public function setStates() |
199
|
|
|
{ |
200
|
|
|
return $this; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @return $this |
205
|
|
|
* @deprecated |
206
|
|
|
*/ |
207
|
|
|
public function setDefaultStates() |
208
|
|
|
{ |
209
|
|
|
return $this; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
|
213
|
|
|
/******************************************* |
214
|
|
|
* SITE SETTINGS |
215
|
|
|
*******************************************/ |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @param int|null $siteId |
219
|
|
|
* @return bool |
220
|
|
|
* @throws \craft\errors\SiteNotFoundException |
221
|
|
|
*/ |
222
|
|
|
public function isSiteEnabled(int $siteId = null): bool |
223
|
|
|
{ |
224
|
|
|
$siteSettings = $this->getSiteSettings(); |
225
|
|
|
return array_key_exists( |
226
|
|
|
SiteHelper::ensureSiteId($siteId), |
227
|
|
|
$siteSettings |
228
|
|
|
); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @return array |
233
|
|
|
* @throws \craft\errors\SiteNotFoundException |
234
|
|
|
*/ |
235
|
|
|
public function getEnabledSiteIds(): array |
236
|
|
|
{ |
237
|
|
|
return array_keys($this->getSiteSettings()); |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
|