Blame view

common/models/Customer.php 8.68 KB
182feb54   Anastasia   customer
1
2
3
4
5
  <?php
      
      namespace common\models;
      
      use Yii;
2beb82f0   Anastasia   register
6
7
      use yii\helpers\FileHelper;
  
182feb54   Anastasia   customer
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
      /**
       * This is the model class for table "customer".
       *
       * @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 ==> ...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
       *
       *
       * New properties
       * @property  string $phone_own
       * @property  string $phone_office
       * @property  string $phone_other
       * @property  string $fax
       * @property  integer $passport_number
       * @property  integer $passport_date
       * @property  string $passport_place
       * @property  integer $passport_valid
       * @property  boolean $need_visa
       * @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
       *
83355b32   alex   Form changed 2
48
       * @property integer $working_lang
9d70b8a6   alex   1) добавил новые ...
49
       * @property string $post_address ==> официальный почтовый адрес
182feb54   Anastasia   customer
50
51
52
       */
      class Customer extends \yii\db\ActiveRecord
      {
2beb82f0   Anastasia   register
53
          public $file;
5983654b   alex   ****WARNING ==> ...
54
55
56
  
          public $acceptance;
  
182feb54   Anastasia   customer
57
58
59
          const STATUS_NEW = 2;
          const STATUS_ACTIVE = 1;
          const STATUS_NO = 0;
83355b32   alex   Form changed 2
60
  
72471595   alex   1) Изменил содерж...
61
62
63
64
          const MEAL_1 = 'Халяль';
          const MEAL_2 = 'Кашрут';
          const MEAL_3 = 'Вегитарианець';
  		const MEAL_NONE = 'Не выбрано';
83355b32   alex   Form changed 2
65
66
67
  
  
  
182feb54   Anastasia   customer
68
          
41f1f148   Alexey Boroda   -Emails ready
69
70
          const MALE = '1';
          const FEMALE = '2';
182feb54   Anastasia   customer
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
          /**
           * {@inheritdoc}
           */
          public static function tableName()
          {
              return 'customer';
          }
          
          /**
           * {@inheritdoc}
           */
          public function rules()
          {
              return [
                  [
                      [
                          'gender',
                          'status',
                          'language_id',
                      ],
                      'default',
                      'value' => null,
                  ],
                  [
                      [
                          'gender',
                          'status',
                          'language_id',
83355b32   alex   Form changed 2
99
100
  	                    'acceptance',
  	                    'working_lang'
182feb54   Anastasia   customer
101
102
103
104
105
106
107
108
109
110
111
112
                      ],
                      'integer',
                  ],
                  [
                      [ 'organization' ],
                      'string',
                  ],
                  [
                      [
                          'conference',
                          'geee',
                          'gere',
5983654b   alex   ****WARNING ==> ...
113
114
115
116
117
118
119
120
  	                    'need_visa',
  	                    'working_language_ru',
  	                    'working_language_en',
  	                    'working_language_fr',
  	                    'meal_halal',
  	                    'meal_kashrut',
  	                    'meal_vegan',
  
182feb54   Anastasia   customer
121
122
123
                      ],
                      'boolean',
                  ],
e3f07d67   alex   need visa теперь ...
124
  
182feb54   Anastasia   customer
125
126
127
128
129
130
131
132
133
134
                  [
                      [
                          'name',
                          'secondname',
                          'dignity',
                          'birth',
                          'citizenship',
                          'passport',
                          'email',
                          'image',
5983654b   alex   ****WARNING ==> ...
135
136
137
138
139
  	                    'passport_place',
  	                    'special_meal',
  	                    'passport_number',
  	                    'passport_date',
  	                    'passport_valid',
9d70b8a6   alex   1) добавил новые ...
140
  	                    'post_address'
182feb54   Anastasia   customer
141
142
143
144
                      ],
                      'string',
                      'max' => 255,
                  ],
5983654b   alex   ****WARNING ==> ...
145
146
147
148
149
150
151
152
153
154
155
  	            [
  	            	[
  	            		'phone_own',
  			            'phone_office',
  			            'phone_other',
  			            'fax'
  			        ],
  		            'string',
  		            'max' => 30,
  	            ],
  
182feb54   Anastasia   customer
156
157
158
159
160
161
162
163
164
165
166
167
168
                  [
                      [ 'gender' ],
                      'in',
                      'range' => [
                          self::MALE,
                          self::FEMALE,
                      ],
                  ],
                  [
                      [
                          'gender',
                          'organization',
                          'name',
5983654b   alex   ****WARNING ==> ...
169
                          #'secondname',
182feb54   Anastasia   customer
170
171
                          'birth',
                          'citizenship',
5983654b   alex   ****WARNING ==> ...
172
                          #'passport',
182feb54   Anastasia   customer
173
                          'email',
9d70b8a6   alex   1) добавил новые ...
174
  	                    'post_address',
5983654b   alex   ****WARNING ==> ...
175
176
177
178
179
  	                    'passport_number',
  	                    'passport_date',
  	                    'passport_place',
  	                    'passport_valid',
  	                    'need_visa',
72471595   alex   1) Изменил содерж...
180
181
182
  	                    'acceptance',
  	                    'phone_office',
  	                    'phone_other',
e3f07d67   alex   need visa теперь ...
183
  	                    'need_visa'
182feb54   Anastasia   customer
184
185
186
                      ],
                      'required',
                  ],
