Browse Source

Emails automatiques

feature/rotating_product
Guillaume Bourgeois 4 months ago
parent
commit
cc25240ecb
18 changed files with 181 additions and 76 deletions
  1. +7
    -3
      backend/controllers/CommunicateController.php
  2. +49
    -32
      backend/views/communicate/email.php
  3. +1
    -1
      backend/views/user/index.php
  4. +10
    -0
      backend/web/css/screen.css
  5. +13
    -0
      backend/web/sass/communication/_email.scss
  6. +1
    -0
      backend/web/sass/screen.scss
  7. +2
    -1
      console/commands/AutomaticEmailController.php
  8. +3
    -0
      domain/Communication/Email/ContactListResolver.php
  9. +6
    -0
      domain/User/User/NewsletterManager.php
  10. +3
    -1
      domain/User/User/UserRepository.php
  11. +6
    -3
      domain/User/User/UserSearch.php
  12. +18
    -2
      producer/controllers/NewsletterController.php
  13. +1
    -1
      producer/views/layouts/main.php
  14. +1
    -32
      producer/views/newsletter/index.php
  15. +24
    -0
      producer/web/css/screen.css
  16. +7
    -0
      producer/web/js/producer.js
  17. +28
    -0
      producer/web/sass/newsletter/_index.scss
  18. +1
    -0
      producer/web/sass/screen.scss

+ 7
- 3
backend/controllers/CommunicateController.php View File

use backend\models\MailForm; use backend\models\MailForm;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use domain\Communication\Email\ContactListResolver; use domain\Communication\Email\ContactListResolver;
use domain\Communication\Email\Email;
use domain\Communication\Email\EmailGenerator; use domain\Communication\Email\EmailGenerator;
use domain\PointSale\PointSale\PointSale; use domain\PointSale\PointSale\PointSale;
use kartik\mpdf\Pdf; use kartik\mpdf\Pdf;
$sectionInactiveUsers = 0, $sectionInactiveUsers = 0,
$usersPointSaleLink = 0, $usersPointSaleLink = 0,
$usersPointSaleHasOrder = 0, $usersPointSaleHasOrder = 0,
$idDistribution = 0)
{
$idDistribution = 0,
$newsletterType = null
) {
$emailModule = $this->getEmailModule(); $emailModule = $this->getEmailModule();


$mailForm = new MailForm(); $mailForm = new MailForm();


$usersArray = $emailModule->getContactListResolver()->search( $usersArray = $emailModule->getContactListResolver()->search(
$this->getProducerCurrent(), $this->getProducerCurrent(),
$newsletterType,
$distribution, $distribution,
$pointSale, $pointSale,
$usersPointSaleLink, $usersPointSaleLink,
$email = $emailModule->getGenerator()->createEmail( $email = $emailModule->getGenerator()->createEmail(
$mailForm->subject, $mailForm->subject,
$mailForm->message, $mailForm->message,
$mailForm->integrate_product_list,
(bool) $mailForm->integrate_product_list,
$this->getProducerCurrent(), $this->getProducerCurrent(),
$distribution $distribution
); );
'sectionInactiveUsers' => $sectionInactiveUsers, 'sectionInactiveUsers' => $sectionInactiveUsers,
'usersPointSaleLink' => $usersPointSaleLink, 'usersPointSaleLink' => $usersPointSaleLink,
'usersPointSaleHasOrder' => $usersPointSaleHasOrder, 'usersPointSaleHasOrder' => $usersPointSaleHasOrder,
'newsletterType' => $newsletterType,
]); ]);
} }



+ 49
- 32
backend/views/communicate/email.php View File

termes. termes.
*/ */


use domain\Communication\Email\Email;
use yii\helpers\Html ; use yii\helpers\Html ;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;




?> ?>


