Procházet zdrojové kódy

Déliverabilité emails

feature/rotating_product
Guillaume Bourgeois před 5 měsíci
rodič
revize
7b2c51413b
11 změnil soubory, kde provedl 180 přidání a 36 odebrání
  1. +49
    -10
      backend/controllers/UserController.php
  2. +16
    -13
      backend/views/user/_form.php
  3. +2
    -2
      backend/views/user/_menu_navigation.php
  4. +27
    -9
      backend/views/user/messages.php
  5. +26
    -0
      console/migrations/m240612_062929_add_column_user_note_email.php
  6. +3
    -2
      domain/User/User/User.php
  7. +5
    -0
      domain/User/UserMessage/UserMessage.php
  8. +6
    -0
      domain/User/UserMessage/UserMessageManager.php
  9. +12
    -0
      domain/User/UserMessage/UserMessageRepository.php
  10. +10
    -0
      producer/controllers/SiteController.php
  11. +24
    -0
      producer/views/layouts/main.php

+ 49
- 10
backend/controllers/UserController.php Zobrazit soubor

@@ -246,7 +246,7 @@ class UserController extends BackendController
}

$this->setFlash('success', 'Utilisateur <strong>' . Html::encode($userModule->getUsername($model)) . '</strong> modifié.');
return $this->redirect(['view', 'id' => $model->id]);
return $this->redirect(['update', 'id' => $model->id]);
}
} else {
throw new UserException("Vous ne pouvez pas modifier cet utilisateur.");
@@ -258,22 +258,37 @@ class UserController extends BackendController
]));
}

public function actionMessages(int $id)
public function actionMessages(int $id, int $idUserMessage = null)
{
$userMessageModule = $this->getUserMessageModule();
$user = $this->findModel($id);
$userMessageModel = $userMessageModule->getBuilder()->instanciateUserMessage(
$user,
$this->getUserCurrent()
);
$isUpdate = false;

if($userMessageModel->load(\Yii::$app->request->post()) && $userMessageModel->validate()) {
$userMessageModule->getManager()->createUserMessage(
if($idUserMessage) {
$isUpdate = true;
$userMessageModel = $this->findUserMessage($idUserMessage);
}
else {
$userMessageModel = $userMessageModule->getBuilder()->instanciateUserMessage(
$user,
$userMessageModel->getMessage(),
$this->getUserCurrent()
);
$this->setFlash('success', "Le message a bien été envoyé à l'utilisateur.");
}

if($userMessageModel->load(\Yii::$app->request->post()) && $userMessageModel->validate()) {
if($isUpdate) {
$userMessageModel->save();
$this->setFlash('success', "Le message a bien été modifié.");
}
else {
$userMessageModule->getManager()->createUserMessage(
$user,
$userMessageModel->getMessage(),
$this->getUserCurrent()
);
$this->setFlash('success', "Le message a bien été envoyé à l'utilisateur.");
}

return $this->redirect(['messages', 'id' => $id]);
}

@@ -286,6 +301,30 @@ class UserController extends BackendController
]);
}

public function actionMessageDelete(int $idUser, int $idUserMessage)
{
$userMessageModule = $this->getUserMessageModule();
$userMessage = $this->findUserMessage($idUserMessage);
if($userMessageModule->getManager()->deleteUserMessage($userMessage)) {
$this->setFlash('success', "Le message a bien été supprimé.");
}
else {
$this->setFlash('error', "Une erreur est survenue pendant la suppression du message.");
}
return $this->redirect(['messages', 'id' => $idUser]);
}

public function findUserMessage(int $idUserMessage)
{
$userMessage = $this->getUserMessageModule()->getRepository()->findOneUserMessageById($idUserMessage);

if(!$userMessage) {
throw new NotFoundHttpException("Le message utilisateur n'a pas été trouvé.");
}

return $userMessage;
}

public function actionReportProblemReceivingEmails(int $id)
{
$user = $this->findModel($id);

+ 16
- 13
backend/views/user/_form.php Zobrazit soubor

@@ -56,7 +56,7 @@ $distributionModule = DistributionModule::getInstance();
<div class="user-form" id="app-user-form">

<?php $form = ActiveForm::begin([
'enableClientValidation' => false
'enableClientValidation' => false,
]); ?>

<div class="col-md-8 col-no-padding-left">
@@ -97,7 +97,7 @@ $distributionModule = DistributionModule::getInstance();
</h3>
</div>
<div class="panel-body">
<?= $form->field($model, 'password_new')->passwordInput() ?>
<?= $form->field($model, 'password_new')->passwordInput(['autocomplete' => 'new-password']) ?>
</div>
</div>
<?php endif; ?>
@@ -183,17 +183,20 @@ $distributionModule = DistributionModule::getInstance();
],
]
); ?>
<?= $form->field($model, 'problem_receiving_emails')->widget(Toggle::class,
[
'options' => [
'data-id' => $model->id,
'data-on' => 'Oui',
'data-off' => 'Non',
'data-onstyle' => 'danger',
'data-offstyle' => 'default',
],
]
); ?>
<?php endif; ?>
<?= $form->field($model, 'problem_receiving_emails')->widget(Toggle::class,
[
'options' => [
'data-id' => $model->id,
'data-on' => 'Oui',
'data-off' => 'Non',
'data-onstyle' => 'danger',
'data-offstyle' => 'default',
],
]
); ?>
<?php if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)): ?>
<?= $form->field($model, 'note_emails')->textarea(['rows' => 7]); ?>
<?php endif; ?>
</div>
</div>

