|
- <?php
-
-
-
- namespace backend\controllers;
-
- use common\helpers\GlobalParam;
- use Yii;
- use common\models\User;
- use common\models\Development;
- use common\models\DevelopmentPriority;
- use yii\data\ActiveDataProvider;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use yii\filters\AccessControl;
-
-
- class DevelopmentController extends Controller
- {
-
-
- public function behaviors() {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'allow' => true,
- 'roles' => ['@'],
- 'matchCallback' => function ($rule, $action) {
- return User::hasAccessBackend() ;
- }
- ]
- ],
- ],
- ];
- }
-
-
-
- public function actionIndex($status = Development::STATUS_OPEN)
- {
- $dataProvider = new ActiveDataProvider([
- 'query' => Development::find()
- ->with(['developmentPriority', 'developmentPriorityCurrentProducer'])
- ->where(['status' => $status])
- ->orderBy('date DESC'),
- ]);
-
- return $this->render('index', [
- 'dataProvider' => $dataProvider,
- 'status' => $status
- ]);
- }
-
-
-
- public function actionCreate()
- {
- $model = new Development();
-
- if ($model->load(Yii::$app->request->post())) {
- $model->date = date('Y-m-d H:i:s');
- $model->setDateDelivery();
- 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->setDateDelivery();
- 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 actionPriority($idDevelopment, $priority = null)
- {
- $develpmentPriority = DevelopmentPriority::searchOne([
- 'id_development' => $idDevelopment,
- ]) ;
-
- if (in_array($priority, [DevelopmentPriority::PRIORITY_HIGH,
- DevelopmentPriority::PRIORITY_NORMAL,
- DevelopmentPriority::PRIORITY_LOW])) {
-
- if ($develpmentPriority) {
- $develpmentPriority->priority = $priority;
- $develpmentPriority->id_producer = GlobalParam::getCurrentProducerId();
- } else {
- $develpmentPriority = new DevelopmentPriority;
- $develpmentPriority->id_development = $idDevelopment;
- $develpmentPriority->priority = $priority;
- $develpmentPriority->id_producer = GlobalParam::getCurrentProducerId();
- }
-
- $develpmentPriority->save();
- } else {
- if ($develpmentPriority) {
- $develpmentPriority->delete();
- }
- }
-
- $this->redirect(['index']);
- }
-
-
-
- protected function findModel($id)
- {
- if (($model = Development::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- }
|