@@ -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. |
@@ -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. |
@@ -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'] | |||
]; |
@@ -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> | |||
@@ -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(); | |||
} | |||
} |
@@ -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'], |