ソースを参照

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

prodstable
keun 8年前
コミット
f1edb4e6a6
10個のファイルの変更116行の追加18行の削除
  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. バイナリ
      frontend/web/uploads/fournil-gf-580884367d033.jpg
  8. バイナリ
      frontend/web/uploads/fournil-gf-5808844caa58b.jpg
  9. バイナリ
      frontend/web/uploads/logo-lechatdesnoisettes2-580884367c07d.png
  10. バイナリ
      frontend/web/uploads/logo-lechatdesnoisettes2-5808844ca9847.png

+ 3
- 16
backend/controllers/ProduitController.php ファイルの表示

@@ -15,6 +15,7 @@ use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\UploadedFile;
use common\helpers\Upload;


/**
@@ -129,8 +130,8 @@ class ProduitController extends Controller
$photo_filename_old = $model->photo ;
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) ;
if($delete_illustration) {
@@ -151,20 +152,6 @@ class ProduitController extends Controller
]);
}
}
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.

+ 34
- 0
backend/controllers/UserController.php ファイルの表示

@@ -10,6 +10,7 @@ use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\helpers\Upload ;

/**
* UserController implements the CRUD actions for User model.
@@ -109,6 +110,39 @@ class UserController extends Controller
]);
}
}
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.

+ 3
- 1
backend/views/layouts/main.php ファイルの表示

@@ -36,13 +36,15 @@ AppAsset::register($this);
['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-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],
];
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Connexion', 'url' => ['/site/login']];
} else {
$menuItems[] = [
'label' => '<span class="glyphicon glyphicon-off"></span> Déconnexion',
'label' => '<span class="glyphicon glyphicon-off"></span>',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
];

+ 47
- 0
backend/views/user/parametres.php ファイルの表示

@@ -0,0 +1,47 @@
<?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 ファイルの表示

@@ -0,0 +1,28 @@
<?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 ファイルの表示

@@ -56,7 +56,7 @@ class User extends ActiveRecord implements IdentityInterface
return [
['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'],
[['nom','prenom','telephone','adresse'], 'string'],
[['nom','prenom','telephone','adresse', 'description'], 'string'],
[['nom','prenom','email'],'required','message'=> 'Ce champs ne peut être vide'],
['email','email','message'=> 'Cette adresse email n\'est pas valide'],
['email','verifyEmail'],

バイナリ
frontend/web/uploads/fournil-gf-580884367d033.jpg ファイルの表示

変更前 変更後
幅: 851  |  高さ: 851  |  サイズ: 146KB

バイナリ
frontend/web/uploads/fournil-gf-5808844caa58b.jpg ファイルの表示

変更前 変更後
幅: 851  |  高さ: 851  |  サイズ: 146KB

バイナリ
frontend/web/uploads/logo-lechatdesnoisettes2-580884367c07d.png ファイルの表示

変更前 変更後
幅: 188  |  高さ: 53  |  サイズ: 3.9KB

バイナリ
frontend/web/uploads/logo-lechatdesnoisettes2-5808844ca9847.png ファイルの表示

変更前 変更後
幅: 188  |  高さ: 53  |  サイズ: 3.9KB

読み込み中…
キャンセル
保存