+ 2
- 2
backend/views/user/_menu_navigation.php Zobrazit soubor

@@ -10,7 +10,7 @@ $orderModule = OrderModule::getInstance();

$credit = $userModule->getRepository()->getCredit($user);
$countOrders = $orderModule->getRepository()->countOrdersByUser($user);
$countUserMessagesUnread = $this->getUserMessageModule()->getRepository()->countUserMessagesUnreadByUser($user);
$countUserMessages = $this->getUserMessageModule()->getRepository()->countUserMessagesByUser($user);

?>

@@ -19,7 +19,7 @@ $countUserMessagesUnread = $this->getUserMessageModule()->getRepository()->count
<?= menu_navigation_item('update', 'Profil', $action, $user) ?>
<?= menu_navigation_item('credit', 'Cagnotte <span class="label label-default badge">'.Price::format($credit).'</span>', $action, $user) ?>
<?= menu_navigation_item('orders', 'Commandes <span class="label label-default badge">'.$countOrders.'</span>', $action, $user) ?>
<?= menu_navigation_item('messages', 'Messages <span class="label label-default badge">'.$countUserMessagesUnread.'</span>', $action, $user) ?>
<?= menu_navigation_item('messages', 'Messages <span class="label label-default badge">'.$countUserMessages.'</span>', $action, $user) ?>
</ul>



+ 27
- 9
backend/views/user/messages.php Zobrazit soubor

@@ -63,7 +63,7 @@ $this->addBreadcrumb('Messages') ;
'enableClientValidation' => false
]); ?>
<?= $form->field($userMessageModel, 'message')->textarea(['rows' => 4]) ?>
<?= Html::submitButton('Envoyer', ['class' => 'btn btn-primary', 'name' => 'save']) ?>
<?= Html::submitButton($userMessageModel->isNewRecord ? 'Envoyer' : 'Modifier', ['class' => 'btn btn-primary', 'name' => 'save']) ?>
<?php ActiveForm::end(); ?>
<br />

@@ -77,25 +77,43 @@ $this->addBreadcrumb('Messages') ;
return nl2br(Html::encode($userMessage->getMessage())).'<br /><br /><em>'.$userMessage->getCreatedAt()->format('\L\e d/m/Y à H:i').'</em>';
}
],
/*[
'label' => 'Création',
'format' => 'raw',
'value' => function ($userMessage) {
return $userMessage->getCreatedAt()->format('d/m/Y à H:i');
}
],*/
[
'label' => 'Lu',
'format' => 'raw',
'value' => function ($userMessage) {
if($userMessage->getReadAt()) {
return '<span class="label label-success" title="'.$userMessage->getReadAt()->format('\L\e d/m/Y à H:i').'">Oui</span>';
//return '<span class="label label-success" title="'.$userMessage->getReadAt()->format('\L\e d/m/Y à H:i').'">Oui</span>';
return '<span class="label label-success">Oui</span><br />'.$userMessage->getReadAt()->format('\L\e d/m/Y à H:i');
}
else {
return '<span class="label label-default">Non</span>';
}
}
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}',
'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'],
'buttons' => [
'update' => function ($url, $userMessage) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>',
Yii::$app->urlManager->createUrl(['user/messages', 'id' => $userMessage->getUser()->id, 'idUserMessage' => $userMessage->id]),
[
'title' => 'Modifier',
'class' => 'btn btn-default'
]);
},
'delete' => function ($url, $userMessage) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>',
Yii::$app->urlManager->createUrl(['user/message-delete', 'idUser' => $userMessage->getUser()->getId(), 'idUserMessage' => $userMessage->getId()]),
[
'title' => 'Supprimer',
'class' => 'btn btn-default'
]);
},
],
],
],
]); ?>
</div>

+ 26
- 0
console/migrations/m240612_062929_add_column_user_note_email.php Zobrazit soubor

@@ -0,0 +1,26 @@
<?php

use yii\db\Migration;
use yii\db\Schema;

/**
* Class m240612_062929_add_column_user_note_email
*/
class m240612_062929_add_column_user_note_email extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('user', 'note_emails', Schema::TYPE_TEXT);
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('user', 'note_emails');
}
}

+ 3
- 2
domain/User/User/User.php Zobrazit soubor

