Browse Source

Ajouter un formulaire dans le backend permettant au boulanger de modifier ses paramètres (logo, photo et description de la boulangerie)

master
keun 8 years ago
parent
commit
f1edb4e6a6
10 changed files with 116 additions and 18 deletions
  1. +3
    -16
      backend/controllers/ProduitController.php
  2. +34
    -0
      backend/controllers/UserController.php
  3. +3
    -1
      backend/views/layouts/main.php
  4. +47
    -0
      backend/views/user/parametres.php
  5. +28
    -0
      common/helpers/Upload.php
  6. +1
    -1
      common/models/User.php
  7. BIN
      frontend/web/uploads/fournil-gf-580884367d033.jpg
  8. BIN
      frontend/web/uploads/fournil-gf-5808844caa58b.jpg
  9. BIN
      frontend/web/uploads/logo-lechatdesnoisettes2-580884367c07d.png
  10. BIN
      frontend/web/uploads/logo-lechatdesnoisettes2-5808844ca9847.png

+ 3
- 16
backend/controllers/ProduitController.php View File

use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\web\UploadedFile; use yii\web\UploadedFile;
use common\helpers\Upload;




/** /**
$photo_filename_old = $model->photo ; $photo_filename_old = $model->photo ;
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
self::uploadFile($model, 'illustration', $illustration_filename_old) ;
self::uploadFile($model, 'photo', $photo_filename_old) ;
Upload::uploadFile($model, 'illustration', $illustration_filename_old) ;
Upload::uploadFile($model, 'photo', $photo_filename_old) ;
$delete_illustration = $request->post('delete_illustration',0) ; $delete_illustration = $request->post('delete_illustration',0) ;
if($delete_illustration) { if($delete_illustration) {
]); ]);
} }
} }
public static function uploadFile($model, $champs, $filename_old = '') {
$file = UploadedFile::getInstance($model, $champs);
if($file) {
$file_name = $file->baseName.'-'.uniqid().'.' . $file->extension ;
$file->saveAs('../../frontend/web/uploads/' . $file_name);
$model->$champs = $file_name ;
}
else {
$model->$champs = $filename_old ;
}
$model->save() ;
}


/** /**
* Deletes an existing Produit model. * Deletes an existing Produit model.

+ 34
- 0
backend/controllers/UserController.php View File

use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use common\helpers\Upload ;


/** /**
* UserController implements the CRUD actions for User model. * UserController implements the CRUD actions for User model.
]); ]);
} }
} }
public function actionParametres()
{
$request = Yii::$app->request ;
$model = $this->findModel(Yii::$app->user->identity->id);
$logo_filename_old = $model->logo ;
$photo_filename_old = $model->photo ;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Upload::uploadFile($model, 'logo', $logo_filename_old) ;
Upload::uploadFile($model, 'photo', $photo_filename_old) ;
$delete_logo = $request->post('delete_logo',0) ;
if($delete_logo) {
$model->logo = '' ;
$model->save() ;
}

$delete_photo = $request->post('delete_photo',0) ;
if($delete_photo) {
$model->photo = '' ;
$model->save() ;
}
return $this->redirect(['parametres', 'id' => $model->id, 'edit_ok' => true]);
} else {
return $this->render('parametres', [
'model' => $model,
]);
}
}


/** /**
* Deletes an existing User model. * Deletes an existing User model.

+ 3
- 1
backend/views/layouts/main.php View File

['label' => '<span class="glyphicon glyphicon-grain"></span> Produits', 'url' => ['/produit/index'], 'visible'=> !Yii::$app->user->isGuest], ['label' => '<span class="glyphicon glyphicon-grain"></span> Produits', 'url' => ['/produit/index'], 'visible'=> !Yii::$app->user->isGuest],
['label' => '<span class="glyphicon glyphicon-map-marker"></span> Points de vente', 'url' => ['/point-vente/index'], 'visible'=> !Yii::$app->user->isGuest], ['label' => '<span class="glyphicon glyphicon-map-marker"></span> Points de vente', 'url' => ['/point-vente/index'], 'visible'=> !Yii::$app->user->isGuest],
['label' => '<span class="glyphicon glyphicon-user"></span> Utilisateurs', 'url' => ['/user/index'], 'visible'=> !Yii::$app->user->isGuest], ['label' => '<span class="glyphicon glyphicon-user"></span> Utilisateurs', 'url' => ['/user/index'], 'visible'=> !Yii::$app->user->isGuest],
['label' => '<span class="glyphicon glyphicon-cog"></span> Paramètres', 'url' => ['/user/parametres'], 'visible'=> !Yii::$app->user->isGuest],
//['label' => 'Statistiques', 'url' => ['/stats/index'], 'visible'=> !Yii::$app->user->isGuest], //['label' => 'Statistiques', 'url' => ['/stats/index'], 'visible'=> !Yii::$app->user->isGuest],
]; ];
if (Yii::$app->user->isGuest) { if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Connexion', 'url' => ['/site/login']]; $menuItems[] = ['label' => 'Connexion', 'url' => ['/site/login']];
} else { } else {
$menuItems[] = [ $menuItems[] = [
'label' => '<span class="glyphicon glyphicon-off"></span> Déconnexion',
'label' => '<span class="glyphicon glyphicon-off"></span>',
'url' => ['/site/logout'], 'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post'] 'linkOptions' => ['data-method' => 'post']
]; ];

+ 47
- 0
backend/views/user/parametres.php View File

<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model common\models\User */

