Achievement model. Achievement CRUD pages. Achievements at sidebar
This commit is contained in:
151
backend/modules/achievements/controllers/AchievementsController.php
Executable file
151
backend/modules/achievements/controllers/AchievementsController.php
Executable file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\achievements\controllers;
|
||||
|
||||
use backend\modules\achievements\models\AchievementSearch;
|
||||
use common\models\Status;
|
||||
use Yii;
|
||||
use backend\modules\achievements\models\Achievement;
|
||||
use common\models\FieldsValueNew;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Default controller for the `achievements` module
|
||||
*/
|
||||
class AchievementsController extends Controller
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'verbs' => [
|
||||
'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.');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user