diff --git a/backend/config/main.php b/backend/config/main.php index 4683bf1..e00864a 100755 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -56,6 +56,9 @@ return [ 'interview' => [ 'class' => 'backend\modules\interview\Interview', ], + 'achievements' => [ + 'class' => 'backend\modules\achievements\Achievements', + ], ], 'components' => [ 'request' => [ diff --git a/backend/modules/achievements/Achievements.php b/backend/modules/achievements/Achievements.php new file mode 100755 index 0000000..fbb7d8e --- /dev/null +++ b/backend/modules/achievements/Achievements.php @@ -0,0 +1,24 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + 'access' => [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'allow' => true, + 'roles' => ['admin'], + ], + ], + ], + ]; + } + + /** + * Renders the index view for the module + * @return string + */ + public function actionIndex() + { + $searchModel = new AchievementSearch(); + + $dataProvider = $searchModel->search(); + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider + ]); + } + + /** + * Creates a new note model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Achievement(); + + if ($model->load(\Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('create', [ + 'model' => $model + ]); + } + + /** + * Displays a single note model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + $additionalDataProvider = new ActiveDataProvider([ + 'query' => FieldsValueNew::find() + ->where(['item_id' => $id, 'item_type' => FieldsValueNew::TYPE_NOTE]) + ->orderBy('order'), + 'pagination' => [ + 'pageSize' => 200, + ], + ]); + + $changeDataProvider = new ActiveDataProvider([ + 'query' => \common\models\ChangeHistory::find()->where(['type_id' => $this->findModel($id)->id]), + 'pagination' => [ + 'pageSize' => 200, + ] + ]); + + return $this->render('view', [ + 'model' => Achievement::findOne($id), + 'additionalDataProvider' => $additionalDataProvider, + 'changeDataProvider' => $changeDataProvider, + ]); + } + + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing Note model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the note model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Achievement the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Achievement::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/backend/modules/achievements/models/Achievement.php b/backend/modules/achievements/models/Achievement.php new file mode 100755 index 0000000..9d9262c --- /dev/null +++ b/backend/modules/achievements/models/Achievement.php @@ -0,0 +1,21 @@ + [ + 'class' => \common\behaviors\LogBehavior::class, + ] + ]; + } +} diff --git a/backend/modules/achievements/models/AchievementSearch.php b/backend/modules/achievements/models/AchievementSearch.php new file mode 100755 index 0000000..ca9761e --- /dev/null +++ b/backend/modules/achievements/models/AchievementSearch.php @@ -0,0 +1,58 @@ +request->queryParams; + $query = Achievement::find(); + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'status' => $this->status + ]); + + $query->andFilterWhere(['like', 'slug', $this->slug]) + ->andFilterWhere(['like', 'description', $this->description]) + ->andFilterWhere(['like', 'title', $this->title]); +// $query->orderBy('created_at DESC'); + + return $dataProvider; + } +} diff --git a/backend/modules/achievements/views/achievements/_form.php b/backend/modules/achievements/views/achievements/_form.php new file mode 100755 index 0000000..69e873c --- /dev/null +++ b/backend/modules/achievements/views/achievements/_form.php @@ -0,0 +1,50 @@ + + +
+ = Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?> +
+ + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], +// 'id', + 'title', + 'slug', + 'description', + [ + 'attribute' => 'status', + 'value' => function ($model) { + return \common\models\Achievement::getStatusLabel()[$model->status ?? 0]; + }, + 'filter' => kartik\select2\Select2::widget([ + 'model' => $searchModel, + 'attribute' => 'status', + 'data' => \common\models\Achievement::getStatusLabel(), + 'options' => ['placeholder' => 'Начните вводить...', 'class' => 'form-control'], + 'pluginOptions' => [ + 'allowClear' => true + ], + ]), + ], +// 'created_at', +// 'updated_at', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> ++ = Html::a('Список', ['index'], ['class' => 'btn btn-primary']) ?> + = Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> + = Html::a('Удалить', ['delete', 'id' => $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + 'title', + 'slug', + 'description:ntext', + [ + 'attribute' => 'status', + 'value' => \common\models\Achievement::getStatusLabel()[$model->status ?? 0], + ], + [ + 'attribute' => 'img', + 'format' => 'raw', + 'value' => function ($model) { + return Html::tag('img', null, ['src' => $model->img, 'width' => '100px']); + } + ], + ], + ]) ?> + +