Blame view

common/models/Customer.php 11.7 KB
182feb54   Anastasia   customer
1
2
3
4
5
  <?php
      
      namespace common\models;
      
      use Yii;
2beb82f0   Anastasia   register
6
      use yii\helpers\FileHelper;
10899280   alex   customer add crea...
7
      use yii\behaviors\TimestampBehavior;
08d25902   Alexey Boroda   -Send mail ready
8
      
182feb54   Anastasia   customer
9
10
11
      /**
       * This is the model class for table "customer".
       *
08d25902   Alexey Boroda   -Send mail ready
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
       * @property int      $id
       * @property string   $name
       * @property string   $secondname
       * @property string   $dignity
       * @property int      $gender
       * @property string   $birth
       * @property string   $citizenship
       * @property string   $passport
       * @property string   $email
       * @property string   $organization
       * @property int      $status
       * @property int      $language_id
       * @property string   $image
       * @property bool     $conference
       * @property bool     $geee
       * @property bool     $gere
5983654b   alex   ****WARNING ==> ...
28
       * New properties
08d25902   Alexey Boroda   -Send mail ready
29
30
31
32
       * @property  string  $phone_own
       * @property  string  $phone_office
       * @property  string  $phone_other
       * @property  string  $fax
5983654b   alex   ****WARNING ==> ...
33
34
       * @property  integer $passport_number
       * @property  integer $passport_date
08d25902   Alexey Boroda   -Send mail ready
35
       * @property  string  $passport_place
5983654b   alex   ****WARNING ==> ...
36
37
       * @property  integer $passport_valid
       * @property  boolean $need_visa
08d25902   Alexey Boroda   -Send mail ready
38
39
40
41
42
43
44
45
46
47
       * @property  string  $special_meal
       * @property boolean  $working_language_ru
       * @property boolean  $working_language_en
       * @property boolean  $working_language_fr
       * @property boolean  $meal_halal
       * @property boolean  $meal_kashrut
       * @property boolean  $meal_vegan
       * @property integer  $working_lang
       * @property string   $post_address ==> официальный почтовый адрес
       * @property integer  $created_at
8a7ade31   alex   Add new fields to...
48
49
50
51
52
53
54
55
56
       *
       * -- from 19.09
       * @property string $nationality
       * @property string $country_from
       * @property integer $user_work_status
       *
       *
       *
       *
182feb54   Anastasia   customer
57
58
59
       */
      class Customer extends \yii\db\ActiveRecord
      {
2beb82f0   Anastasia   register
60
          public $file;
08d25902   Alexey Boroda   -Send mail ready
61
          
5983654b   alex   ****WARNING ==> ...
62
          public $acceptance;
08d25902   Alexey Boroda   -Send mail ready
63
64
          
          const ADMIN_SCENARIO = 'admin';
8a7ade31   alex   Add new fields to...
65
66
67
68
  
  	    #----------------------------------------------------------------------
  	    #                   Текущий статус пользователя
  	    #----------------------------------------------------------------------
182feb54   Anastasia   customer
69
70
71
          const STATUS_NEW = 2;
          const STATUS_ACTIVE = 1;
          const STATUS_NO = 0;
8a7ade31   alex   Add new fields to...
72
73
74
75
  
  	    #----------------------------------------------------------------------
  	    #                  Специальная еда
  	    #----------------------------------------------------------------------
72471595   alex   1) Изменил содерж...
76
77
78
          const MEAL_1 = 'Халяль';
          const MEAL_2 = 'Кашрут';
          const MEAL_3 = 'Вегитарианець';
08d25902   Alexey Boroda   -Send mail ready
79
          const MEAL_NONE = 'Не выбрано';
8a7ade31   alex   Add new fields to...
80
81
82
83
84
  
  
  	    #----------------------------------------------------------------------
  	    #                            Пол
  	    #----------------------------------------------------------------------
41f1f148   Alexey Boroda   -Emails ready
85
86
          const MALE = '1';
          const FEMALE = '2';
8a7ade31   alex   Add new fields to...
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  
  
  
          #----------------------------------------------------------------------
  	    #                   Деловые статусы посетителя форума
          #----------------------------------------------------------------------
  
  	    const WORK_STATUS_0 = 'International organization';
  	    const WORK_STATUS_1 = 'Official delegation';
  	    const WORK_STATUS_2 = 'Non-government organization';
  	    const WORK_STATUS_3 = 'Expert';
  	    const WORK_STATUS_4 = 'Press';
  
  
182feb54   Anastasia   customer
101
102
103
104
105
106
107
          /**
           * {@inheritdoc}
           */
          public static function tableName()
          {
              return 'customer';
          }
