From 4ec01e3b5a3715458cf189028162ce4612b0783d Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 2 Jan 2018 18:07:29 +0200 Subject: [PATCH] -New feedback model --- frontend/controllers/FeedbackController.php | 2 +- frontend/models/Feedback.php | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 frontend/models/Feedback.php diff --git a/frontend/controllers/FeedbackController.php b/frontend/controllers/FeedbackController.php index ed4f29b..47d0c23 100644 --- a/frontend/controllers/FeedbackController.php +++ b/frontend/controllers/FeedbackController.php @@ -2,7 +2,7 @@ namespace frontend\controllers; - use artbox\core\models\Feedback; + use frontend\models\Feedback; use yii\filters\Cors; use yii\web\Controller; use yii\web\Response; diff --git a/frontend/models/Feedback.php b/frontend/models/Feedback.php new file mode 100644 index 0000000..326dff9 --- /dev/null +++ b/frontend/models/Feedback.php @@ -0,0 +1,123 @@ + TimestampBehavior::className(), + 'updatedAtAttribute' => false, + ], + [ + 'class' => AttributeBehavior::className(), + 'attributes' => [ + ActiveRecord::EVENT_BEFORE_INSERT => 'ip', + ], + 'value' => function () { + return \Yii::$app->request->userIP; + }, + ], + [ + 'class' => AttributeBehavior::className(), + 'attributes' => [ + ActiveRecord::EVENT_BEFORE_INSERT => 'url', + ], + 'value' => function () { + return \Yii::$app->request->referrer; + }, + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ + 'email', + ], + 'required', + ], + [ + [ 'email' ], + 'email', + ], + [ + [ + 'name', + 'phone', + 'email', + ], + 'string', + 'max' => 255, + ], + [ + [ + 'message', + ], + 'string', + ], + [ + [ + 'status', + ], + 'boolean', + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('core', 'id'), + 'name' => Yii::t('core', 'name'), + 'phone' => Yii::t('core', 'phone'), + 'created_at' => Yii::t('core', 'created_at'), + 'ip' => Yii::t('core', 'ip'), + 'url' => Yii::t('core', 'url'), + 'status' => Yii::t('core', 'status'), + 'message' => Yii::t('core', 'message'), + 'email' => Yii::t('core', 'email'), + ]; + } + } -- libgit2 0.21.4