<div id="">
<div class="communication-email row">
<div class="col-md-8"> <div class="col-md-8">
<div class="panel panel-default">
<div id="panel-mail-form" class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title">Envoyer un email</h3> <h3 class="panel-title">Envoyer un email</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($mailForm, 'id_distribution')->dropDownList($incomingDistributionsDatesArray)
->hint("Sélectionnez une distribution pour ajouter automatiquement au message un lien vers la prise de commande de cette distribution"); ?>
<?= $form->field($mailForm, 'integrate_product_list')->checkbox() ; ?>
<?= $form->field($mailForm, 'subject')->textInput() ; ?>
<?php //$form->field($mailForm, 'message')->textarea(['rows' => '15']) ; ?>
<?= $form->field($mailForm, 'message')->widget(letyii\tinymce\Tinymce::class, [
'configs' => [
'plugins' => Yii::$app->parameterBag->get('tinyMcePlugins')
],
]); ?>
<div class="form-group form-buttons">
<?= Html::submitButton( 'Envoyer', ['class' => 'btn btn-primary']) ?>
<div class="newsletter-type">
<strong>Type d'email</strong>
<div>
<?php $linkParamsArray = ['idPointSale' => $idPointSaleActive, 'idDistribution' => $idDistributionActive, 'usersPointSaleLink' => $usersPointSaleLink, 'usersPointSaleHasOrder' => $usersPointSaleHasOrder, 'sectionSubscribers' => $sectionSubscribers, 'sectionInactiveUsers' => $sectionInactiveUsers]; ?>
<a class="btn <?= ($newsletterType == Email::TYPE_ORDER_TAKING) ? 'btn-primary' : 'btn-default'; ?>" href="<?= Yii::$app->urlManager->createUrl(['communicate/email', 'newsletterType' => Email::TYPE_ORDER_TAKING] + $linkParamsArray) ?>">Prise de commande</a>
<a class="btn <?= ($newsletterType == Email::TYPE_NEWSLETTER) ? 'btn-primary' : 'btn-default'; ?>" href="<?= Yii::$app->urlManager->createUrl(['communicate/email', 'newsletterType' => Email::TYPE_NEWSLETTER] + $linkParamsArray) ?>">Actualité</a>
</div>
</div> </div>
<?php ActiveForm::end(); ?>