@@ -109,7 +109,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
'mail_distribution_thursday', 'mail_distribution_friday', 'mail_distribution_saturday',
'mail_distribution_sunday', 'is_main_contact', 'newsletter', 'exclude_export_shopping_cart_labels',
'send_mail_welcome', 'trust_alert', 'newsletter_souke', 'problem_receiving_emails'], 'boolean'],
[['lastname', 'name', 'phone', 'address', 'type', 'name_legal_person', 'evoliz_code', 'trust_alert_comment'], 'string'],
[['lastname', 'name', 'phone', 'address', 'type', 'name_legal_person', 'evoliz_code', 'trust_alert_comment', 'note_emails'], 'string'],
['lastname', 'verifyOneName', 'skipOnError' => false, 'skipOnEmpty' => false],
[['email', 'email_sending_invoicing_documents'], 'email', 'message' => 'Cette adresse email n\'est pas valide'],
['email', 'verifyEmail'],
@@ -158,7 +158,8 @@ class User extends ActiveRecordCommon implements IdentityInterface
'trust_alert' => 'Alerte confiance',
'trust_alert_comment' => 'Commentaire',
'newsletter_souke' => "S'abonner à l'infolettre de Souke",
'problem_receiving_emails' => "Rencontre des problèmes pour recevoir les emails"
'problem_receiving_emails' => "Rencontre des problèmes pour recevoir les emails",
'note_emails' => "Note emails"
];
}


+ 5
- 0
domain/User/UserMessage/UserMessage.php Zobrazit soubor

@@ -101,6 +101,11 @@ class UserMessage extends ActiveRecordCommon

/* Relations */

public function getUserRelation()
{
return $this->hasOne(User::class, ['id' => 'id_user']);
}

public function getCreatedByRelation()
{
return $this->hasOne(User::class, ['id' => 'created_by']);

+ 6
- 0
domain/User/UserMessage/UserMessageManager.php Zobrazit soubor

@@ -26,4 +26,10 @@ class UserMessageManager extends AbstractManager
{
return $userMessage->delete();
}

public function readUserMessage(UserMessage $userMessage): bool
{
$userMessage->setReadAt(new \DateTime());
return $userMessage->save();
}
}

+ 12
- 0
domain/User/UserMessage/UserMessageRepository.php Zobrazit soubor

@@ -24,6 +24,13 @@ class UserMessageRepository extends AbstractRepository
];
}

public function findOneUserMessageById(int $id): ?UserMessage
{
return $this->createQuery()
->filterById($id)
->findOne();
}

public function queryUserMessagesByUser(User $user)
{
return $this->createDefaultQuery()
@@ -35,6 +42,11 @@ class UserMessageRepository extends AbstractRepository
return $this->queryUserMessagesByUser($user)->find();
}

public function countUserMessagesByUser(User $user): int
{
return count($this->findUserMessagesByUser($user));
}

public function findUserMessagesUnreadByUser(User $user)
{
return $this->queryUserMessagesByUser($user)

+ 10
- 0
producer/controllers/SiteController.php Zobrazit soubor

@@ -314,6 +314,16 @@ class SiteController extends ProducerBaseController
'producer' => $producer
]);
}

public function actionUserMessageRead(int $idUserMessage)
{
$userMessageModule = $this->getUserMessageModule();
$userMessage = $userMessageModule->getRepository()->findOneUserMessageById($idUserMessage);
if($userMessage) {
$userMessageModule->getManager()->readUserMessage($userMessage);
}
return $this->redirectReferer();
}
}

?>

+ 24
- 0
producer/views/layouts/main.php Zobrazit soubor

@@ -60,6 +60,7 @@ $producerModule = ProducerModule::getInstance();
$featureModule = FeatureModule::getInstance();
$productModule = ProductModule::getInstance();
$pointSaleModule = PointSaleModule::getInstance();
$userMessageModule = $this->getUserMessageModule();
$producerUser = null;
if ($userModule->getAuthorizationChecker()->isGrantedAsProducer($userCurrent)) {
$producerUser = $producerModule->findOneProducerById($userCurrent->id_producer);
@@ -326,6 +327,29 @@ $mainColor = $producer->option_main_color ?: '#ee6f42' ;

<section id="content">

<?php
// Message utilisateur
$userMessagesArray = $userMessageModule->getRepository()->findUserMessagesUnreadByUser($userCurrent);
if($userMessagesArray && count($userMessagesArray)):
foreach($userMessagesArray as $userMessage): ?>
<div class="alert alert-info">
<h4 class="alert-heading">
<i class="bi bi-envelope"></i>
Nouveau message
</h4>
<p><?= nl2br(Html::encode($userMessage->getMessage())) ?></p>
<p>
<a class="alert-link" href="<?= Yii::$app->urlManager->createUrl(['site/'.($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userMessage->getCreatedBy()) ? 'support' : 'contact')]); ?>">
Répondre</a>
&bull;
<a class="alert-link" href="<?= Yii::$app->urlManager->createUrl(['site/user-message-read', 'idUserMessage' => $userMessage->getId()]); ?>">
Fermer
</a>
</p>
</div>
<?php endforeach;
endif; ?>

<?php
// Message congés
$leavePeriodMessageDisplay = $producerModule->getSolver()->getConfig('option_leave_period_message_display', $producer);

Načítá se…
Zrušit
Uložit