Blame view

common/models/Settings.php 6.13 KB
ae432de6   Alexey Boroda   first commit
1
2
  <?php
      namespace common\models;
9870b2b4   Alexey Boroda   -In process
3
      
ae432de6   Alexey Boroda   first commit
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
      use noam148\imagemanager\models\ImageManager;
      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 $vk
       * @property string $ok
       * @property string $google
       * @property string $twitter
       * @property string name
       * @property int    $logo
       * @property string $about
9870b2b4   Alexey Boroda   -In process
36
       * @property string $index
ae432de6   Alexey Boroda   first commit
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
       */
      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',
                      ],
                  ]
              );
          }
9870b2b4   Alexey Boroda   -In process
62
          
ae432de6   Alexey Boroda   first commit
63
64
65
66
67
68
69
70
          /**
           * @inheritdoc
           */
          public function rules()
          {
              return [
                  [
                      [
9870b2b4   Alexey Boroda   -In process
71
                          'index',
ae432de6   Alexey Boroda   first commit
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
                          'analytics_key',
                          'robots',
                          'ga_code',
                          'ya_code',
                          'tag_manager',
                          'phone',
                          'phone2',
                          'skype',
                          'email',
                          'house',
                          'street',
                          'office',
                          'city',
                          'country',
                          'facebook',
                          'vk',
                          'google',
                          'twitter',
                          'name',
                          'about',
                          'ok',
                      ],
                      'string',
                  ],
                  [
                      [
                          'lat',
                          'lon',
                      ],
                      'double',
                  ],
                  [
                      [
                          'email',
                      ],
                      'email',
                  ],
                  [
                      [
                          'logo',
                      ],
                      'integer',
                  ],
                  [
                      [
                          'logo',
                      ],
                      'exist',
                      'targetClass'     => ImageManager::className(),
                      'targetAttribute' => 'id',
                  ],
                  [
                      [
                          'logo',
                      ],
                      'filter',
                      'filter' => function ($value) {
9870b2b4   Alexey Boroda   -In process
129
                          if (empty($value)) {
ae432de6   Alexey Boroda   first commit
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
                              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'),
                  'house'         => Yii::t('core', 'House'),
                  'street'        => Yii::t('core', 'Street'),
                  'office'        => Yii::t('core', 'Office'),
                  'city'          => Yii::t('core', 'City'),
                  'country'       => Yii::t('core', 'Country'),
                  'lat'           => Yii::t('core', 'Latitude'),
                  'lon'           => Yii::t('core', 'Longitude'),
                  'facebook'      => Yii::t('core', 'Facebook'),
                  'vk'            => Yii::t('core', 'VK'),
                  'google'        => Yii::t('core', 'Google'),
                  'twitter'       => Yii::t('core', 'Twitter'),
                  'logo'          => Yii::t('core', 'Company logo'),
                  'about'         => Yii::t('core', 'About us'),
                  'ok'            => Yii::t('core', 'Odnoklassniki'),
9870b2b4   Alexey Boroda   -In process
177
                  'index'         => Yii::t('core', 'Index'),
ae432de6   Alexey Boroda   first commit
178
179
              ];
          }
9870b2b4   Alexey Boroda   -In process
180
          
ae432de6   Alexey Boroda   first commit
181
182
183
184
185
186
187
          public function afterFind()
          {
              if ($this->logo === '') {
                  $this->logo = null;
              }
              parent::afterFind();
          }
9870b2b4   Alexey Boroda   -In process
188
          
ae432de6   Alexey Boroda   first commit
189
190
191
192
193
194
195
          /**
           * Get Settings model instance
           *
           * @return Settings
           */
          public static function getInstance()
          {
9870b2b4   Alexey Boroda   -In process
196
              if (empty(self::$instance)) {
ae432de6   Alexey Boroda   first commit
197
198
199
                  self::$instance = self::findOne([ 'id' => 1 ]);
                  return self::$instance;
              }
9870b2b4   Alexey Boroda   -In process
200
              
ae432de6   Alexey Boroda   first commit
201
202
203
204
              return self::$instance;
          }
      }