<?php if($newsletterType): ?>
<?php $form = ActiveForm::begin(['enableClientValidation' => false]); ?>
<?php if($newsletterType == Email::TYPE_ORDER_TAKING): ?>
<?= $form->field($mailForm, 'id_distribution')->dropDownList($incomingDistributionsDatesArray)
->hint("Sélectionnez une distribution pour ajouter automatiquement au message un lien vers la prise de commande de cette distribution"); ?>
<?php endif; ?>
<?= $form->field($mailForm, 'subject')->textInput() ; ?>
<?= $form->field($mailForm, 'message')->widget(letyii\tinymce\Tinymce::class, [
'configs' => [
'plugins' => Yii::$app->parameterBag->get('tinyMcePlugins')
],
]); ?>
<?php if($newsletterType == Email::TYPE_ORDER_TAKING): ?>
<?= $form->field($mailForm, 'integrate_product_list')->checkbox() ; ?>
<?php endif; ?>
<div class="form-group form-buttons">
<?= Html::submitButton( 'Envoyer', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
<?php endif; ?>
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
Liste des emails <span class="label label-default"><?= count($usersArray); ?></span>
</h3>
</div>
<div class="panel-body">
<?php if($newsletterType): ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
Liste des emails <span class="label label-default"><?= count($usersArray); ?></span>
</h3>
</div>
<div class="panel-body">


<?php if($idPointSaleActive): ?>
<a class="btn btn-xs <?php if($usersPointSaleLink): ?>btn-primary<?php else: ?>btn-default<?php endif; ?>" href="<?= Yii::$app->urlManager->createUrl(['communicate/email','idPointSale' => $idPointSaleActive, 'idDistribution' => $idDistributionActive, 'usersPointSaleLink' => 1]); ?>">Liés au point de vente</a>
<a class="btn btn-xs <?php if($usersPointSaleHasOrder): ?>btn-primary<?php else: ?>btn-default<?php endif; ?>" href="<?= Yii::$app->urlManager->createUrl(['communicate/email','idPointSale' => $idPointSaleActive, 'idDistribution' => $idDistributionActive, 'usersPointSaleHasOrder' => 1]); ?>">Déjà commandés dans ce point de vente</a>
<br /><br />
<?php endif; ?>
<?php if($idPointSaleActive): ?>
<a class="btn btn-xs <?php if($usersPointSaleLink): ?>btn-primary<?php else: ?>btn-default<?php endif; ?>" href="<?= Yii::$app->urlManager->createUrl(['communicate/email','idPointSale' => $idPointSaleActive, 'idDistribution' => $idDistributionActive, 'usersPointSaleLink' => 1, 'newsletterType' => $newsletterType]); ?>">Liés au point de vente</a>
<a class="btn btn-xs <?php if($usersPointSaleHasOrder): ?>btn-primary<?php else: ?>btn-default<?php endif; ?>" href="<?= Yii::$app->urlManager->createUrl(['communicate/email','idPointSale' => $idPointSaleActive, 'idDistribution' => $idDistributionActive, 'usersPointSaleHasOrder' => 1, 'newsletterType' => $newsletterType]); ?>">Déjà commandés dans ce point de vente</a>
<br /><br />
<?php endif; ?>


<?= implode(', ', array_map(function($user) {
return $user['email'];
}, $usersArray)); ?>
<?= implode(', ', array_map(function($user) {
return $user['email'];
}, $usersArray)); ?>
</div>
</div> </div>
</div>
<?php endif; ?>
</div> </div>
<div class="clr"></div> <div class="clr"></div>
</div> </div>

+ 1
- 1
backend/views/user/index.php View File

1 => 'Oui' 1 => 'Oui'
], ],
'value' => function ($user) use ($userModule) { 'value' => function ($user) use ($userModule) {
if($userModule->isUserSubscribedNewsletter($user)) {
if($userModule->getNewsletterManager()->isUserSubscribedOneNewsletter($user)) {
return '<span class="label label-success">Oui</span>'; return '<span class="label label-success">Oui</span>';
} }
return '<span class="label label-danger">Non</span>'; return '<span class="label label-danger">Non</span>';

+ 10
- 0
backend/web/css/screen.css View File

display: block; display: block;
} }


/* line 5, ../sass/communication/_email.scss */
.communication-email #panel-mail-form .newsletter-type {
margin-bottom: 20px;
}
/* line 7, ../sass/communication/_email.scss */
.communication-email #panel-mail-form .newsletter-type strong {
display: block;
margin-bottom: 5px;
}