9d70b8a6   alex   1) добавил новые ...
187
188
189
  	            [['phone_office',
  		            'phone_other'
  		            ],'match','pattern'=>'#^[\d\s]+$#'],
5983654b   alex   ****WARNING ==> ...
190
191
192
193
194
  	            [
  	            	['acceptance'],
  		            'compare',
  		            'compareValue' => 1
  	            ],
182feb54   Anastasia   customer
195
                  ['email', 'email'],
2beb82f0   Anastasia   register
196
                  ['file', 'file', 'skipOnEmpty' => false, 'checkExtensionByMimeType'=>false,'extensions' => ['png', 'jpg', 'gif'], 'maxSize' => 1024*1024*1024*2]
182feb54   Anastasia   customer
197
198
199
200
201
202
203
204
205
206
              
              ];
          }
          
          /**
           * {@inheritdoc}
           */
          public function attributeLabels()
          {
              return [
5983654b   alex   ****WARNING ==> ...
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
                  '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'),
9b8b9f71   alex   Form changed 3
233
  	            'working_lang'              => Yii::t('app', 'Working language'),
2ab4ee29   alex   Form changed 4
234
  	            'special_meal'              => Yii::t('app', 'Special meal'),
9d70b8a6   alex   1) добавил новые ...
235
  	            'post_address'              => Yii::t('app', 'Post address'),
2ab4ee29   alex   Form changed 4
236
  
182feb54   Anastasia   customer
237
238
              ];
          }
2beb82f0   Anastasia   register
239
240
          
          
f36f2e82   Anastasia   valid files
241
          public function upload()
2beb82f0   Anastasia   register
242
243
244
245
          {
              /**
               * @var \yii\web\UploadedFile $file;
               */
f36f2e82   Anastasia   valid files
246
              if (!empty($this->file) and $this->validate()) {
2beb82f0   Anastasia   register
247
248
249
                  if (!file_exists(\Yii::getAlias('@storage/customers/'))) {
                      FileHelper::createDirectory(\Yii::getAlias('@storage/customers/'));
                  }
f36f2e82   Anastasia   valid files
250
251
                  $filename = $this->file->baseName.'_'.Yii::$app->security->generateRandomString(5).'.'.$this->file->extension;
  	            if ($this->file->saveAs(\Yii::getAlias('@storage/customers/') . $filename)) {
5ff3d26f   Anastasia   images path
252
253
                      $this->image = '/storage/customers/'.$filename;
                      $this->file->name = $filename;
2beb82f0   Anastasia   register
254
255
256
257
258
259
260
                      return true;
                  }
                  return false;
              
              }
              return true;
          }
182feb54   Anastasia   customer
261
      }