$this->title = 'Paramètres';
$this->params['breadcrumbs'][] = 'Paramètres';
?>
<div class="user-update">

<h1><?= Html::encode($this->title) ?></h1>

<div class="user-form">

<?php $form = ActiveForm::begin(); ?>

<?= $form->field($model, 'logo')->fileInput() ?>
<?php
if(strlen($model->logo)) {
echo '<img src="../../frontend/web/uploads/'.$model->logo.'" width="200px" /><br />' ;
echo '<input type="checkbox" name="delete_logo" id="delete_logo" /> <label for="delete_logo">Supprimer le logo</label><br /><br />' ;
}
?>
<?= $form->field($model, 'photo')->fileInput() ?>
<?php
if(strlen($model->photo)) {
echo '<img src="../../frontend/web/uploads/'.$model->photo.'" width="400px" /><br />' ;
echo '<input type="checkbox" name="delete_photo" id="delete_photo" /> <label for="delete_photo">Supprimer la photo</label><br /><br />' ;
}
?>

<?= $form->field($model, 'description')->textarea() ?>

<div class="form-group">
<?= Html::submitButton('Mettre à jour', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end(); ?>
</div>

</div>




+ 28
- 0
common/helpers/Upload.php View File

<?php

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

namespace common\helpers;

use yii\web\UploadedFile;

class Upload {

public static function uploadFile($model, $champs, $filename_old = '') {
$file = UploadedFile::getInstance($model, $champs);
if ($file) {
$file_name = $file->baseName . '-' . uniqid() . '.' . $file->extension;
$file->saveAs('../../frontend/web/uploads/' . $file_name);
$model->$champs = $file_name;
} else {
$model->$champs = $filename_old;
}

$model->save();
}

}

+ 1
- 1
common/models/User.php View File

return [ return [
['confiance','default','value'=>0], ['confiance','default','value'=>0],
[['no_mail','mail_prod_lundi','mail_prod_mardi','mail_prod_mercredi','mail_prod_jeudi','mail_prod_vendredi','mail_prod_samedi','mail_prod_dimanche'],'boolean'], [['no_mail','mail_prod_lundi','mail_prod_mardi','mail_prod_mercredi','mail_prod_jeudi','mail_prod_vendredi','mail_prod_samedi','mail_prod_dimanche'],'boolean'],
[['nom','prenom','telephone','adresse'], 'string'],
[['nom','prenom','telephone','adresse', 'description'], 'string'],
[['nom','prenom','email'],'required','message'=> 'Ce champs ne peut être vide'], [['nom','prenom','email'],'required','message'=> 'Ce champs ne peut être vide'],
['email','email','message'=> 'Cette adresse email n\'est pas valide'], ['email','email','message'=> 'Cette adresse email n\'est pas valide'],
['email','verifyEmail'], ['email','verifyEmail'],

BIN
frontend/web/uploads/fournil-gf-580884367d033.jpg View File

Before After
Width: 851  |  Height: 851  |  Size: 146KB

BIN
frontend/web/uploads/fournil-gf-5808844caa58b.jpg View File

Before After
Width: 851  |  Height: 851  |  Size: 146KB

BIN
frontend/web/uploads/logo-lechatdesnoisettes2-580884367c07d.png View File

Before After
Width: 188  |  Height: 53  |  Size: 3.9KB

BIN
frontend/web/uploads/logo-lechatdesnoisettes2-5808844ca9847.png View File

Before After
Width: 188  |  Height: 53  |  Size: 3.9KB

Loading…
Cancel
Save