/** /**
Copyright Souke (2018) Copyright Souke (2018)



+ 13
- 0
backend/web/sass/communication/_email.scss View File



.communication-email {
#panel-mail-form {
.newsletter-type {
margin-bottom: 20px;
strong {
display: block;
margin-bottom: 5px;
}
}
}
}

+ 1
- 0
backend/web/sass/screen.scss View File

@import "setting/_form.scss"; @import "setting/_form.scss";
@import "dashboard-admin/_index.scss" ; @import "dashboard-admin/_index.scss" ;
@import "automatic-email/_form.scss" ; @import "automatic-email/_form.scss" ;
@import "communication/_email.scss" ;
@import "_responsive.scss" ; @import "_responsive.scss" ;

+ 2
- 1
console/commands/AutomaticEmailController.php View File

namespace console\commands; namespace console\commands;


use domain\Communication\AutomaticEmail\AutomaticEmailModule; use domain\Communication\AutomaticEmail\AutomaticEmailModule;
use domain\Communication\Email\Email;
use domain\Communication\Email\EmailModule; use domain\Communication\Email\EmailModule;
use domain\Producer\Producer\ProducerModule; use domain\Producer\Producer\ProducerModule;
use yii\console\Controller; use yii\console\Controller;
$distribution = $automaticEmailModule->getResolver()->getMatchedDistribution($automaticEmail); $distribution = $automaticEmailModule->getResolver()->getMatchedDistribution($automaticEmail);
if($distribution) { if($distribution) {
$email = $automaticEmailModule->getManager()->createEmailFromAutomaticEmail($automaticEmail, $distribution); $email = $automaticEmailModule->getManager()->createEmailFromAutomaticEmail($automaticEmail, $distribution);
$usersArray = $emailModule->getContactListResolver()->search($producer, $distribution);
$usersArray = $emailModule->getContactListResolver()->search($producer, Email::TYPE_ORDER_TAKING, $distribution);
$emailModule->getBulkMailer()->sendEmail($email, $usersArray); $emailModule->getBulkMailer()->sendEmail($email, $usersArray);
echo 'Email automatique "'.$automaticEmail->getSubject().'" envoyé à '.count($usersArray)." utilisateur(s)\n"; echo 'Email automatique "'.$automaticEmail->getSubject().'" envoyé à '.count($usersArray)." utilisateur(s)\n";
} }

+ 3
- 0
domain/Communication/Email/ContactListResolver.php View File



public function search( public function search(
Producer $producer, Producer $producer,
string $newsletterType = null,
Distribution $distribution = null, Distribution $distribution = null,
PointSale $pointSale = null, PointSale $pointSale = null,
bool $usersPointSaleLink = false, bool $usersPointSaleLink = false,
'id_point_sale' => $pointSaleDistribution->id_point_sale, 'id_point_sale' => $pointSaleDistribution->id_point_sale,
'users_point_sale_link' => $usersPointSaleLink, 'users_point_sale_link' => $usersPointSaleLink,
'users_point_sale_has_order' => $usersPointSaleHasOrder, 'users_point_sale_has_order' => $usersPointSaleHasOrder,
'newsletter_type' => $newsletterType,
'newsletter' => true 'newsletter' => true
])->all(); ])->all();


'users_point_sale_has_order' => $usersPointSaleHasOrder, 'users_point_sale_has_order' => $usersPointSaleHasOrder,
'subscribers' => $isSubscriber, 'subscribers' => $isSubscriber,
'inactive' => $isInactive, 'inactive' => $isInactive,
'newsletter_type' => $newsletterType,
'newsletter' => true 'newsletter' => true
])->all(); ])->all();
} }

+ 6
- 0
domain/User/User/NewsletterManager.php View File

return false; return false;
} }


public function isUserSubscribedOneNewsletter(User $user): bool
{
return $this->isUserSubscribedNewsletter($user, Email::TYPE_NEWSLETTER)
|| $this->isUserSubscribedNewsletter($user, Email::TYPE_ORDER_TAKING);
}

public function manageUserNewsletter(User $user, ?bool $newsletter, ?bool $newsletterOrderTaking) public function manageUserNewsletter(User $user, ?bool $newsletter, ?bool $newsletterOrderTaking)
{ {
if($newsletter) { if($newsletter) {

+ 3
- 1
domain/User/User/UserRepository.php View File

namespace domain\User\User; namespace domain\User\User;


use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use domain\Communication\Email\Email;
use domain\PointSale\PointSale\PointSale; use domain\PointSale\PointSale\PointSale;
use domain\Producer\Producer\Producer; use domain\Producer\Producer\Producer;
use domain\User\UserProducer\UserProducerRepository; use domain\User\UserProducer\UserProducerRepository;
->from('user'); ->from('user');


$active = (isset($params['inactive']) && $params['inactive']) ? 0 : 1; $active = (isset($params['inactive']) && $params['inactive']) ? 0 : 1;
$filterNewsletter = (isset($params['newsletter']) && $params['newsletter']) ? 'AND user_producer.newsletter = 1' : '';
$fieldNewsletter = (isset($params['newsletter_type']) && $params['newsletter_type'] == Email::TYPE_ORDER_TAKING) ? 'newsletter_order_taking' : 'newsletter';;
$filterNewsletter = (isset($params['newsletter']) && $params['newsletter']) ? 'AND user_producer.'.$fieldNewsletter.' = 1' : '';
$query->innerJoin('user_producer', 'user.id = user_producer.id_user AND user_producer.active = ' . $active . ' '.$filterNewsletter.' AND user_producer.id_producer = :id_producer', [':id_producer' => $params['id_producer']]); $query->innerJoin('user_producer', 'user.id = user_producer.id_user AND user_producer.active = ' . $active . ' '.$filterNewsletter.' AND user_producer.id_producer = :id_producer', [':id_producer' => $params['id_producer']]);


if (isset($params['id_point_sale']) && $params['id_point_sale']) { if (isset($params['id_point_sale']) && $params['id_point_sale']) {

+ 6
- 3
domain/User/User/UserSearch.php View File

} }


if (isset($this->newsletter) && is_numeric($this->newsletter)) { if (isset($this->newsletter) && is_numeric($this->newsletter)) {
$query->andWhere([
'user_producer.newsletter' => $this->newsletter
]);
if($this->newsletter) {
$query->andWhere('user_producer.newsletter = 1 OR user_producer.newsletter_order_taking = 1');
}
else {
$query->andWhere('(user_producer.newsletter = 0 OR user_producer.newsletter IS NULL) AND (user_producer.newsletter_order_taking = 0 OR user_producer.newsletter_order_taking IS NULL)');
}
} }


if (isset($this->id_user_user_group) && is_numeric($this->id_user_user_group)) { if (isset($this->id_user_user_group) && is_numeric($this->id_user_user_group)) {

+ 18
- 2
producer/controllers/NewsletterController.php View File



namespace producer\controllers; namespace producer\controllers;


use domain\Communication\Email\Email;
use yii\filters\AccessControl; use yii\filters\AccessControl;


class NewsletterController extends ProducerBaseController class NewsletterController extends ProducerBaseController


public function actionIndex() public function actionIndex()
{ {
if(!$this->getUserCurrent()) {
$userModule = $this->getUserModule();
$user = $this->getUserCurrent();

if(!$user) {
return $this->redirectProducerLoginFrontend('index'); return $this->redirectProducerLoginFrontend('index');
} }


$user->newsletter = $userModule->getNewsletterManager()->isUserSubscribedNewsletter($user, Email::TYPE_NEWSLETTER);
$user->newsletter_order_taking = $userModule->getNewsletterManager()->isUserSubscribedNewsletter($user, Email::TYPE_ORDER_TAKING);

if($user->load(\Yii::$app->request->post()) && $user->validate()) {
$userModule->getNewsletterManager()->manageUserNewsletter(
$user,
$user->newsletter,
$user->newsletter_order_taking
);
$this->setFlash('success', 'Vos changements ont bien été pris en compte.');
}

return $this->render('index', [ return $this->render('index', [
'user' => $this->getUserCurrent(),
'user' => $user,
'producer' => $this->getProducerCurrent() 'producer' => $this->getProducerCurrent()
]); ]);
} }

+ 1
- 1
producer/views/layouts/main.php View File

->count(); ->count();
$labelOrders = $countOrders > 0 ? 'success' : 'default'; $labelOrders = $countOrders > 0 ? 'success' : 'default';


$isUserSubscribedNewsletter = $userModule->isUserSubscribedNewsletter($userCurrent);
$isUserSubscribedNewsletter = $userModule->getNewsletterManager()->isUserSubscribedOneNewsletter($userCurrent);
$isHome = in_array($this->getControllerAction(), ['site/index', 'site/products', 'site/points-sale']); $isHome = in_array($this->getControllerAction(), ['site/index', 'site/products', 'site/points-sale']);


echo Nav::widget([ echo Nav::widget([

+ 1
- 32
producer/views/newsletter/index.php View File

$producer = $this->context->getProducerCurrent(); $producer = $this->context->getProducerCurrent();
$this->setTitle("Infolettres"); $this->setTitle("Infolettres");


/*if($userModule->isUserSubscribedNewsletter($user)) {
$this->addButton(
[
'label' => '<i class="bi bi-x-circle"></i> Me désinscrire',
'url' => 'newsletter/unsubscribe',
'class' => 'btn btn-secondary'
]
);
}
else {
$this->addButton(
[
'label' => '<i class="bi bi-megaphone"></i> M\'inscrire',
'url' => 'newsletter/subscribe',
'class' => 'btn btn-primary'
]
);
}*/

