diff --git a/common/models/FeedbackCompany.php b/common/models/FeedbackCompany.php index eb93589..60c1760 100644 --- a/common/models/FeedbackCompany.php +++ b/common/models/FeedbackCompany.php @@ -20,6 +20,9 @@ use yii\behaviors\TimestampBehavior; */ class FeedbackCompany extends \yii\db\ActiveRecord { + + const STATUS_NEW = 1; + const STATUS_READ = 2; /** * @inheritdoc */ diff --git a/common/models/FeedbackCompanySearch.php b/common/models/FeedbackCompanySearch.php index 43e05f6..ac978e5 100644 --- a/common/models/FeedbackCompanySearch.php +++ b/common/models/FeedbackCompanySearch.php @@ -12,6 +12,10 @@ class FeedbackCompanySearch extends FeedbackCompany { + public $date_add_from; + + public $date_add_to; + /** * @inheritdoc */ @@ -23,10 +27,21 @@ 'name', 'date_add', 'phone', - 'status', + 'date_add_from', + 'date_add_to', ], 'safe', ], + [ + [ 'status' ], + 'integer', + ], + [ + 'date_add_to', + 'compare', + 'compareAttribute' => 'date_add_from', + 'operator' => '>=', + ], ]; } @@ -55,7 +70,37 @@ 'like', 'LOWER(phone)', mb_strtolower($this->phone), - ]); + ]) + ->andFilterWhere([ 'status' => $this->status ]); + + $date_add_from = $this->date_add_from; + $date_add_to = $this->date_add_to; + if(!empty( $date_add_from )) { + $date_add_from = strtotime($date_add_from); + } + if(!empty( $date_add_to )) { + $date_add_to = strtotime($date_add_to) + 86400; + } + if(!empty( $date_add_from ) && !empty( $date_add_to )) { + $query->andWhere([ + 'between', + 'date_add', + $date_add_from, + $date_add_to, + ]); + } elseif(!empty( $date_add_from )) { + $query->andWhere([ + '>=', + 'date_add', + $date_add_from, + ]); + } elseif(!empty( $date_add_to )) { + $query->andWhere([ + '<=', + 'date_add', + $date_add_to, + ]); + } return $dataProvider; diff --git a/common/modules/fileloader/models/Fileloader.php b/common/modules/fileloader/models/Fileloader.php index 03eba2a..2a9d068 100644 --- a/common/modules/fileloader/models/Fileloader.php +++ b/common/modules/fileloader/models/Fileloader.php @@ -46,6 +46,7 @@ class Fileloader extends \yii\db\ActiveRecord public function rules() { return [ + [['files'], 'file', 'maxSize' => 5242880], [['status'], 'integer'], [['name'], 'string', 'max' => 50], [['dir'], 'string', 'max' => 255], diff --git a/common/modules/fileloader/resources/handler.js b/common/modules/fileloader/resources/handler.js index e9b9742..48a9d10 100644 --- a/common/modules/fileloader/resources/handler.js +++ b/common/modules/fileloader/resources/handler.js @@ -37,7 +37,6 @@ $(function() { } }); } - $(document).on('click', '.fileloader-item-remove', function(e) { var wrapper = $(this).parents('.fileloader-item-wrapper').first(); var id = $(wrapper).data('id'); diff --git a/frontend/controllers/AccountsController.php b/frontend/controllers/AccountsController.php index bd05c35..a264c24 100755 --- a/frontend/controllers/AccountsController.php +++ b/frontend/controllers/AccountsController.php @@ -42,6 +42,7 @@ use yii\filters\VerbFilter; use yii\web\Controller; use yii\web\NotFoundHttpException; + use yii\web\Response; use yii\web\UploadedFile; /** @@ -76,6 +77,7 @@ 'blog-delete' => [ 'POST' ], 'gallery-cover' => [ 'POST' ], 'feedback-delete' => [ 'POST' ], + 'feedback-read' => [ 'POST' ], ], ], ]; @@ -89,7 +91,14 @@ 'status' => 2, ]) ->count(); + $feedback_company_count = FeedbackCompany::find() + ->where([ + 'user_id' => \Yii::$app->user->id, + 'status' => FeedbackCompany::STATUS_NEW, + ]) + ->count(); $this->view->params[ 'portfolio_user_count' ] = $portfolio_user_count; + $this->view->params[ 'feedback_company_count' ] = $feedback_company_count; return parent::beforeAction($action); // TODO: Change the autogenerated stub } @@ -297,6 +306,15 @@ { $searchModel = new FeedbackCompanySearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + $dataProvider->pagination = [ + 'pageSize' => 20, + ]; + $dataProvider->sort = new Sort([ + 'defaultOrder' => [ + 'status' => SORT_ASC, + 'date_add' => SORT_DESC, + ], + ]); return $this->render('feedback-company', [ 'searchModel' => $searchModel, @@ -306,7 +324,12 @@ /** * Delete company feedback - * @return string + * + * @param int $id + * + * @return Response + * @throws NotFoundHttpException + * @throws \Exception */ public function actionFeedbackDelete($id) { @@ -317,11 +340,41 @@ ]) ->one(); - if(empty($model)) { + if(empty( $model )) { throw new NotFoundHttpException('Заявка не найдена'); } else { $model->delete(); - return $this->redirect(['accounts/feedback-company']); + return $this->redirect([ 'accounts/feedback-company' ]); + } + } + + /** + * Mark feedback as read + * + * @param int $id + * + * @return Response + * @throws NotFoundHttpException + */ + public function actionFeedbackRead($id) + { + $model = FeedbackCompany::find() + ->where([ + 'feedback_company_id' => $id, + 'user_id' => \Yii::$app->user->id, + ]) + ->andWhere([ + 'not', + [ 'status' => FeedbackCompany::STATUS_READ ], + ]) + ->one(); + + if(empty( $model )) { + throw new NotFoundHttpException('Заявка не найдена'); + } else { + $model->status = FeedbackCompany::STATUS_READ; + $model->save(false); + return $this->redirect([ 'accounts/feedback-company' ]); } } diff --git a/frontend/views/accounts/feedback-company.php b/frontend/views/accounts/feedback-company.php index e9abd01..0f7f91b 100644 --- a/frontend/views/accounts/feedback-company.php +++ b/frontend/views/accounts/feedback-company.php @@ -5,6 +5,7 @@ use yii\grid\GridView; use yii\grid\SerialColumn; use yii\helpers\Html; + use yii\jui\DatePicker; use yii\web\View; /** @@ -25,17 +26,52 @@ [ 'class' => SerialColumn::className() ], [ 'attribute' => 'date_add', - 'value' => function($model, $key) { + 'filter' => "