@@ -64,15 +64,15 @@ class ProducerBuilder extends AbstractBuilder | |||
/** | |||
* Lie un utilisateur à un producteur. | |||
*/ | |||
public function addUser(User $user, Producer $producer, int $bookmark = 1): UserProducer | |||
public function addUser(User $user, Producer $producer, bool $bookmark = true, bool $newsletter = true): UserProducer | |||
{ | |||
$userProducer = $this->userProducerBuilder->createUserProducerIfNotExist($user, $producer, $bookmark); | |||
$userProducer = $this->userProducerBuilder->createUserProducerIfNotExist($user, $producer, $bookmark, $newsletter); | |||
if (!$userProducer->getActive()) { | |||
$userProducer->setActive(1); | |||
$userProducer->setActive(true); | |||
} | |||
$this->saveUpdate($userProducer); | |||
$this->update($userProducer); | |||
return $userProducer; | |||
} |
@@ -19,11 +19,13 @@ class NewsletterUtils extends AbstractService implements UtilsInterface | |||
$this->userProducerBuilder = $this->loadService(UserProducerBuilder::class); | |||
} | |||
public function isUserSubscribedNewsletter(User $user): bool | |||
public function isUserSubscribedNewsletter(User $user = null): bool | |||
{ | |||
$userProducer = $this->userProducerRepository->findOneUserProducer($user); | |||
if($userProducer && $userProducer->newsletter) { | |||
return true; | |||
if($user) { | |||
$userProducer = $this->userProducerRepository->findOneUserProducer($user); | |||
if($userProducer && $userProducer->newsletter) { | |||
return true; | |||
} | |||
} | |||
return false; |
@@ -152,6 +152,13 @@ class UserProducer extends ActiveRecordCommon | |||
return $this; | |||
} | |||
public function setNewsletter(bool $newsletter): self | |||
{ | |||
$this->newsletter = $newsletter; | |||
return $this; | |||
} | |||
public function getCredit(): float | |||
{ | |||
return $this->credit; |
@@ -32,30 +32,31 @@ class UserProducerBuilder extends AbstractBuilder | |||
$this->orderSolver = $this->loadService(OrderSolver::class); | |||
} | |||
public function instanciateUserProducer(User $user, Producer $producer, int $bookmark = 1) | |||
public function instanciateUserProducer(User $user, Producer $producer, bool $bookmark = true, bool $newsletter = true) | |||
{ | |||
$userProducer = new UserProducer(); | |||
$userProducer->populateUser($user); | |||
$userProducer->populateproducer($producer); | |||
$userProducer->setCredit(0); | |||
$userProducer->setActive(1); | |||
$userProducer->setActive(true); | |||
$userProducer->setBookmark($bookmark); | |||
$userProducer->setNewsletter($newsletter); | |||
return $userProducer; | |||
} | |||
public function createUserProducer(User $user, Producer $producer, int $bookmark = 1): UserProducer | |||
public function createUserProducer(User $user, Producer $producer, bool $bookmark = true, bool $newsletter = true): UserProducer | |||
{ | |||
$userProducer = $this->instanciateUserProducer($user, $producer, $bookmark); | |||
$userProducer = $this->instanciateUserProducer($user, $producer, $bookmark, $newsletter); | |||
$this->create($userProducer); | |||
return $userProducer; | |||
} | |||
public function createUserProducerIfNotExist(User $user, Producer $producer, int $bookmark = 1): UserProducer | |||
public function createUserProducerIfNotExist(User $user, Producer $producer, bool $bookmark = true, bool $newsletter = true): UserProducer | |||
{ | |||
return $this->userProducerRepository->findOneUserProducer($user) | |||
?? $this->createUserProducer($user, $producer, $bookmark); | |||
?? $this->createUserProducer($user, $producer, $bookmark, $newsletter); | |||
} | |||
public function updateCredit(CreditHistory $creditHistory): void |
@@ -70,6 +70,7 @@ class SignupForm extends Model | |||
public $id_tax_rate_default; | |||
public $verifyCode; | |||
public $is_test; | |||
public $newsletter = true; | |||
/** | |||
* @inheritdoc | |||
@@ -96,7 +97,7 @@ class SignupForm extends Model | |||
[['name', 'lastname', 'phone', 'option_user_producer'], 'string', 'min' => 2, 'max' => 255], | |||
['password', 'required', 'message' => 'Champs obligatoire'], | |||
['password', 'string', 'min' => 6, 'tooShort' => 'Votre mot de passe doit contenir au moins 6 caractères'], | |||
['is_producer', 'boolean'], | |||
[['is_producer', 'newsletter'], 'boolean'], | |||
['cgv', 'boolean'], | |||
['cgv', function ($attribute, $params) { | |||
$cgv = $this->$attribute; | |||
@@ -222,6 +223,7 @@ class SignupForm extends Model | |||
// 'free_price' => 'Prix libre', | |||
'id_tax_rate_default' => 'TVA par défaut', | |||
'verifyCode' => 'Code de vérification', | |||
'newsletter' => "S'abonner au bulletin d'information de ce producteur" | |||
]; | |||
} | |||
@@ -253,7 +255,7 @@ class SignupForm extends Model | |||
\Yii::$app->logic->setProducerContext($producer); | |||
$producerManager->addUser($user, $producer); | |||
$producerManager->addUser($user, $producer, true, $this->newsletter); | |||
$userManager->sendEmailSignup($user, $producer); | |||
return $user; |
@@ -100,6 +100,7 @@ $this->setMeta('description', 'Veuillez vous connecter pour réserver les produi | |||
<?= $form->field($signupForm, 'lastname') ?> | |||
<?= $form->field($signupForm, 'name') ?> | |||
<?= $form->field($signupForm, 'phone') ?> | |||
<?= $form->field($signupForm, 'newsletter')->checkbox() ?> | |||
<?php if(strlen($producer->code)): ?> | |||
<?= $form->field($signupForm, 'code',[ | |||
'inputTemplate' => '<div class="input-group"><span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>{input}</div>', |
@@ -87,7 +87,9 @@ $this->params['breadcrumbs'][] = $this->title; | |||
<?= $form->field($model, 'cgv')->checkbox()->label('J\'accepte les <button type="button" class="btn btn-xs btn-default btn-modal-cgv" data-toggle="modal" data-target="#modal-cgv">conditions générales de service</button> et les <button type="button" class="btn btn-xs btn-default btn-modal-prices" data-toggle="modal" data-target="#modal-prices">conditions tarifaires</button>.') ?> | |||
</div> | |||
<div id="fields-user"> | |||
<?= $form->field($model, 'id_producer')->dropDownList($dataProducers, ['prompt' => '--','encode' => false,'options' => $optionsProducers]) ?> | |||
<?= $form->field($model, 'id_producer') | |||
->dropDownList($dataProducers, ['prompt' => '--','encode' => false,'options' => $optionsProducers]) ?> | |||
<?= $form->field($model, 'newsletter')->checkbox() ?> | |||
<div id="bloc-code-acces"> | |||
<?= $form->field($model, 'code',[ | |||
'inputTemplate' => '<div class="input-group"><span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>{input}</div>', |
@@ -197,8 +197,10 @@ function opendistrib_signup() { | |||
}); | |||
opendistrib_signup_code_producer(); | |||
opendistrib_signup_newsletter(); | |||
$('#signupform-id_producer').change(function () { | |||
opendistrib_signup_code_producer(); | |||
opendistrib_signup_newsletter(); | |||
}); | |||
// modals | |||
@@ -231,4 +233,16 @@ function opendistrib_signup_code_producer() { | |||
} | |||
} | |||
function opendistrib_signup_newsletter() { | |||
if($('#signupform-id_producer').length) { | |||
var $fieldNewsletter = $('.field-signupform-newsletter'); | |||
if($('#signupform-id_producer').val()) { | |||
$fieldNewsletter.show(); | |||
} | |||
else { | |||
$fieldNewsletter.hide(); | |||
} | |||
} | |||
} | |||
@@ -172,6 +172,7 @@ if (!Yii::$app->user->isGuest) { | |||
[ | |||
'label' => '<span class="glyphicon glyphicon-bullhorn"></span> Bulletin d\'information <span class="label label-'.($isUserSubscribedNewsletter ? 'success' : 'danger').'">'.($isUserSubscribedNewsletter ? 'Oui' : 'Non').'</span>', | |||
'url' => $this->getUrlManagerProducer()->createUrl(['newsletter/index']), | |||
'visible' => !Yii::$app->user->isGuest, | |||
'active' => $this->getControllerAction() == 'newsletter/index', | |||
], | |||
[ |