} | } | ||||
$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); |
<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> |
$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> | ||||
'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> |
<?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'); | |||||
} | |||||
} |
'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" | |||||
]; | ]; | ||||
} | } | ||||
/* 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']); |
{ | { | ||||
return $userMessage->delete(); | return $userMessage->delete(); | ||||
} | } | ||||
public function readUserMessage(UserMessage $userMessage): bool | |||||
{ | |||||
$userMessage->setReadAt(new \DateTime()); | |||||
return $userMessage->save(); | |||||
} | |||||
} | } |
]; | ]; | ||||
} | } | ||||
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) |
'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(); | |||||
} | |||||
} | } | ||||
?> | ?> |
$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> | |||||
• | |||||
<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); |