diff --git a/composer.json b/composer.json index 7f29fa6..6b99d33 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "php": ">=5.4.0", "yiisoft/yii2": "~2.0.6", "yiisoft/yii2-bootstrap": "~2.0.0", - "yiisoft/yii2-swiftmailer": "~2.0.0" + "yiisoft/yii2-swiftmailer": "~2.0.0", + "bower-asset/remarkable-bootstrap-notify": "*" }, "require-dev": { "yiisoft/yii2-debug": "~2.0.0", diff --git a/frontend/assets/AppAsset.php b/frontend/assets/AppAsset.php index 9a27b92..36a554c 100644 --- a/frontend/assets/AppAsset.php +++ b/frontend/assets/AppAsset.php @@ -22,5 +22,6 @@ class AppAsset extends AssetBundle 'yii\web\JqueryAsset', 'yii\web\YiiAsset', 'yii\bootstrap\BootstrapAsset', + 'yii\bootstrap\BootstrapPluginAsset', ]; } diff --git a/frontend/assets/CabinetAsset.php b/frontend/assets/CabinetAsset.php index e67062b..677a37d 100644 --- a/frontend/assets/CabinetAsset.php +++ b/frontend/assets/CabinetAsset.php @@ -23,5 +23,6 @@ class CabinetAsset extends AssetBundle 'yii\web\YiiAsset', 'yii\bootstrap\BootstrapAsset', 'frontend\assets\AppAsset', + 'frontend\assets\NotifyAsset', ]; } diff --git a/frontend/assets/NotifyAsset.php b/frontend/assets/NotifyAsset.php new file mode 100644 index 0000000..3323e08 --- /dev/null +++ b/frontend/assets/NotifyAsset.php @@ -0,0 +1,20 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'personal' => ['post'], + ], + ], ]; } @@ -44,4 +51,55 @@ ]); } + public function actionPersonal() + { + $request = \Yii::$app->request; + $response = \Yii::$app->response; + $response->format = $response::FORMAT_JSON; + /** + * @var User $user + */ + $user = \Yii::$app->user->identity; + if(!$userData = $user->userData) { + $userData = new UserData(); + $userData->user_id = $user->id; + } + if($userData->load($request->post()) && $userData->save()) { + return [ + 'success' => true, + 'message' => 'Данные успешно сохранены', + ]; + } else { + return [ + 'error' => true, + 'message' => 'Ошибка сохранения данных', + ]; + } + } + + public function actionPassport() + { + $request = \Yii::$app->request; + $response = \Yii::$app->response; + $response->format = $response::FORMAT_JSON; + /** + * @var User $user + */ + $user = \Yii::$app->user->identity; + if(!$userPassport = $user->userPassport) { + $userPassport = new UserPassport(); + $userPassport->user_id = $user->id; + } + if($userPassport->load($request->post()) && $userPassport->save()) { + return [ + 'success' => true, + 'message' => 'Данные успешно сохранены', + ]; + } else { + return [ + 'error' => true, + 'message' => 'Ошибка сохранения данных', + ]; + } + } } diff --git a/frontend/models/UserData.php b/frontend/models/UserData.php index 5a1abae..d198070 100644 --- a/frontend/models/UserData.php +++ b/frontend/models/UserData.php @@ -1,67 +1,95 @@ 255, + ], + [ + [ 'user_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => User::className(), + 'targetAttribute' => [ 'user_id' => 'id' ], + ], + [ + [ 'phone' ], + 'match', + 'pattern' => '/\+38\s\(\d{3}\)\s\d{3}-\d{2}-\d{2}/', + ], + [ + ['email'], + 'email', + ] + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'user_id' => 'User ID', + 'name' => 'Ім\'я', + 'surname' => 'Прізвище', + 'patronymic' => 'По батькові', + 'phone' => 'Телефон', + 'email' => 'Email', + 'inn' => 'ІНН', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getUser() + { + return $this->hasOne(User::className(), [ 'id' => 'user_id' ]); + } } - - /** - * @inheritdoc - */ - public function rules() - { - return [ - [['user_id'], 'integer'], - [['name', 'surname', 'patronymic', 'phone', 'email', 'inn'], 'string', 'max' => 255], - [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'id' => 'ID', - 'user_id' => 'User ID', - 'name' => 'Name', - 'surname' => 'Surname', - 'patronymic' => 'Patronymic', - 'phone' => 'Phone', - 'email' => 'Email', - 'inn' => 'Inn', - ]; - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getUser() - { - return $this->hasOne(User::className(), ['id' => 'user_id']); - } -} diff --git a/frontend/models/UserPassport.php b/frontend/models/UserPassport.php index f1692cd..730ebe7 100644 --- a/frontend/models/UserPassport.php +++ b/frontend/models/UserPassport.php @@ -47,10 +47,10 @@ class UserPassport extends \yii\db\ActiveRecord return [ 'id' => 'ID', 'user_id' => 'User ID', - 'series' => 'Series', - 'number' => 'Number', - 'birthday' => 'Birthday', - 'given_by' => 'Given By', + 'series' => 'Серія', + 'number' => '№', + 'birthday' => 'Дата народження', + 'given_by' => 'Ким виданий', ]; } diff --git a/frontend/views/cabinet/_passport_form.php b/frontend/views/cabinet/_passport_form.php new file mode 100644 index 0000000..cd537ff --- /dev/null +++ b/frontend/views/cabinet/_passport_form.php @@ -0,0 +1,80 @@ + [ + 'class' => 'pjax_container forms-cabinet forms-2', + ], + ] + ); +?> +