08d25902   Alexey Boroda   -Send mail ready
108
          
10899280   alex   customer add crea...
109
110
          public function behaviors()
          {
08d25902   Alexey Boroda   -Send mail ready
111
112
113
114
115
116
              return [
                  [
                      'class'              => TimestampBehavior::className(),
                      'updatedAtAttribute' => false,
                  ],
              ];
10899280   alex   customer add crea...
117
          }
08d25902   Alexey Boroda   -Send mail ready
118
119
          
          /**
182feb54   Anastasia   customer
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
           * {@inheritdoc}
           */
          public function rules()
          {
              return [
                  [
                      [
                          'gender',
                          'status',
                          'language_id',
                      ],
                      'default',
                      'value' => null,
                  ],
                  [
                      [
                          'gender',
                          'status',
                          'language_id',
08d25902   Alexey Boroda   -Send mail ready
139
140
                          'acceptance',
                          'working_lang',
182feb54   Anastasia   customer
141
142
143
144
145
146
147
148
149
150
151
152
                      ],
                      'integer',
                  ],
                  [
                      [ 'organization' ],
                      'string',
                  ],
                  [
                      [
                          'conference',
                          'geee',
                          'gere',
08d25902   Alexey Boroda   -Send mail ready
153
154
155
156
157
158
159
160
                          'need_visa',
                          'working_language_ru',
                          'working_language_en',
                          'working_language_fr',
                          'meal_halal',
                          'meal_kashrut',
                          'meal_vegan',
                      
182feb54   Anastasia   customer
161
162
163
                      ],
                      'boolean',
                  ],
08d25902   Alexey Boroda   -Send mail ready
164
                  
182feb54   Anastasia   customer
165
166
167
168
169
170
171
172
173
174
                  [
                      [
                          'name',
                          'secondname',
                          'dignity',
                          'birth',
                          'citizenship',
                          'passport',
                          'email',
                          'image',
08d25902   Alexey Boroda   -Send mail ready
175
176
177
178
179
180
                          'passport_place',
                          'special_meal',
                          'passport_number',
                          'passport_date',
                          'passport_valid',
                          'post_address',
8a7ade31   alex   Add new fields to...
181
182
  	                    'nationality',
  	                    'country_from',
182feb54   Anastasia   customer
183
184
185
186
                      ],
                      'string',
                      'max' => 255,
                  ],
08d25902   Alexey Boroda   -Send mail ready
187
188
189
190
191
192
193
194
195
196
197
                  [
                      [
                          'phone_own',
                          'phone_office',
                          'phone_other',
                          'fax',
                      ],
                      'string',
                      'max' => 30,
                  ],
                  
182feb54   Anastasia   customer
198
199
200
201
202
203
204
205
                  [
                      [ 'gender' ],
                      'in',
                      'range' => [
                          self::MALE,
                          self::FEMALE,
                      ],
                  ],
8a7ade31   alex   Add new fields to...
206
207
208
209
210
  	            [
  		            [ 'user_work_status' ],
  		            'in',
  		            'range' => [
  			            '0',
f76bf49c   alex   little form and l...
211
212
213
  			            '1',
  			            '2',
  			            '3',
8a7ade31   alex   Add new fields to...
214
215
216
  			            '4',
  		            ],
  	            ],
182feb54   Anastasia   customer
217
218
219
220
221
                  [
                      [
                          'gender',
                          'organization',
                          'name',
5983654b   alex   ****WARNING ==> ...
222
                          #'secondname',
182feb54   Anastasia   customer
223
224
                          'birth',
                          'citizenship',
5983654b   alex   ****WARNING ==> ...
225
                          #'passport',
182feb54   Anastasia   customer
226
                          'email',
08d25902   Alexey Boroda   -Send mail ready
227
228
229
230
231
232
233
234
235
                          'post_address',
                          'passport_number',
                          'passport_date',
                          'passport_place',
                          'passport_valid',
                          'need_visa',
                          'phone_office',
                          'phone_other',
                          'need_visa',
8a7ade31   alex   Add new fields to...
236
237
  	                    'nationality',
  	                    'country_from',
f76bf49c   alex   little form and l...
238
  	                    'user_work_status',
182feb54   Anastasia   customer
239
240
241
                      ],
                      'required',
                  ],
08d25902   Alexey Boroda   -Send mail ready
242
243
244
245
246
247
248
249
250
251
252
253
254
                  [
                      [
                          'acceptance',
                      ],
                      'required',
                      'except' => self::ADMIN_SCENARIO,
                  ],
                  [
                      [
                          'phone_office',
                          'phone_other',
                      ],
                      'match',
8c5df6e2   alex   Изменил regex пат...
255
                      'pattern' => '#^\+?[\d\s]+$#',
08d25902   Alexey Boroda   -Send mail ready
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
                  ],
                  [
                      [ 'acceptance' ],
                      'compare',
                      'compareValue' => 1,
                  ],
                  [
                      'email',
                      'email',
                  ],
                  [
                      'file',
                      'file',
                      'skipOnEmpty'              => false,
                      'checkExtensionByMimeType' => false,
                      'extensions'               => [
                          'png',
                          'jpg',
                          'gif',
                      ],
                      'maxSize'                  => 1024 * 1024 * 1024 * 2,
                      'except'                   => self::ADMIN_SCENARIO,
                  ],
182feb54   Anastasia   customer
279
280
281
282
283
284
285
286
287
288
              
              ];
          }
          
          /**
           * {@inheritdoc}
           */
          public function attributeLabels()
          {
              return [
08d25902   Alexey Boroda   -Send mail ready
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
                  'id'              => Yii::t('app', 'ID'),
                  'name'            => Yii::t('app', 'Name'),
                  'secondname'      => Yii::t('app', 'Secondname'),
                  'dignity'         => Yii::t('app', 'Dignity'),
                  'gender'          => Yii::t('app', 'Gender'),
                  'birth'           => Yii::t('app', 'Birth'),
                  'citizenship'     => Yii::t('app', 'Citizenship'),
                  'passport'        => Yii::t('app', 'Passport'),
                  'email'           => Yii::t('app', 'Email'),
                  'organization'    => Yii::t('app', 'Organization'),
                  'status'          => Yii::t('app', 'Status'),
                  'language_id'     => Yii::t('app', 'Language ID'),
                  'image'           => Yii::t('app', 'Image'),
                  'conference'      => Yii::t('app', 'Conference'),
                  'geee'            => Yii::t('app', 'Geee'),
                  'gere'            => Yii::t('app', 'Gere'),
                  'need_visa'       => Yii::t('app', 'Need visa'),
                  'passport_number' => Yii::t('app', 'Passport number'),
                  'passport_date'   => Yii::t('app', 'Passport date'),
                  'passport_place'  => Yii::t('app', 'Passport place'),
                  'passport_valid'  => Yii::t('app', 'Passport valid'),
                  'phone_own'       => Yii::t('app', 'Phone own'),
                  'phone_office'    => Yii::t('app', 'Phone office'),
                  'phone_other'     => Yii::t('app', 'Phone other'),
                  'fax'             => Yii::t('app', 'fax'),
                  'acceptance'      => Yii::t('app', 'acceptance'),
                  'working_lang'    => Yii::t('app', 'Working language'),
                  'special_meal'    => Yii::t('app', 'Special meal'),
                  'post_address'    => Yii::t('app', 'Post address'),
8a7ade31   alex   Add new fields to...
318
319
320
321
322
  
                  'nationality'     => Yii::t('app', 'Nationality'),
                  'country_from'    => Yii::t('app', 'Country from'),
                  'user_work_status'    => Yii::t('app', 'Work status'),
  
182feb54   Anastasia   customer
323
324
              ];
          }
