Browse Source

Gestion slug producer + lien UserProducer

refactoring
Guillaume Bourgeois 5 years ago
parent
commit
5fcff79e89
6 changed files with 24 additions and 12 deletions
  1. +1
    -1
      common/helpers/Url.php
  2. +1
    -1
      frontend/controllers/SiteController.php
  3. +0
    -1
      frontend/models/ProducerCodeForm.php
  4. +20
    -6
      frontend/models/SignupForm.php
  5. +1
    -2
      frontend/views/layouts/main.php
  6. +1
    -1
      frontend/views/site/producer_code.php

+ 1
- 1
common/helpers/Url.php View File

public static function slugify($string) public static function slugify($string)
{ {
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string)));
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '', $string)));
} }
} }

+ 1
- 1
frontend/controllers/SiteController.php View File

*/ */
public function actionProducerCode($id) public function actionProducerCode($id)
{ {
$producer = Producer::searchOne($id);
$producer = Producer::findOne($id);
if(!$producer) { if(!$producer) {
throw new \yii\web\HttpException(404, 'Producteur introuvable'); throw new \yii\web\HttpException(404, 'Producteur introuvable');

+ 0
- 1
frontend/models/ProducerCodeForm.php View File

['code', function($attribute, $params) { ['code', function($attribute, $params) {
$code = $this->$attribute; $code = $this->$attribute;
$producer = Producer::findOne($this->id_producer); $producer = Producer::findOne($this->id_producer);

if ($producer && strtolower(trim($code)) != strtolower(trim($producer->code))) { if ($producer && strtolower(trim($code)) != strtolower(trim($producer->code))) {
$this->addError($attribute, 'Code incorrect'); $this->addError($attribute, 'Code incorrect');
} }

+ 20
- 6
frontend/models/SignupForm.php View File

$producer->order_deadline = 20; $producer->order_deadline = 20;
$producer->order_delay = 1; $producer->order_delay = 1;
$producer->free_price = (float) abs($this->free_price); $producer->free_price = (float) abs($this->free_price);
$producer->slug = \common\helpers\Url::slugify($this->name_producer) ;

$cptSlug = 0 ;
do {
$slug = \common\helpers\Url::slugify($this->name_producer) ;
if($cptSlug) {
$slug .= $cptSlug ;
}
$producer->slug = $slug ;
$cptSlug ++ ;
} while(Producer::findOne(['slug' => $producer->slug])) ;


// génération d'un code // génération d'un code
do { do {
->setFrom([Yii::$app->params['adminEmail'] => 'distrib']) ->setFrom([Yii::$app->params['adminEmail'] => 'distrib'])
->setSubject('[distrib] Nouveau producteur') ->setSubject('[distrib] Nouveau producteur')
->send(); ->send();
$idProducer = $producer->id ;
}
else {
$idProducer = $this->id_producer ;
} }


$user->setPassword($this->password); $user->setPassword($this->password);
if ($user->save()) { if ($user->save()) {


// on ajoute l'établissement sélectionnée par l'user en favoris
if ($this->option_user_producer == 'user' && $this->id_producer) {
$producer = Producer::find()->where(['id' => $this->id_producer])->one();
$producer = Producer::find()->where(['id' => $idProducer])->one();


if ($producer) {
Producer::addUser($user->id, $this->id_producer) ;
if ($producer) {
Producer::addUser($user->id, $idProducer) ;


if($this->option_user_producer == 'user') {
// envoi d'un email à l'utilisateur // envoi d'un email à l'utilisateur
Yii::$app->mailer->compose( Yii::$app->mailer->compose(
[ [

+ 1
- 2
frontend/views/layouts/main.php View File

'options' => ['id' => 'li-producteurs'] 'options' => ['id' => 'li-producteurs']
], ],
[ [
'label' => '<span class="glyphicon glyphicon-flag"></span> Le Chat des Noisettes',
'label' => '<span class="glyphicon glyphicon-flag"></span> '.($producer ? Html::encode($producer->name) : ''),
'url' => '#', 'url' => '#',
'items' => [ 'items' => [
[ [
->where([ ->where([
'user_producer.id_user' => User::getCurrentId(), 'user_producer.id_user' => User::getCurrentId(),
'user_producer.bookmark' => 1, 'user_producer.bookmark' => 1,
'producer.active' => 1
]) ])
->all() ; ->all() ;
?> ?>

+ 1
- 1
frontend/views/site/producer_code.php View File

<h1 class="title-system-order"><?= Html::encode($producer->name) ?></h1> <h1 class="title-system-order"><?= Html::encode($producer->name) ?></h1>
<p class="info"><span class="alert alert-warning">Ce producteur est protègé par un code d'accès.</span></p> <p class="info"><span class="alert alert-warning">Ce producteur est protègé par un code d'accès.</span></p>
<?php $form = ActiveForm::begin(['id' => 'producer-code','enableClientValidation'=> false]); ?> <?php $form = ActiveForm::begin(['id' => 'producer-code','enableClientValidation'=> false]); ?>
<?= $form->field($modelProducerCode, 'code',[
<?= $form->field($producerCodeForm, 'code',[
'inputTemplate' => '<div class="input-group"><span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>{input}</div>', 'inputTemplate' => '<div class="input-group"><span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>{input}</div>',
]) ])
->label('Code du producteur') ->label('Code du producteur')

Loading…
Cancel
Save