Gestion de la priorité des développements suivant chaque établissement. Chaque producteur peut définir une priorité (basse, normale, haute) pour chaque développement.master
@@ -5,6 +5,7 @@ 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; | |||
@@ -44,7 +45,7 @@ class DeveloppementController extends Controller { | |||
*/ | |||
public function actionIndex() { | |||
$dataProvider = new ActiveDataProvider([ | |||
'query' => Developpement::find(), | |||
'query' => Developpement::find()->with(['developpementPriorite','developpementPrioriteCurrentEtablissement']), | |||
]); | |||
return $this->render('index', [ | |||
@@ -109,6 +110,39 @@ class DeveloppementController extends Controller { | |||
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']) ; | |||
} | |||
/** | |||
* Finds the Developpement model based on its primary key value. | |||
* If the model is not found, a 404 HTTP exception will be thrown. | |||
@@ -123,5 +157,5 @@ class DeveloppementController extends Controller { | |||
throw new NotFoundHttpException('The requested page does not exist.'); | |||
} | |||
} | |||
} |
@@ -3,6 +3,7 @@ | |||
use yii\helpers\Html; | |||
use yii\grid\GridView; | |||
use common\models\Developpement; | |||
use common\models\DeveloppementPriorite; | |||
use common\models\User; | |||
/* @var $this yii\web\View */ | |||
@@ -24,7 +25,12 @@ $this->params['breadcrumbs'][] = $this->title; | |||
<?php | |||
$columns = [ | |||
['class' => 'yii\grid\SerialColumn'], | |||
[ | |||
'header' => '#', | |||
'value' => function($model) { | |||
return '#'.$model->id ; | |||
} | |||
], | |||
[ | |||
'attribute' => 'type', | |||
'header' => 'Type', | |||
@@ -73,24 +79,62 @@ $this->params['breadcrumbs'][] = $this->title; | |||
return '' ; | |||
}], | |||
] ; | |||
if(Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER) { | |||
$columns[] = [ | |||
'header' => 'Priorité', | |||
'format' => 'raw', | |||
'value' => function($model) { | |||
$current_priorite = (isset($model->developpementPrioriteCurrentEtablissement)) ? $model->developpementPrioriteCurrentEtablissement->getStrPriorite() : 'Non' ; | |||
$style_bouton = (isset($model->developpementPrioriteCurrentEtablissement)) ? $model->developpementPrioriteCurrentEtablissement->getClassCssStyleBouton() : 'default' ; | |||
$html = '<div class="btn-group btn-group-priorite"> | |||
<button type="button" class="btn btn-priorite btn-sm btn-'.$style_bouton.' dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | |||
'.$current_priorite.' <span class="caret"></span> | |||
</button> | |||
<ul class="dropdown-menu"> | |||
<li><a href="'.Yii::$app->urlManager->createUrl(['developpement/priorite','id_developpement'=>$model->id]).'">Non</a></li> | |||
<li><a href="'.Yii::$app->urlManager->createUrl(['developpement/priorite','id_developpement'=>$model->id, 'priorite' => DeveloppementPriorite::PRIORITE_BASSE]).'">Basse</a></li> | |||
<li><a href="'.Yii::$app->urlManager->createUrl(['developpement/priorite','id_developpement'=>$model->id, 'priorite' => DeveloppementPriorite::PRIORITE_NORMALE]).'">Normale</a></li> | |||
<li><a href="'.Yii::$app->urlManager->createUrl(['developpement/priorite','id_developpement'=>$model->id, 'priorite' => DeveloppementPriorite::PRIORITE_HAUTE]).'">Haute</a></li> | |||
</ul> | |||
</div><br />' ; | |||
if(isset($model->developpementPriorite) && count($model->developpementPriorite)) { | |||
foreach($model->developpementPriorite as $developpement_priorite) { | |||
if($developpement_priorite->id_etablissement != Yii::$app->user->identity->id_etablissement) | |||
$html .= '<div class="label label-priorite label-sm label-'.$developpement_priorite->getClassCssStyleBouton().'">'.Html::encode($developpement_priorite->etablissement->nom).'</div> ' ; | |||
} | |||
} | |||
return $html ; | |||
} | |||
] ; | |||
} | |||
if(Yii::$app->user->identity->status == USER::STATUS_ADMIN) { | |||
if(Yii::$app->user->identity->status == USER::STATUS_ADMIN) { | |||
$columns[] = [ | |||
'class' => 'yii\grid\ActionColumn', | |||
'template' => '{update} {delete}', | |||
'template' => '{update}', | |||
'headerOptions' => ['class' => 'actions'], | |||
'buttons' => [ | |||
'update' => function ($url, $model) { | |||
return Html::a('<span class="glyphicon glyphicon-pencil"></span> Modifier', $url, [ | |||
'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default' | |||
]); | |||
return '<div class="btn-group"> | |||
<a href="'.$url.'" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span> Modifier</a> | |||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | |||
<span class="caret"></span> | |||
<span class="sr-only">Toggle Dropdown</span> | |||
</button> | |||
<ul class="dropdown-menu"> | |||
<li><a href="'.Yii::$app->urlManager->createUrl(['developpement/delete','id' => $model->id]).'" class=""><span class="glyphicon glyphicon-trash"></span> Supprimer</a></li> | |||
</ul> | |||
</div>' ; | |||
}, | |||
'delete' => function ($url, $model) { | |||
return Html::a('<span class="glyphicon glyphicon-trash"></span> Suprimer', $url, [ | |||
'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default' | |||
]); | |||
} | |||
], | |||
] ; | |||
} | |||
@@ -99,6 +143,7 @@ $this->params['breadcrumbs'][] = $this->title; | |||
<?= | |||
GridView::widget([ | |||
'id' => 'tab-developpements', | |||
'dataProvider' => $dataProvider, | |||
'columns' => $columns | |||
]); |
@@ -1212,3 +1212,22 @@ a:hover, a:focus, a:active { | |||
padding: 10px; | |||
text-align: center; | |||
} | |||
/* line 1230, ../sass/screen.scss */ | |||
.developpement-index #tab-developpements .btn-group-priorite { | |||
width: 100%; | |||
margin-bottom: 5px; | |||
} | |||
/* line 1234, ../sass/screen.scss */ | |||
.developpement-index #tab-developpements .btn-group-priorite .btn-priorite { | |||
display: block; | |||
float: none; | |||
width: 100%; | |||
} | |||
/* line 1241, ../sass/screen.scss */ | |||
.developpement-index #tab-developpements .label-priorite { | |||
display: block; | |||
width: 100%; | |||
margin-bottom: 2px; | |||
padding: 5px 8px; | |||
} |
@@ -1223,4 +1223,26 @@ a { | |||
padding: 10px ; | |||
text-align: center ; | |||
} | |||
} | |||
.developpement-index { | |||
#tab-developpements { | |||
.btn-group-priorite { | |||
width: 100% ; | |||
margin-bottom: 5px ; | |||
.btn-priorite { | |||
display: block ; | |||
float: none ; | |||
width: 100% ; | |||
} | |||
} | |||
.label-priorite { | |||
display: block ; | |||
width: 100% ; | |||
margin-bottom: 2px ; | |||
padding: 5px 8px ; | |||
} | |||
} | |||
} |
@@ -3,6 +3,7 @@ | |||
namespace common\models; | |||
use Yii; | |||
use common\models\DeveloppementPriorite ; | |||
/** | |||
* This is the model class for table "developpement". | |||
@@ -43,6 +44,14 @@ class Developpement extends \yii\db\ActiveRecord { | |||
[['objet', 'statut','type'], 'string', 'max' => 255], | |||
]; | |||
} | |||
public function getDeveloppementPriorite() { | |||
return $this->hasMany(DeveloppementPriorite::className(), ['id_developpement' => 'id'])->with('etablissement') ; | |||
} | |||
public function getDeveloppementPrioriteCurrentEtablissement() { | |||
return $this->hasOne(DeveloppementPriorite::className(), ['id_developpement' => 'id'])->where(['id_etablissement'=>Yii::$app->user->identity->id_etablissement])->with('etablissement') ; | |||
} | |||
/** | |||
* @inheritdoc |
@@ -3,6 +3,7 @@ | |||
namespace common\models; | |||
use Yii; | |||
use common\models\Etablissement ; | |||
/** | |||
* This is the model class for table "developpement_priorite". | |||
@@ -12,6 +13,10 @@ use Yii; | |||
*/ | |||
class DeveloppementPriorite extends \yii\db\ActiveRecord { | |||
const PRIORITE_HAUTE = 'haute' ; | |||
const PRIORITE_NORMALE = 'normale' ; | |||
const PRIORITE_BASSE = 'basse' ; | |||
/** | |||
* @inheritdoc | |||
*/ | |||
@@ -24,19 +29,48 @@ class DeveloppementPriorite extends \yii\db\ActiveRecord { | |||
*/ | |||
public function rules() { | |||
return [ | |||
[['id_user', 'id_developpement'], 'required'], | |||
[['id_user', 'id_developpement'], 'integer'], | |||
[['id_etablissement', 'id_developpement'], 'required'], | |||
[['id_etablissement', 'id_developpement'], 'integer'], | |||
[['priorite'], 'string'], | |||
]; | |||
} | |||
public function getEtablissement() { | |||
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']) ; | |||
} | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() { | |||
return [ | |||
'id_user' => 'Id User', | |||
'id_developpement' => 'Id Developpement', | |||
'id_etablissement' => 'Établissement', | |||
'id_developpement' => 'Développement', | |||
'priorite' => 'Priorité' | |||
]; | |||
} | |||
public function getStrPriorite() | |||
{ | |||
switch($this->priorite) | |||
{ | |||
case self::PRIORITE_BASSE : return 'Basse' ; break ; | |||
case self::PRIORITE_NORMALE : return 'Normale' ; break ; | |||
case self::PRIORITE_HAUTE : return 'Haute' ; break ; | |||
default: return 'Non définie' ; break ; | |||
} | |||
} | |||
public function getClassCssStyleBouton() { | |||
$style_bouton = 'default' ; | |||
if($this->priorite == DeveloppementPriorite::PRIORITE_BASSE) | |||
$style_bouton = 'info' ; | |||
elseif($this->priorite == DeveloppementPriorite::PRIORITE_NORMALE) | |||
$style_bouton = 'warning' ; | |||
elseif($this->priorite == DeveloppementPriorite::PRIORITE_HAUTE) | |||
$style_bouton = 'danger' ; | |||
return $style_bouton ; | |||
} | |||
} |
@@ -19,7 +19,7 @@ class m171226_200642_tables_developpement extends Migration { | |||
]); | |||
$this->createTable('developpement_priorite', [ | |||
'id_user' => Schema::TYPE_INTEGER . ' NOT NULL', | |||
'id_etablissement' => Schema::TYPE_INTEGER . ' NOT NULL', | |||
'id_developpement' => Schema::TYPE_INTEGER . ' NOT NULL', | |||
'PRIMARY KEY (`id_user`, `id_developpement`)' | |||
]); |
@@ -0,0 +1,17 @@ | |||
<?php | |||
use yii\db\Migration; | |||
use yii\db\Schema; | |||
use common\models\DeveloppementPriorite ; | |||
class m171227_090138_champs_priorite_developpement extends Migration { | |||
public function up() { | |||
$this->addColumn('developpement_priorite','priorite',Schema::TYPE_STRING.' DEFAULT \''.DeveloppementPriorite::PRIORITE_NORMALE.'\''); | |||
} | |||
public function down() { | |||
$this->dropColumn('developpement_priorite','priorite'); | |||
} | |||
} |