2beb82f0   Anastasia   register
325
          
f36f2e82   Anastasia   valid files
326
          public function upload()
2beb82f0   Anastasia   register
327
328
          {
              /**
08d25902   Alexey Boroda   -Send mail ready
329
               * @var \yii\web\UploadedFile $file ;
2beb82f0   Anastasia   register
330
               */
f36f2e82   Anastasia   valid files
331
              if (!empty($this->file) and $this->validate()) {
2beb82f0   Anastasia   register
332
333
334
                  if (!file_exists(\Yii::getAlias('@storage/customers/'))) {
                      FileHelper::createDirectory(\Yii::getAlias('@storage/customers/'));
                  }
08d25902   Alexey Boroda   -Send mail ready
335
336
337
338
339
                  $filename = $this->file->baseName . '_' . Yii::$app->security->generateRandomString(
                          5
                      ) . '.' . $this->file->extension;
                  if ($this->file->saveAs(\Yii::getAlias('@storage/customers/') . $filename)) {
                      $this->image = '/storage/customers/' . $filename;
5ff3d26f   Anastasia   images path
340
                      $this->file->name = $filename;
2beb82f0   Anastasia   register
341
342
343
                      return true;
                  }
                  return false;
08d25902   Alexey Boroda   -Send mail ready
344
                  
2beb82f0   Anastasia   register
345
346
347
              }
              return true;
          }
182feb54   Anastasia   customer
348
      }