Преглед на файлове

Adaptations refactoring/traduction backend/controllers/DeveloppementController > DevelopmentController

refactoring
Guillaume Bourgeois преди 6 години
родител
ревизия
d0780dd3d9
променени са 3 файла, в които са добавени 63 реда и са изтрити 33 реда
  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 Целия файл

@@ -40,8 +40,8 @@ namespace backend\controllers;

use Yii;
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\web\Controller;
use yii\web\NotFoundHttpException;
@@ -51,9 +51,8 @@ use yii\filters\AccessControl;
/**
* DeveloppementController implements the CRUD actions for Developpement model.
*/
class DeveloppementController extends Controller
class DevelopmentController extends Controller
{

/**
* @inheritdoc
*/
@@ -66,7 +65,7 @@ class DeveloppementController extends Controller
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return Yii::$app->user->identity->status == USER::STATUS_ADMIN || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
return User::hasAccessBackend() ;
}
]
],
@@ -79,15 +78,18 @@ class DeveloppementController extends Controller
*
* @return mixed
*/
public function actionIndex($statut = Developpement::STATUT_OPEN)
public function actionIndex($status = Development::STATUT_OPEN)
{
$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', [
'dataProvider' => $dataProvider,
'statut' => $statut
'status' => $status
]);
}

@@ -98,18 +100,18 @@ class DeveloppementController extends Controller
*/
public function actionCreate()
{
$model = new Developpement();
$model = new Development();

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

if ($model->load(Yii::$app->request->post())) {
$model->setDateLivraison();
$model->setDateDelivery();
if ($model->save()) {
Yii::$app->getSession()->setFlash('success', 'Développement modifié');
return $this->redirect(['index']);
}
} else {
return $this->render('update', [
'model' => $model,
'model' => $model,
]);
}
}
@@ -154,34 +157,33 @@ class DeveloppementController extends Controller
/**
* Définit une priorité pour un développement.
*
* @param integer $id_developpement
* @param integer $idDevelopment
* @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 {
$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 {
if ($developpement_priorite) {
$developpement_priorite->delete();
if ($develpmentPriority) {
$develpmentPriority->delete();
}
}

@@ -197,7 +199,7 @@ class DeveloppementController extends Controller
*/
protected function findModel($id)
{
if (($model = Developpement::findOne($id)) !== null) {
if (($model = Development::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');

+ 14
- 0
common/models/Development.php Целия файл

@@ -122,6 +122,20 @@ class Development extends \yii\db\ActiveRecord
];
}
/**
* 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.
*

+ 14
- 0
common/models/DevelopmentPriority.php Целия файл

@@ -94,6 +94,20 @@ class DevelopmentPriority extends \yii\db\ActiveRecord
'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é.

Loading…
Отказ
Запис