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