@@ -0,0 +1,127 @@ | |||
<?php | |||
namespace backend\controllers; | |||
use Yii; | |||
use common\models\User; | |||
use common\models\Developpement; | |||
use yii\data\ActiveDataProvider; | |||
use yii\web\Controller; | |||
use yii\web\NotFoundHttpException; | |||
use yii\filters\VerbFilter; | |||
use yii\filters\AccessControl; | |||
/** | |||
* DeveloppementController implements the CRUD actions for Developpement model. | |||
*/ | |||
class DeveloppementController extends Controller { | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function behaviors() | |||
{ | |||
return [ | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||
} | |||
] | |||
], | |||
], | |||
]; | |||
} | |||
/** | |||
* Lists all Developpement models. | |||
* @return mixed | |||
*/ | |||
public function actionIndex() { | |||
$dataProvider = new ActiveDataProvider([ | |||
'query' => Developpement::find(), | |||
]); | |||
return $this->render('index', [ | |||
'dataProvider' => $dataProvider, | |||
]); | |||
} | |||
/** | |||
* 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 Developpement(); | |||
if ($model->load(Yii::$app->request->post())) { | |||
$model->date = date('Y-m-d H:i:s') ; | |||
$model->setDateLivraison() ; | |||
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->setDateLivraison() ; | |||
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']); | |||
} | |||
/** | |||
* 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 = Developpement::findOne($id)) !== null) { | |||
return $model; | |||
} else { | |||
throw new NotFoundHttpException('The requested page does not exist.'); | |||
} | |||
} | |||
} |
@@ -0,0 +1,42 @@ | |||
<?php | |||
use yii\helpers\Html; | |||
use yii\widgets\ActiveForm; | |||
use common\models\Developpement ; | |||
/* @var $this yii\web\View */ | |||
/* @var $model common\models\Developpement */ | |||
/* @var $form yii\widgets\ActiveForm */ | |||
?> | |||
<div class="developpement-form"> | |||
<?php $form = ActiveForm::begin(); ?> | |||
<?= $form->field($model, 'type')->dropDownList([ | |||
Developpement::TYPE_EVOLUTION => 'Évolution', | |||
Developpement::TYPE_BUG => 'Anomalie', | |||
]) ?> | |||
<?= $form->field($model, 'statut')->dropDownList([ | |||
Developpement::STATUT_OPEN => 'Ouvert', | |||
Developpement::STATUT_CLOSED => 'Fermé', | |||
]) ?> | |||
<?= $form->field($model, 'objet')->textInput(['maxlength' => true]) ?> | |||
<?= $form->field($model, 'description')->textarea(['rows' => 6]) ?> | |||
<?= $form->field($model, 'estimation_temps')->textInput() ?> | |||
<?= $form->field($model, 'avancement')->textInput() ?> | |||
<?= $form->field($model, 'date_livraison')->textInput() ?> | |||
<div class="form-group"> | |||
<?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |||
</div> | |||
<?php ActiveForm::end(); ?> | |||
</div> |
@@ -0,0 +1,21 @@ | |||
<?php | |||
use yii\helpers\Html; | |||
/* @var $this yii\web\View */ | |||
/* @var $model common\models\Developpement */ | |||
$this->title = 'Ajouter un développement'; | |||
$this->params['breadcrumbs'][] = ['label' => 'Développement', 'url' => ['index']]; | |||
$this->params['breadcrumbs'][] = $this->title; | |||
?> | |||
<div class="developpement-create"> | |||
<h1><?= Html::encode($this->title) ?></h1> | |||
<?= $this->render('_form', [ | |||
'model' => $model, | |||
]) ?> | |||
</div> |
@@ -0,0 +1,106 @@ | |||
<?php | |||
use yii\helpers\Html; | |||
use yii\grid\GridView; | |||
use common\models\Developpement; | |||
use common\models\User; | |||
/* @var $this yii\web\View */ | |||
/* @var $dataProvider yii\data\ActiveDataProvider */ | |||
$this->title = 'Développement'; | |||
$this->params['breadcrumbs'][] = $this->title; | |||
?> | |||
<div class="developpement-index"> | |||
<h1><?= Html::encode($this->title) ?> <?= Html::a('Ajouter', ['create'], ['class' => 'btn btn-success']) ?></h1> | |||
<?php | |||
foreach (Yii::$app->session->getAllFlashes() as $key => $message) { | |||
echo '<div class="alert alert-' . $key . '">' . $message . '</div>'; | |||
} | |||
?> | |||
<?php | |||
$columns = [ | |||
['class' => 'yii\grid\SerialColumn'], | |||
[ | |||
'attribute' => 'type', | |||
'header' => 'Type', | |||
'format' => 'raw', | |||
'value' => function($model) { | |||
if($model->type == Developpement::TYPE_EVOLUTION) { | |||
return '<span class="label label-success">Évolution</span>' ; | |||
} | |||
else { | |||
return '<span class="label label-danger">Anomalie</span>' ; | |||
} | |||
} | |||
], | |||
[ 'attribute' => 'sujet', | |||
'format' => 'raw', | |||
'value' => function($model) { | |||
$html = '<strong>'.Html::encode($model->objet).'</strong>' ; | |||
if(strlen($model->description)) | |||
$html .= '<br />'.Html::encode($model->description) ; | |||
return $html ; | |||
}], | |||
[ 'attribute' => 'estimation_temps', | |||
'header' => 'Estimation', | |||
'format' => 'raw', | |||
'value' => function($model) { | |||
return intval($model->estimation_temps).' h' ; | |||
}], | |||
[ 'attribute' => 'avancement', | |||
'format' => 'raw', | |||
'value' => function($model) { | |||
if($model->avancement) | |||
return '<div class="progress"> | |||
<div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="'.intval($model->avancement).'" aria-valuemin="0" aria-valuemax="100" style="width: '.intval($model->avancement).'%;"> | |||
<span class="sr-only">'.intval($model->avancement).'% effectué</span> | |||
</div> | |||
</div> ' ; | |||
else | |||
return '' ; | |||
}], | |||
[ 'attribute' => 'date_livraison', | |||
'format' => 'raw', | |||
'value' => function($model) { | |||
if(strlen($model->date_livraison)) | |||
return date('d/m/Y',strtotime($model->date_livraison)) ; | |||
else | |||
return '' ; | |||
}], | |||
] ; | |||
if(Yii::$app->user->identity->status == USER::STATUS_ADMIN) { | |||
$columns[] = [ | |||
'class' => 'yii\grid\ActionColumn', | |||
'template' => '{update} {delete}', | |||
'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' | |||
]); | |||
}, | |||
'delete' => function ($url, $model) { | |||
return Html::a('<span class="glyphicon glyphicon-trash"></span> Suprimer', $url, [ | |||
'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default' | |||
]); | |||
} | |||
], | |||
] ; | |||
} | |||
?> | |||
<?= | |||
GridView::widget([ | |||
'dataProvider' => $dataProvider, | |||
'columns' => $columns | |||
]); | |||
?> | |||
</div> |
@@ -0,0 +1,21 @@ | |||
<?php | |||
use yii\helpers\Html; | |||
/* @var $this yii\web\View */ | |||
/* @var $model common\models\Developpement */ | |||
$this->title = 'Modifier un développement'; | |||
$this->params['breadcrumbs'][] = ['label' => 'Développement', 'url' => ['index']]; | |||
$this->params['breadcrumbs'][] = ['label' => '#'.$model->id, 'url' => ['update', 'id' => $model->id]]; | |||
$this->params['breadcrumbs'][] = 'Modifier'; | |||
?> | |||
<div class="developpement-update"> | |||
<h1><?= Html::encode($this->title) ?></h1> | |||
<?= $this->render('_form', [ | |||
'model' => $model, | |||
]) ?> | |||
</div> |
@@ -61,4 +61,13 @@ class Developpement extends \yii\db\ActiveRecord { | |||
]; | |||
} | |||
public function setDateLivraison($date = '') { | |||
if(strlen($date)) | |||
$this->date_livraison = $date ; | |||
if(strlen($this->date_livraison)) | |||
$this->date_livraison = date('Y-m-d',strtotime($this->date_livraison)) ; | |||
} | |||
} |