Settings.php
6.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
namespace common\models;
use artbox\core\models\Language;
use noam148\imagemanager\models\ImageManager;
use yii\db\ActiveQuery;
use yii2tech\ar\variation\VariationBehavior;
use yii2tech\filedb\ActiveRecord;
use Yii;
/**
* Class Settings
*
* @package artbox\core\models
* @property string $analytics_key
* @property string $robots
* @property string $ga_code
* @property string $ya_code
* @property string $tag_manager
* @property string $phone
* @property string $phone2
* @property string $skype
* @property string $email
* @property string $house
* @property string $street
* @property string $office
* @property string $city
* @property string $country
* @property float $lat
* @property float $lon
* @property string $facebook
* @property string $google
* @property string $twitter
* @property string name
* @property int $logo
* @property string $about
*/
class Settings extends ActiveRecord
{
const SCENARIO_ROBOTS = 'robots';
const SCENARIO_CODES = 'codes';
private static $instance;
/**
* @inheritdoc
*/
public function scenarios()
{
return array_merge(
parent::scenarios(),
[
self::SCENARIO_ROBOTS => [ 'robots' ],
self::SCENARIO_CODES => [
'ga_code',
'ya_code',
'tag_manager',
],
]
);
}
public function behaviors()
{
return [
'translations' => [
'class' => VariationBehavior::className(),
'variationsRelation' => 'languages',
'defaultVariationRelation' => 'language',
'variationOptionReferenceAttribute' => 'language_id',
'optionModelClass' => Language::className(),
'defaultVariationOptionReference' => function () {
return Language::getCurrent()->id;
},
'optionQueryFilter' => function (ActiveQuery $query) {
$query->where(
[
'status' => true,
]
);
},
],
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[
[
'phone',
'phone2',
'skype',
'email',
'address',
'facebook',
'google',
'twitter',
'name',
'analytics_key',
'about',
'logo'
],
'string',
],
[
[
'lat',
'lon',
],
'double',
],
[
[
'email',
],
'email',
],
[
[
'logo',
],
'filter',
'filter' => function ($value) {
if (empty( $value )) {
return null;
} else {
return $value;
}
},
],
];
}
/**
* @inheritdoc
*/
public static function fileName()
{
return 'settings';
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'analytics_key' => Yii::t('core', 'Google Analytics Key'),
'robots' => Yii::t('core', 'Robots'),
'ga_code' => Yii::t('core', 'Google analytics code'),
'ya_code' => Yii::t('core', 'Yandex metrics code'),
'tag_manager' => Yii::t('core', 'Tag Manager code'),
'phone' => Yii::t('core', 'Phone'),
'phone2' => Yii::t('core', 'Additional phone'),
'skype' => Yii::t('core', 'Skype'),
'name' => Yii::t('core', 'Company name'),
'email' => Yii::t('core', 'Email'),
'address' => Yii::t('core', 'Address'),
'lat' => Yii::t('core', 'Latitude'),
'lon' => Yii::t('core', 'Longitude'),
'facebook' => Yii::t('core', 'Facebook'),
'google' => Yii::t('core', 'Google'),
'twitter' => Yii::t('core', 'Twitter'),
'logo' => Yii::t('core', 'Company logo'),
'about' => Yii::t('core', 'About us'),
];
}
public function afterFind()
{
if ($this->logo === '') {
$this->logo = null;
}
parent::afterFind();
}
/**
* Get Settings model instance
*
* @return Settings
*/
public static function getInstance()
{
if (empty( self::$instance )) {
self::$instance = self::find()->with('languages')->where([ 'id' => 1 ])->one();
return self::$instance;
}
return self::$instance;
}
public function getLanguages()
{
return $this->hasMany(SettingsLang::className(), [ 'settings_id' => 'id' ]);
}
/**
* @return \yii\db\ActiveQuery
*/
// public function getLanguage()
// {
// return $this->hasOne(SettingsLang::className(), [ 'settings_id' => 'id' ]);
// }
}