$model = new Produit(); | $model = new Produit(); | ||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
self::uploadFile($model, 'illustration') ; | |||||
self::uploadFile($model, 'photo') ; | |||||
Upload::uploadFile($model, 'illustration') ; | |||||
Upload::uploadFile($model, 'photo') ; | |||||
$model->save() ; | |||||
// on ajoute un enregistrement ProductionProduit pour chaque production | // on ajoute un enregistrement ProductionProduit pour chaque production | ||||
$productions = Production::find()->where('date > '.date('Y-m-d'))->all() ; | $productions = Production::find()->where('date > '.date('Y-m-d'))->all() ; | ||||
foreach($productions as $prod) { | foreach($productions as $prod) { | ||||
$production_produit->actif = 0 ; | $production_produit->actif = 0 ; | ||||
$production_produit->save() ; | $production_produit->save() ; | ||||
} | } | ||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('create', [ | return $this->render('create', [ | ||||
$request = Yii::$app->request ; | $request = Yii::$app->request ; | ||||
$model = $this->findModel($id); | $model = $this->findModel($id); | ||||
$illustration_filename_old = $model->illustration ; | |||||
$photo_filename_old = $model->photo ; | |||||
$illustration_filename_old = $model->illustration ; | |||||
$photo_filename_old = $model->photo ; | |||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
Upload::uploadFile($model, 'illustration', $illustration_filename_old) ; | Upload::uploadFile($model, 'illustration', $illustration_filename_old) ; | ||||
Upload::uploadFile($model, 'photo', $photo_filename_old) ; | Upload::uploadFile($model, 'photo', $photo_filename_old) ; |
<?= $form->field($model, 'poids')->textInput() ?> | <?= $form->field($model, 'poids')->textInput() ?> | ||||
<?= $form->field($model, 'quantite_max')->textInput() ?> | <?= $form->field($model, 'quantite_max')->textInput() ?> | ||||
<?= $form->field($model, 'illustration')->fileInput() ?> | |||||
<?php | |||||
if(strlen($model->illustration)) { | |||||
echo '<img src="../../frontend/web/uploads/'.$model->illustration.'" width="200px" /><br />' ; | |||||
echo '<input type="checkbox" name="delete_illustration" id="delete_illustration" /> <label for="delete_illustration">Supprimer l\'illustration</label><br /><br />' ; | |||||
} | |||||
?> | |||||
<?= $form->field($model, 'photo')->fileInput() ?> | <?= $form->field($model, 'photo')->fileInput() ?> | ||||
<?php | <?php | ||||
if(strlen($model->photo)) { | if(strlen($model->photo)) { | ||||
<?= $form->field($model, 'samedi')->checkbox() ?> | <?= $form->field($model, 'samedi')->checkbox() ?> | ||||
<?= $form->field($model, 'dimanche')->checkbox() ?> | <?= $form->field($model, 'dimanche')->checkbox() ?> | ||||
<?= $form->field($model, 'id_etablissement')->hiddenInput()->label('') ?> | |||||
<div class="form-group"> | <div class="form-group"> | ||||
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | ||||
</div> | </div> |
public function save($runValidation = true, $attributeNames = NULL) | public function save($runValidation = true, $attributeNames = NULL) | ||||
{ | { | ||||
$this->id_etablissement = 0 ; | |||||
$this->id_etablissement = Yii::$app->user->identity->id_etablissement ; | |||||
$this->pain = 1 ; | $this->pain = 1 ; | ||||
return parent::save($runValidation, $attributeNames) ; | return parent::save($runValidation, $attributeNames) ; | ||||
} | } | ||||
} | } |
public function rules() | public function rules() | ||||
{ | { | ||||
return [ | return [ | ||||
[['nom'], 'required'], | |||||
[['actif','order','quantite_max'], 'integer'], | |||||
[['nom', 'id_etablissement'], 'required'], | |||||
[['actif','order','quantite_max', 'id_etablissement'], 'integer'], | |||||
[['lundi','mardi','mercredi','jeudi','vendredi','samedi','dimanche','epuise'], 'boolean'], | [['lundi','mardi','mercredi','jeudi','vendredi','samedi','dimanche','epuise'], 'boolean'], | ||||
[['prix', 'poids'], 'number'], | [['prix', 'poids'], 'number'], | ||||
[['illustration','photo'], 'file'], | [['illustration','photo'], 'file'], | ||||
[['nom', 'description', 'illustration', 'photo', 'saison','diminutif'], 'string', 'max' => 255], | [['nom', 'description', 'illustration', 'photo', 'saison','diminutif'], 'string', 'max' => 255], | ||||
[['recette'], 'string','max'=>1000], | [['recette'], 'string','max'=>1000], | ||||
['id_etablissement','integer'], | |||||
['id_etablissement','required'], | |||||
]; | ]; | ||||
} | } | ||||
public function save($runValidation = true, $attributeNames = NULL) | public function save($runValidation = true, $attributeNames = NULL) | ||||
{ | { | ||||
$this->id_etablissement = 0 ; | |||||
$this->id_etablissement = Yii::$app->user->identity->id_etablissement ; | |||||
return parent::save($runValidation, $attributeNames) ; | return parent::save($runValidation, $attributeNames) ; | ||||
} | } | ||||
} | } |