|
- <?php
-
- namespace backend\controllers;
-
- use Yii;
- use common\models\User;
- use common\models\Developpement;
- use yii\data\ActiveDataProvider;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use yii\filters\AccessControl;
-
- /**
- * DeveloppementController implements the CRUD actions for Developpement model.
- */
- class DeveloppementController extends Controller {
-
- /**
- * @inheritdoc
- */
- public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'allow' => true,
- 'roles' => ['@'],
- 'matchCallback' => function ($rule, $action) {
- return Yii::$app->user->identity->status == USER::STATUS_ADMIN
- || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
- }
- ]
- ],
- ],
- ];
- }
-
- /**
- * Lists all Developpement models.
- * @return mixed
- */
- public function actionIndex() {
- $dataProvider = new ActiveDataProvider([
- 'query' => Developpement::find(),
- ]);
-
- return $this->render('index', [
- 'dataProvider' => $dataProvider,
- ]);
- }
-
- /**
- * Creates a new Developpement model.
- * If creation is successful, the browser will be redirected to the 'view' page.
- * @return mixed
- */
- public function actionCreate() {
- $model = new Developpement();
-
- if ($model->load(Yii::$app->request->post())) {
- $model->date = date('Y-m-d H:i:s') ;
- $model->setDateLivraison() ;
- if($model->save()) {
- Yii::$app->getSession()->setFlash('success','Développement ajouté') ;
- return $this->redirect(['index']);
- }
- } else {
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- }
-
- /**
- * Updates an existing Developpement model.
- * If update is successful, the browser will be redirected to the 'view' page.
- * @param integer $id
- * @return mixed
- */
- public function actionUpdate($id) {
- $model = $this->findModel($id);
-
- if ($model->load(Yii::$app->request->post())) {
- $model->setDateLivraison() ;
- if($model->save()) {
- Yii::$app->getSession()->setFlash('success','Développement modifié') ;
- return $this->redirect(['index']);
- }
- } else {
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
- }
-
- /**
- * Deletes an existing Developpement model.
- * If deletion is successful, the browser will be redirected to the 'index' page.
- * @param integer $id
- * @return mixed
- */
- public function actionDelete($id) {
- $this->findModel($id)->delete();
- Yii::$app->getSession()->setFlash('success','Développement supprimé') ;
-
- return $this->redirect(['index']);
- }
-
- /**
- * Finds the Developpement model based on its primary key value.
- * If the model is not found, a 404 HTTP exception will be thrown.
- * @param integer $id
- * @return Developpement the loaded model
- * @throws NotFoundHttpException if the model cannot be found
- */
- protected function findModel($id) {
- if (($model = Developpement::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- }
|