diff --git a/common/models/FeedbackCompany.php b/common/models/FeedbackCompany.php new file mode 100644 index 0000000..eb93589 --- /dev/null +++ b/common/models/FeedbackCompany.php @@ -0,0 +1,82 @@ + 255], + [['phone'], 'match', 'pattern' => '/^\+?(?:\d{0,3})?[\(\s]?\d{0,5}[\)\s]?\d{3}[-\s]?\d{2}[-\s]?\d{2}$/'], + [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id'], 'filter' => ['type' => 2]], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'feedback_company_id' => 'Feedback Company ID', + 'date_add' => Yii::t('app', 'Feedback date add'), + 'name' => Yii::t('app', 'Feedback name'), + 'phone' => Yii::t('app', 'Feedback phone'), + 'ip' => 'Ip', + 'user_id' => 'User ID', + 'status' => Yii::t('app', 'status'), + ]; + } + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::className(), + 'createdAtAttribute' => 'date_add', + 'updatedAtAttribute' => false, + ], + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getUser() + { + return $this->hasOne(User::className(), ['id' => 'user_id']); + } +} diff --git a/common/models/FeedbackCompanySearch.php b/common/models/FeedbackCompanySearch.php new file mode 100644 index 0000000..43e05f6 --- /dev/null +++ b/common/models/FeedbackCompanySearch.php @@ -0,0 +1,63 @@ +where([ 'user_id' => \Yii::$app->user->id ]); + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + $this->load($params); + + if(!$this->validate()) { + return $dataProvider; + } + + $query->andFilterWhere([ + 'like', + 'LOWER(name)', + mb_strtolower($this->name), + ]) + ->andFilterWhere([ + 'like', + 'LOWER(phone)', + mb_strtolower($this->phone), + ]); + + return $dataProvider; + + } + } diff --git a/console/migrations/m160519_124222_create_feedback_company.php b/console/migrations/m160519_124222_create_feedback_company.php new file mode 100644 index 0000000..6cd4f49 --- /dev/null +++ b/console/migrations/m160519_124222_create_feedback_company.php @@ -0,0 +1,36 @@ +createTable('feedback_company', [ + 'feedback_company_id' => $this->primaryKey(), + 'date_add' => $this->integer()->notNull(), + 'name' => $this->string()->notNull(), + 'phone' => $this->string()->notNull(), + 'ip' => $this->string()->notNull(), + 'user_id' => $this->integer()->notNull(), + 'status' => $this->integer()->notNull()->defaultValue(1), + ]); + + $this->addForeignKey('feedback_company_user', '{{%feedback_company}}', 'user_id', '{{%user}}', 'id', 'CASCADE', 'CASCADE'); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropForeignKey('feedback_company_user', '{{%feedback_company}}'); + $this->dropTable('feedback_company'); + } +} diff --git a/frontend/controllers/AccountsController.php b/frontend/controllers/AccountsController.php index 65df06d..bd05c35 100755 --- a/frontend/controllers/AccountsController.php +++ b/frontend/controllers/AccountsController.php @@ -8,6 +8,8 @@ use common\models\Currency; use common\models\Department; use common\models\Employment; + use common\models\FeedbackCompany; + use common\models\FeedbackCompanySearch; use common\models\Fields; use common\models\File; use common\models\Gallery; @@ -59,7 +61,6 @@ 'class' => AccessControl::className(), 'rules' => [ [ - //'actions' => ['cabinet','change-password', 'bookmarks', 'projects'], 'allow' => true, 'roles' => [ '@' ], ], @@ -74,6 +75,7 @@ 'projects-delete' => [ 'POST' ], 'blog-delete' => [ 'POST' ], 'gallery-cover' => [ 'POST' ], + 'feedback-delete' => [ 'POST' ], ], ], ]; @@ -288,6 +290,42 @@ } /** + * Page of Company feedback + * @return string + */ + public function actionFeedbackCompany() + { + $searchModel = new FeedbackCompanySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('feedback-company', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Delete company feedback + * @return string + */ + public function actionFeedbackDelete($id) + { + $model = FeedbackCompany::find() + ->where([ + 'feedback_company_id' => $id, + 'user_id' => \Yii::$app->user->id, + ]) + ->one(); + + if(empty($model)) { + throw new NotFoundHttpException('Заявка не найдена'); + } else { + $model->delete(); + return $this->redirect(['accounts/feedback-company']); + } + } + + /** * Page of User's image galleries * @return string */ diff --git a/frontend/controllers/AjaxController.php b/frontend/controllers/AjaxController.php index 3d9431b..af61f4c 100644 --- a/frontend/controllers/AjaxController.php +++ b/frontend/controllers/AjaxController.php @@ -2,6 +2,7 @@ namespace frontend\controllers; use common\models\Feedback; + use common\models\FeedbackCompany; use common\models\Portfolio; use common\models\PortfolioUser; use common\models\User; @@ -188,4 +189,18 @@ return ['error' => 'Error detected', 'result' => ['form' => $form]]; } + public function actionFeedbackCompany() + { + $request = \Yii::$app->request; + $response = \Yii::$app->response; + $response->format = $response::FORMAT_JSON; + $model = new FeedbackCompany(['ip' => $request->userIP]); + if($model->load($request->post())) { + if($model->save()) { + return ['result' => ['message' => 'Вопрос успешно отправлен, представители компании свяжутся с Вами в ближайшее время']]; + } + } + return ['error' => 'Ошибка формы']; + } + } diff --git a/frontend/messages/ru/app.php b/frontend/messages/ru/app.php index 416d162..fd507d9 100644 --- a/frontend/messages/ru/app.php +++ b/frontend/messages/ru/app.php @@ -10,7 +10,7 @@ 'description' => 'Описание', 'cover' => 'Фото главное', 'chat_id' => 'Chat ID', - 'status' => 'Status', + 'status' => 'Статус', 'comment' => 'Comment', 'from_user' => 'From User', 'to_user' => 'To User', diff --git a/frontend/views/accounts/feedback-company.php b/frontend/views/accounts/feedback-company.php new file mode 100644 index 0000000..e9abd01 --- /dev/null +++ b/frontend/views/accounts/feedback-company.php @@ -0,0 +1,62 @@ +title = 'Заявки'; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +