diff --git a/backend/controllers/RequestController.php b/backend/controllers/RequestController.php index 1e9b899..35f5b74 100755 --- a/backend/controllers/RequestController.php +++ b/backend/controllers/RequestController.php @@ -16,18 +16,18 @@ 'index' => [ 'class' => Index::class, 'columns' => [ - 'id' => [ - 'type' => Index::NUMBER_COL, - - ], - 'name' => [ + 'id' => [ + 'type' => Index::NUMBER_COL, + + ], + 'name' => [ 'type' => Index::ACTION_COL, 'columnConfig' => [ #'buttonsTemplate' => '{edit}{delete}', 'buttonsTemplate' => '{edit}', ], ], - + 'organization' => [ 'type' => Index::STRING_COL, ], @@ -37,7 +37,7 @@ 'enableMassDelete' => true, 'modelPrimaryKey' => 'id', 'create' => false, - 'defaultSort' => ['id' => SORT_DESC] + 'defaultSort' => [ 'id' => SORT_DESC ], ], ]; } @@ -46,6 +46,23 @@ { $model = $this->findModel($id); + $model->scenario = Customer::ADMIN_SCENARIO; + + $request = \Yii::$app->request; + + $wasNew = (strval($model->status) === '2'); + + if ($request->isPost) { + if ($model->load($request->post()) && $model->save()) { + + if ($wasNew && (strval($model->status) === '1' )) { + $this->mail($model->email); + } + + return $this->redirect([ 'index' ]); + } + } + return $this->render( 'update', [ @@ -96,4 +113,8 @@ return false; } } + + public function mail($email) { + + } } \ No newline at end of file diff --git a/common/models/Customer.php b/common/models/Customer.php index eb244b8..8392769 100755 --- a/common/models/Customer.php +++ b/common/models/Customer.php @@ -5,71 +5,63 @@ use Yii; use yii\helpers\FileHelper; use yii\behaviors\TimestampBehavior; - - + /** * 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 - * - * + * @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 * New properties - * @property string $phone_own - * @property string $phone_office - * @property string $phone_other - * @property string $fax + * @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 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 - * - * @property integer $working_lang - * @property string $post_address ==> официальный почтовый адрес - * - * @property integer $created_at - * + * @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 */ class Customer extends \yii\db\ActiveRecord { public $file; - + public $acceptance; - + + const ADMIN_SCENARIO = 'admin'; + const STATUS_NEW = 2; const STATUS_ACTIVE = 1; const STATUS_NO = 0; - + const MEAL_1 = 'Халяль'; const MEAL_2 = 'Кашрут'; const MEAL_3 = 'Вегитарианець'; - const MEAL_NONE = 'Не выбрано'; - - - + const MEAL_NONE = 'Не выбрано'; const MALE = '1'; const FEMALE = '2'; @@ -80,21 +72,18 @@ { return 'customer'; } - - - + public function behaviors() { - return [ - [ - 'class' => TimestampBehavior::className(), - 'updatedAtAttribute' => false, - ], - ]; + return [ + [ + 'class' => TimestampBehavior::className(), + 'updatedAtAttribute' => false, + ], + ]; } - - - /** + + /** * {@inheritdoc} */ public function rules() @@ -114,8 +103,8 @@ 'gender', 'status', 'language_id', - 'acceptance', - 'working_lang' + 'acceptance', + 'working_lang', ], 'integer', ], @@ -128,18 +117,18 @@ 'conference', 'geee', 'gere', - 'need_visa', - 'working_language_ru', - 'working_language_en', - 'working_language_fr', - 'meal_halal', - 'meal_kashrut', - 'meal_vegan', - + 'need_visa', + 'working_language_ru', + 'working_language_en', + 'working_language_fr', + 'meal_halal', + 'meal_kashrut', + 'meal_vegan', + ], 'boolean', ], - + [ [ 'name', @@ -150,27 +139,27 @@ 'passport', 'email', 'image', - 'passport_place', - 'special_meal', - 'passport_number', - 'passport_date', - 'passport_valid', - 'post_address' + 'passport_place', + 'special_meal', + 'passport_number', + 'passport_date', + 'passport_valid', + 'post_address', ], 'string', 'max' => 255, ], - [ - [ - 'phone_own', - 'phone_office', - 'phone_other', - 'fax' - ], - 'string', - 'max' => 30, - ], - + [ + [ + 'phone_own', + 'phone_office', + 'phone_other', + 'fax', + ], + 'string', + 'max' => 30, + ], + [ [ 'gender' ], 'in', @@ -189,29 +178,55 @@ 'citizenship', #'passport', 'email', - 'post_address', - 'passport_number', - 'passport_date', - 'passport_place', - 'passport_valid', - 'need_visa', - 'acceptance', - 'phone_office', - 'phone_other', - 'need_visa' + 'post_address', + 'passport_number', + 'passport_date', + 'passport_place', + 'passport_valid', + 'need_visa', + 'phone_office', + 'phone_other', + 'need_visa', ], 'required', ], - [['phone_office', - 'phone_other' - ],'match','pattern'=>'#^[\d\s]+$#'], - [ - ['acceptance'], - 'compare', - 'compareValue' => 1 - ], - ['email', 'email'], - ['file', 'file', 'skipOnEmpty' => false, 'checkExtensionByMimeType'=>false,'extensions' => ['png', 'jpg', 'gif'], 'maxSize' => 1024*1024*1024*2] + [ + [ + 'acceptance', + ], + 'required', + 'except' => self::ADMIN_SCENARIO, + ], + [ + [ + 'phone_office', + 'phone_other', + ], + 'match', + 'pattern' => '#^[\d\s]+$#', + ], + [ + [ '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, + ], ]; } @@ -222,57 +237,58 @@ public function attributeLabels() { return [ - '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'), - + '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'), + ]; } - public function upload() { /** - * @var \yii\web\UploadedFile $file; + * @var \yii\web\UploadedFile $file ; */ if (!empty($this->file) and $this->validate()) { if (!file_exists(\Yii::getAlias('@storage/customers/'))) { FileHelper::createDirectory(\Yii::getAlias('@storage/customers/')); } - $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; + $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; $this->file->name = $filename; return true; } return false; - + } return true; } diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index b807c2d..bf910cd 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -241,7 +241,7 @@ ) ->setTo( [ - 'kennen.md@gmail.com', +// 'kennen.md@gmail.com', 'energyforum@euromediacompany.com', ] ) -- libgit2 0.21.4