Browse Source

Adaptations refactoring/traduction backend/controllers/DeveloppementController > DevelopmentController

refactoring
Guillaume Bourgeois 6 years ago
parent
commit
d0780dd3d9
3 changed files with 63 additions and 33 deletions
  1. +35
    -33
      backend/controllers/DevelopmentController.php
  2. +14
    -0
      common/models/Development.php
  3. +14
    -0
      common/models/DevelopmentPriority.php

backend/controllers/DeveloppementController.php → backend/controllers/DevelopmentController.php View File



use Yii; use Yii;
use common\models\User; use common\models\User;
use common\models\Developpement;
use common\models\DeveloppementPriorite;
use common\models\Development;
use common\models\DevelopmentPriority;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
/** /**
* DeveloppementController implements the CRUD actions for Developpement model. * DeveloppementController implements the CRUD actions for Developpement model.
*/ */
class DeveloppementController extends Controller
class DevelopmentController extends Controller
{ {

/** /**
* @inheritdoc * @inheritdoc
*/ */
'allow' => true, 'allow' => true,
'roles' => ['@'], 'roles' => ['@'],
'matchCallback' => function ($rule, $action) { 'matchCallback' => function ($rule, $action) {
return Yii::$app->user->identity->status == USER::STATUS_ADMIN || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
return User::hasAccessBackend() ;
} }
] ]
], ],
* *
* @return mixed * @return mixed
*/ */
public function actionIndex($statut = Developpement::STATUT_OPEN)
public function actionIndex($status = Development::STATUT_OPEN)
{ {
$dataProvider = new ActiveDataProvider([ $dataProvider = new ActiveDataProvider([
'query' => Developpement::find()->with(['developpementPriorite', 'developpementPrioriteCurrentEtablissement'])->where(['statut' => $statut])->orderBy('date DESC'),
'query' => Development::find()
->with(['developmentPriority', 'developmentPriorityCurrentProducer'])
->where(['status' => $status])
->orderBy('date DESC'),
]); ]);


return $this->render('index', [ return $this->render('index', [
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'statut' => $statut
'status' => $status
]); ]);
} }


*/ */
public function actionCreate() public function actionCreate()
{ {
$model = new Developpement();
$model = new Development();


if ($model->load(Yii::$app->request->post())) { if ($model->load(Yii::$app->request->post())) {
$model->date = date('Y-m-d H:i:s'); $model->date = date('Y-m-d H:i:s');
$model->setDateLivraison();
$model->setDateDelivery();
if ($model->save()) { if ($model->save()) {
Yii::$app->getSession()->setFlash('success', 'Développement ajouté'); Yii::$app->getSession()->setFlash('success', 'Développement ajouté');
return $this->redirect(['index']); return $this->redirect(['index']);
} }
} else { } else {
return $this->render('create', [ return $this->render('create', [
'model' => $model,
'model' => $model,
]); ]);
} }
} }
/** /**
* Updates an existing Developpement model. * Updates an existing Developpement model.
* If update is successful, the browser will be redirected to the 'view' page. * If update is successful, the browser will be redirected to the 'view' page.
*
* @param integer $id * @param integer $id
* @return mixed * @return mixed
*/ */
$model = $this->findModel($id); $model = $this->findModel($id);


if ($model->load(Yii::$app->request->post())) { if ($model->load(Yii::$app->request->post())) {
$model->setDateLivraison();
$model->setDateDelivery();
if ($model->save()) { if ($model->save()) {
Yii::$app->getSession()->setFlash('success', 'Développement modifié'); Yii::$app->getSession()->setFlash('success', 'Développement modifié');
return $this->redirect(['index']); return $this->redirect(['index']);
} }
} else { } else {
return $this->render('update', [ return $this->render('update', [
'model' => $model,
'model' => $model,
]); ]);
} }
} }
/** /**
* Définit une priorité pour un développement. * Définit une priorité pour un développement.
* *
* @param integer $id_developpement
* @param integer $idDevelopment
* @param string $priorite * @param string $priorite
*/ */
public function actionPriorite($id_developpement, $priorite = null)
public function actionPriority($idDevelopment, $priority = null)
{ {
$develpmentPriority = DevelopmentPriority::searchOne([
'id_development' => $idDevelopment,
]) ;


$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 (in_array($priority, [DevelopmentPriority::PRIORITY_HIGH,
DevelopmentPriority::PRIORITY_NORMAL,
DevelopmentPriority::PRIORITY_LOW])) {


if ($developpement_priorite) {
$developpement_priorite->priorite = $priorite;
$developpement_priorite->id_etablissement = Yii::$app->user->identity->id_etablissement;
if ($develpmentPriority) {
$develpmentPriority->priority = $priorite;
$develpmentPriority->id_producer = Producer::getId();
} else { } 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;
$develpmentPriority = new DevelopmentPriority;
$develpmentPriority->id_development = $idDevelopment;
$develpmentPriority->priority = $priority;
$develpmentPriority->id_producer = Producer::getId();
} }


$developpement_priorite->save();
$develpmentPriority->save();
} else { } else {
if ($developpement_priorite) {
$developpement_priorite->delete();
if ($develpmentPriority) {
$develpmentPriority->delete();
} }
} }


*/ */
protected function findModel($id) protected function findModel($id)
{ {
if (($model = Developpement::findOne($id)) !== null) {
if (($model = Development::findOne($id)) !== null) {
return $model; return $model;
} else { } else {
throw new NotFoundHttpException('The requested page does not exist.'); throw new NotFoundHttpException('The requested page does not exist.');

+ 14
- 0
common/models/Development.php View File

]; ];
} }
/**
* Retourne les options de base nécessaires à la fonction de recherche.
*
* @return array
*/
public static function defaultOptionsSearch() {
return [
'with' => ['developmentPriority', 'developmentPriorityCurrentProducer'],
'join_with' => [],
'orderby' => 'date DESC',
'attribute_id_producer' => ''
] ;
}
/** /**
* Définit une date de livraison. * Définit une date de livraison.
* *

+ 14
- 0
common/models/DevelopmentPriority.php View File

'priority' => 'Priorité' 'priority' => 'Priorité'
]; ];
} }
/**
* Retourne les options de base nécessaires à la fonction de recherche.
*
* @return array
*/
public static function defaultOptionsSearch() {
return [
'with' => [],
'join_with' => [],
'orderby' => '',
'attribute_id_producer' => 'development_priority.id_producer'
] ;
}


/** /**
* Retourne la priorité. * Retourne la priorité.

Loading…
Cancel
Save