?> ?>
<div class="newsletter-index"> <div class="newsletter-index">


Les infolettres vous permettent de recevoir les actualités et les emails de prise de commande de ce producteur. Les infolettres vous permettent de recevoir les actualités et les emails de prise de commande de ce producteur.
<?php endif; ?> <?php endif; ?>
</div> </div>
<!--
<?php if($userModule->isUserSubscribedNewsletter($user)): ?>
<div class="alert alert-success">
<i class="bi bi-megaphone"></i>
Vous êtes inscrit à l'infolettre <strong><?= Html::encode($producer->name) ?></strong>.
</div>
<?php else: ?>
<div class="alert alert-danger">
<i class="bi bi-x-circle"></i>
Vous n'êtes pas inscrit à l'infolettre <strong><?= Html::encode($producer->name) ?></strong>.
</div>
<?php endif; ?>
-->


<?php $form = ActiveForm::begin(['id' => 'newsletter-form', 'enableClientValidation' => false,]); ?> <?php $form = ActiveForm::begin(['id' => 'newsletter-form', 'enableClientValidation' => false,]); ?>
<?= $form->field($user, 'newsletter')->widget(Toggle::class, <?= $form->field($user, 'newsletter')->widget(Toggle::class,
]) ])
->label('Actualités'); ->label('Actualités');
?> ?>
<div class="clr"></div>
<?= $form->field($user, 'newsletter_order_taking')->widget(Toggle::class, <?= $form->field($user, 'newsletter_order_taking')->widget(Toggle::class,
[ [
'options' => [ 'options' => [

+ 24
- 0
producer/web/css/screen.css View File

display: inline-block; display: inline-block;
} }


/* line 5, ../sass/newsletter/_index.scss */
.newsletter-index #newsletter-form .form-group {
margin-bottom: 25px;
}
/* line 8, ../sass/newsletter/_index.scss */
.newsletter-index #newsletter-form .form-group .toggle {
float: left;
width: 150px !important;
}
/* line 13, ../sass/newsletter/_index.scss */
.newsletter-index #newsletter-form .form-group label {
display: inline-block;
font-weight: bold;
margin-left: 20px;
}
/* line 18, ../sass/newsletter/_index.scss */
.newsletter-index #newsletter-form .form-group label.control-label {
margin-top: 10px;
}
/* line 23, ../sass/newsletter/_index.scss */
.newsletter-index #newsletter-form .form-group.form-buttons {
display: none;
}

