[ 'class' => AccessControl::className(), 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return User::hasAccessBackend() ; } ] ], ], ]; } /** * Liste les développements. * * @return mixed */ public function actionIndex($status = Development::STATUT_OPEN) { $dataProvider = new ActiveDataProvider([ 'query' => Development::find() ->with(['developmentPriority', 'developmentPriorityCurrentProducer']) ->where(['status' => $status]) ->orderBy('date DESC'), ]); return $this->render('index', [ 'dataProvider' => $dataProvider, 'status' => $status ]); } /** * 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 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, ]); } } /** * 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->setDateDelivery(); 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']); } /** * Définit une priorité pour un développement. * * @param integer $idDevelopment * @param string $priorite */ 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 = $priorite; $develpmentPriority->id_producer = Producer::getId(); } else { $develpmentPriority = new DevelopmentPriority; $develpmentPriority->id_development = $idDevelopment; $develpmentPriority->priority = $priority; $develpmentPriority->id_producer = Producer::getId(); } $develpmentPriority->save(); } else { if ($develpmentPriority) { $develpmentPriority->delete(); } } $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 = Development::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } }