|
- <?php
-
- namespace backend\controllers;
-
- use Yii;
- use common\models\User;
- use common\models\Developpement;
- use common\models\DeveloppementPriorite;
- use yii\data\ActiveDataProvider;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use yii\filters\AccessControl;
-
-
- class DeveloppementController extends Controller {
-
-
-
- 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;
- }
- ]
- ],
- ],
- ];
- }
-
-
-
- public function actionIndex() {
- $dataProvider = new ActiveDataProvider([
- 'query' => Developpement::find()->with(['developpementPriorite','developpementPrioriteCurrentEtablissement']),
- ]);
-
- return $this->render('index', [
- 'dataProvider' => $dataProvider,
- ]);
- }
-
-
-
- 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,
- ]);
- }
- }
-
-
-
- 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,
- ]);
- }
- }
-
-
-
- public function actionDelete($id) {
- $this->findModel($id)->delete();
- Yii::$app->getSession()->setFlash('success','Développement supprimé') ;
-
- return $this->redirect(['index']);
- }
-
- public function actionPriorite($id_developpement, $priorite = null) {
-
- $developpement_priorite = DeveloppementPriorite::find()
- ->where(['id_developpement' => $id_developpement, 'id_etablissement' => Yii::$app->user->identity->id_etablissement])
- ->one() ;
-
- if(in_array($priorite,
- [DeveloppementPriorite::PRIORITE_HAUTE,
- DeveloppementPriorite::PRIORITE_NORMALE,
- DeveloppementPriorite::PRIORITE_BASSE])) {
-
- if($developpement_priorite) {
- $developpement_priorite->priorite = $priorite ;
- $developpement_priorite->id_etablissement = Yii::$app->user->identity->id_etablissement ;
- }
- else {
- $developpement_priorite = new DeveloppementPriorite ;
- $developpement_priorite->id_developpement = $id_developpement ;
- $developpement_priorite->priorite = $priorite ;
- $developpement_priorite->id_etablissement = Yii::$app->user->identity->id_etablissement ;
- }
-
- $developpement_priorite->save() ;
- }
- else {
- if($developpement_priorite) {
- $developpement_priorite->delete() ;
- }
- }
-
- $this->redirect(['index']) ;
- }
-
-
-
- protected function findModel($id) {
- if (($model = Developpement::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- }
|