/** /**
Copyright Souke (2018) Copyright Souke (2018)



+ 7
- 0
producer/web/js/producer.js View File

opendistrib_datepicker(); opendistrib_datepicker();
opendistrib_fix_width_sidebar(); opendistrib_fix_width_sidebar();
opendistrib_products(); opendistrib_products();
opendistrib_newsletter();
}); });


function opendistrib_newsletter() {
$('#newsletter-form input').change(function() {
$('#newsletter-form').submit();
});
}

function opendistrib_products() { function opendistrib_products() {
$('.product-name-description-block .show-more-link').unbind('click').click(function() { $('.product-name-description-block .show-more-link').unbind('click').click(function() {
$(this).hide(); $(this).hide();

+ 28
- 0
producer/web/sass/newsletter/_index.scss View File



.newsletter-index {
#newsletter-form {
.form-group {
margin-bottom: 25px;

.toggle {
float: left;
width: 150px !important;
}

label {
display: inline-block;
font-weight: bold;
margin-left: 20px;

&.control-label {
margin-top: 10px;
}
}

&.form-buttons {
display: none;
}
}
}
}

+ 1
- 0
producer/web/sass/screen.scss View File

@import "credit/_history.scss"; @import "credit/_history.scss";
@import "subscription/_index.scss"; @import "subscription/_index.scss";
@import "subscription/_form.scss"; @import "subscription/_form.scss";
@import "newsletter/_index.scss";
@import "_responsive.scss"; @import "_responsive.scss";

Loading…
Cancel
Save