Browse Source

Déliverabilité emails

feature/rotating_product
Guillaume Bourgeois 5 months ago
parent
commit
7b2c51413b
11 changed files with 180 additions and 36 deletions
  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 View File

} }


$this->setFlash('success', 'Utilisateur <strong>' . Html::encode($userModule->getUsername($model)) . '</strong> modifié.'); $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 { } else {
throw new UserException("Vous ne pouvez pas modifier cet utilisateur."); throw new UserException("Vous ne pouvez pas modifier cet utilisateur.");
])); ]));
} }


public function actionMessages(int $id)
public function actionMessages(int $id, int $idUserMessage = null)
{ {
$userMessageModule = $this->getUserMessageModule(); $userMessageModule = $this->getUserMessageModule();
$user = $this->findModel($id); $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, $user,
$userMessageModel->getMessage(),
$this->getUserCurrent() $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]); return $this->redirect(['messages', 'id' => $id]);
} }


]); ]);
} }


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) public function actionReportProblemReceivingEmails(int $id)
{ {
$user = $this->findModel($id); $user = $this->findModel($id);

+ 16
- 13
backend/views/user/_form.php View File

<div class="user-form" id="app-user-form"> <div class="user-form" id="app-user-form">


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


<div class="col-md-8 col-no-padding-left"> <div class="col-md-8 col-no-padding-left">
</h3> </h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<?= $form->field($model, 'password_new')->passwordInput() ?>
<?= $form->field($model, 'password_new')->passwordInput(['autocomplete' => 'new-password']) ?>
</div> </div>
</div> </div>
<?php endif; ?> <?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 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; ?> <?php endif; ?>
</div> </div>
</div> </div>

+ 2
- 2
backend/views/user/_menu_navigation.php View File



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


?> ?>


<?= menu_navigation_item('update', 'Profil', $action, $user) ?> <?= 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('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('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> </ul>





+ 27
- 9
backend/views/user/messages.php View File

'enableClientValidation' => false 'enableClientValidation' => false
]); ?> ]); ?>
<?= $form->field($userMessageModel, 'message')->textarea(['rows' => 4]) ?> <?= $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(); ?> <?php ActiveForm::end(); ?>
<br /> <br />


return nl2br(Html::encode($userMessage->getMessage())).'<br /><br /><em>'.$userMessage->getCreatedAt()->format('\L\e d/m/Y à H:i').'</em>'; 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', 'label' => 'Lu',
'format' => 'raw', 'format' => 'raw',
'value' => function ($userMessage) { 'value' => function ($userMessage) {
if($userMessage->getReadAt()) { 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 { else {
return '<span class="label label-default">Non</span>'; 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> </div>

+ 26
- 0
console/migrations/m240612_062929_add_column_user_note_email.php View File

<?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 View File

'mail_distribution_thursday', 'mail_distribution_friday', 'mail_distribution_saturday', 'mail_distribution_thursday', 'mail_distribution_friday', 'mail_distribution_saturday',
'mail_distribution_sunday', 'is_main_contact', 'newsletter', 'exclude_export_shopping_cart_labels', 'mail_distribution_sunday', 'is_main_contact', 'newsletter', 'exclude_export_shopping_cart_labels',
'send_mail_welcome', 'trust_alert', 'newsletter_souke', 'problem_receiving_emails'], 'boolean'], '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], ['lastname', 'verifyOneName', 'skipOnError' => false, 'skipOnEmpty' => false],
[['email', 'email_sending_invoicing_documents'], 'email', 'message' => 'Cette adresse email n\'est pas valide'], [['email', 'email_sending_invoicing_documents'], 'email', 'message' => 'Cette adresse email n\'est pas valide'],
['email', 'verifyEmail'], ['email', 'verifyEmail'],
'trust_alert' => 'Alerte confiance', 'trust_alert' => 'Alerte confiance',
'trust_alert_comment' => 'Commentaire', 'trust_alert_comment' => 'Commentaire',
'newsletter_souke' => "S'abonner à l'infolettre de Souke", '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 View File



/* Relations */ /* Relations */


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

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

+ 6
- 0
domain/User/UserMessage/UserMessageManager.php View File

{ {
return $userMessage->delete(); return $userMessage->delete();
} }

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

+ 12
- 0
domain/User/UserMessage/UserMessageRepository.php View File

]; ];
} }


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

public function queryUserMessagesByUser(User $user) public function queryUserMessagesByUser(User $user)
{ {
return $this->createDefaultQuery() return $this->createDefaultQuery()
return $this->queryUserMessagesByUser($user)->find(); return $this->queryUserMessagesByUser($user)->find();
} }


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

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

+ 10
- 0
producer/controllers/SiteController.php View File

'producer' => $producer '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 View File

$featureModule = FeatureModule::getInstance(); $featureModule = FeatureModule::getInstance();
$productModule = ProductModule::getInstance(); $productModule = ProductModule::getInstance();
$pointSaleModule = PointSaleModule::getInstance(); $pointSaleModule = PointSaleModule::getInstance();
$userMessageModule = $this->getUserMessageModule();
$producerUser = null; $producerUser = null;
if ($userModule->getAuthorizationChecker()->isGrantedAsProducer($userCurrent)) { if ($userModule->getAuthorizationChecker()->isGrantedAsProducer($userCurrent)) {
$producerUser = $producerModule->findOneProducerById($userCurrent->id_producer); $producerUser = $producerModule->findOneProducerById($userCurrent->id_producer);


<section id="content"> <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 <?php
// Message congés // Message congés
$leavePeriodMessageDisplay = $producerModule->getSolver()->getConfig('option_leave_period_message_display', $producer); $leavePeriodMessageDisplay = $producerModule->getSolver()->getConfig('option_leave_period_message_display', $producer);

Loading…
Cancel
Save