use domain\User\User\UserSearch; | use domain\User\User\UserSearch; | ||||
use Yii; | use Yii; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use yii\web\NotFoundHttpException; | |||||
class UserAdminController extends BackendController | class UserAdminController extends BackendController | ||||
{ | { | ||||
]); | ]); | ||||
} | } | ||||
public function actionEmailDeliverability() | |||||
{ | |||||
$searchModel = new UserSearch(); | |||||
$searchModel->problem_receiving_emails = true; | |||||
$dataProvider = $searchModel->search([ | |||||
'UserSearch' => isset(\Yii::$app->request->queryParams['UserSearch']) ? | |||||
Yii::$app->request->queryParams['UserSearch'] : [] | |||||
]); | |||||
return $this->render('email_deliverability', [ | |||||
'searchModel' => $searchModel, | |||||
'dataProvider' => $dataProvider | |||||
]); | |||||
} | |||||
public function actionReportProblemReceivingEmails(int $id) | |||||
{ | |||||
$user = $this->findModel($id); | |||||
if($this->getUserModule()->getManager()->reportProblemReceivingEmails($user)) { | |||||
$this->setFlash('success', "L'utilisateur <strong>".$this->getUserModule()->getSolver()->getUsername($user)."</strong> a bien été signalé comme ayant des problèmes dans la réception de vos emails. L'administrateur débloquera la situation dès que possible et préviendra l'utilisateur."); | |||||
} | |||||
else { | |||||
$this->setFlash('error', "Une erreur est survenue."); | |||||
} | |||||
return $this->redirect('index'); | |||||
} | |||||
public function actionRedirectView(int $idUserProducer) | public function actionRedirectView(int $idUserProducer) | ||||
{ | { | ||||
$userCurrent = $this->getUserCurrent(); | $userCurrent = $this->getUserCurrent(); | ||||
return $this->redirectReferer(); | return $this->redirectReferer(); | ||||
} | } | ||||
} | } | ||||
protected function findModel($id) | |||||
{ | |||||
if (($user = $this->getUserModule()->findOneUserById($id)) !== null) { | |||||
return $user; | |||||
} else { | |||||
throw new NotFoundHttpException("Utilisateur introuvable"); | |||||
} | |||||
} | |||||
} | } |
])); | ])); | ||||
} | } | ||||
public function actionMessages(int $id) | |||||
{ | |||||
$userMessageModule = $this->getUserMessageModule(); | |||||
$user = $this->findModel($id); | |||||
$userMessageModel = $userMessageModule->getBuilder()->instanciateUserMessage( | |||||
$user, | |||||
$this->getUserCurrent() | |||||
); | |||||
if($userMessageModel->load(\Yii::$app->request->post()) && $userMessageModel->validate()) { | |||||
$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->render('messages', [ | |||||
'user' => $user, | |||||
'userMessageModel' => $userMessageModel, | |||||
'userMessagesDataProvider' => $userMessageModule->getRepository() | |||||
->queryUserMessagesByUser($user) | |||||
->getDataProvider(20) | |||||
]); | |||||
} | |||||
public function actionReportProblemReceivingEmails(int $id) | public function actionReportProblemReceivingEmails(int $id) | ||||
{ | { | ||||
$user = $this->findModel($id); | $user = $this->findModel($id); |
?> | ?> | ||||
<div class="dashboard-admin-index"> | <div class="dashboard-admin-index"> | ||||
<div class="row"> | |||||
<div class="col-lg-6 col-xs-6"> | |||||
<?= AdminLTE::smallBox( | |||||
$countUsersOnline, | |||||
'En ligne', | |||||
$countUsersOnline ? 'green' : 'blue', | |||||
'wifi', | |||||
Yii::$app->urlManager->createUrl('online-admin/index') | |||||
) ?> | |||||
<div id="producers-online" class="box box-solid"> | |||||
<div class="box-header with-border"> | |||||
<i class="fa fa-bookmark"></i> | |||||
<h3 class="box-title">Producteurs en ligne</h3> | |||||
</div> | </div> | ||||
<div class="col-lg-6 col-xs-6" id="producers-online"> | |||||
<!--<h3>Producteurs en ligne :</h3>--> | |||||
<div class="box-body"> | |||||
<?php if($usersWithStatusProducerOnlineArray && count($usersWithStatusProducerOnlineArray) > 0): ?> | <?php if($usersWithStatusProducerOnlineArray && count($usersWithStatusProducerOnlineArray) > 0): ?> | ||||
<?php foreach ($usersWithStatusProducerOnlineArray as $userWithStatusProducerOnline): ?> | <?php foreach ($usersWithStatusProducerOnlineArray as $userWithStatusProducerOnline): ?> | ||||
<?php $producer = $userWithStatusProducerOnline->producer; ?> | <?php $producer = $userWithStatusProducerOnline->producer; ?> | ||||
<?php endforeach; ?> | <?php endforeach; ?> | ||||
<div class="clr"></div> | <div class="clr"></div> | ||||
<?php else: ?> | <?php else: ?> | ||||
<div class="alert alert-info">Aucun producteur en ligne actuellement.</div> | |||||
<p><em>Aucun producteur en ligne actuellement.</em></p> | |||||
<?php endif; ?> | <?php endif; ?> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
<div class="row"> | |||||
<div class="col-lg-6 col-xs-6"> | |||||
<?= AdminLTE::smallBox( | |||||
$countUsersOnline, | |||||
'Utilisateurs en ligne', | |||||
$countUsersOnline ? 'green' : 'blue', | |||||
'wifi', | |||||
Yii::$app->urlManager->createUrl('online-admin/index') | |||||
) ?> | |||||
</div> | |||||
<div class="col-lg-6 col-xs-6"> | |||||
<?php $countUsersWithProblemReceivingEmails = $this->getUserModule()->getRepository()->countUsersWithProblemReceivingEmails(); ?> | |||||
<?= AdminLTE::smallBox( | |||||
$countUsersWithProblemReceivingEmails, | |||||
'Problèmes réception emails', | |||||
$countUsersWithProblemReceivingEmails ? 'red' : 'green', | |||||
'send', | |||||
Yii::$app->urlManager->createUrl('user-admin/email-deliverability') | |||||
) ?> | |||||
</div> | |||||
</div> | |||||
<div class="row"> | <div class="row"> | ||||
<div class="col-lg-6 col-xs-6"> | <div class="col-lg-6 col-xs-6"> | ||||
<?= AdminLTE::smallBox( | <?= AdminLTE::smallBox( |
'url' => ['/user-admin/index'], | 'url' => ['/user-admin/index'], | ||||
'visible' => $isUserCurrentGrantedAsAdministrator | 'visible' => $isUserCurrentGrantedAsAdministrator | ||||
], | ], | ||||
[ | |||||
'label' => 'Deliverabilité emails', | |||||
'icon' => 'paper-plane', | |||||
'url' => ['/user-admin/email-deliverability'], | |||||
'visible' => $isUserCurrentGrantedAsAdministrator | |||||
], | |||||
[ | [ | ||||
'label' => 'Statistiques', | 'label' => 'Statistiques', | ||||
'icon' => 'line-chart', | 'icon' => 'line-chart', |
<?php | |||||
/** | |||||
* Copyright Souke (2018) | |||||
* | |||||
* contact@souke.fr | |||||
* | |||||
* Ce logiciel est un programme informatique servant à aider les producteurs | |||||
* à distribuer leur production en circuits courts. | |||||
* | |||||
* Ce logiciel est régi par la licence CeCILL soumise au droit français et | |||||
* respectant les principes de diffusion des logiciels libres. Vous pouvez | |||||
* utiliser, modifier et/ou redistribuer ce programme sous les conditions | |||||
* de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA | |||||
* sur le site "http://www.cecill.info". | |||||
* | |||||
* En contrepartie de l'accessibilité au code source et des droits de copie, | |||||
* de modification et de redistribution accordés par cette licence, il n'est | |||||
* offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, | |||||
* seule une responsabilité restreinte pèse sur l'auteur du programme, le | |||||
* titulaire des droits patrimoniaux et les concédants successifs. | |||||
* | |||||
* A cet égard l'attention de l'utilisateur est attirée sur les risques | |||||
* associés au chargement, à l'utilisation, à la modification et/ou au | |||||
* développement et à la reproduction du logiciel par l'utilisateur étant | |||||
* donné sa spécificité de logiciel libre, qui peut le rendre complexe à | |||||
* manipuler et qui le réserve donc à des développeurs et des professionnels | |||||
* avertis possédant des connaissances informatiques approfondies. Les | |||||
* utilisateurs sont donc invités à charger et tester l'adéquation du | |||||
* logiciel à leurs besoins dans des conditions permettant d'assurer la | |||||
* sécurité de leurs systèmes et ou de leurs données et, plus généralement, | |||||
* à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. | |||||
* | |||||
* Le fait que vous puissiez accéder à cet en-tête signifie que vous avez | |||||
* pris connaissance de la licence CeCILL, et que vous en avez accepté les | |||||
* termes. | |||||
*/ | |||||
use common\helpers\GlobalParam; | |||||
use common\helpers\Price; | |||||
use domain\Order\Order\Order; | |||||
use domain\Producer\Producer\ProducerModule; | |||||
use domain\User\User\User; | |||||
use domain\User\User\UserModule; | |||||
use domain\User\UserProducer\UserProducer; | |||||
use domain\User\UserProducer\UserProducerModule; | |||||
use yii\grid\GridView; | |||||
use yii\helpers\Html; | |||||
use domain\User\UserGroup\UserGroupModule; | |||||
$userModule = UserModule::getInstance(); | |||||
$producerModule = ProducerModule::getInstance(); | |||||
$userCurrent = GlobalParam::getCurrentUser(); | |||||
$userGroupModule = UserGroupModule::getInstance(); | |||||
$userProducerModule = UserProducerModule::getInstance(); | |||||
$this->setTitle('Déliverabilité des emails'); | |||||
$this->addBreadcrumb($this->getTitle()); | |||||
?> | |||||
<?= GridView::widget([ | |||||
'dataProvider' => $dataProvider, | |||||
'filterModel' => $searchModel, | |||||
'summary' => | |||||
'Affichage de <b>{begin, number}-{end, number}</b> sur <b>{totalCount, number}</b> {totalCount, plural, one{élément} other{éléments}}.', | |||||
'columns' => [ | |||||
[ | |||||
'attribute' => 'username', | |||||
'label' => 'Nom', | |||||
'value' => function ($user) use ($userModule) { | |||||
return $userModule->getUsername($user); | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'type', | |||||
'label' => 'Type', | |||||
'headerOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'filterOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'contentOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'filter' => $userModule->getTypeChoicesArray(), | |||||
'value' => function ($user) use ($userModule) { | |||||
return $userModule->getTypeLabel($user['type']); | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'contacts', | |||||
'header' => 'Contacts', | |||||
'format' => 'raw', | |||||
'headerOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'filterOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'contentOptions' => ['class' => 'column-hide-on-mobile'], | |||||
'value' => function ($user) { | |||||
$html = ''; | |||||
if (strlen($user['phone'])) { | |||||
$html .= $user['phone']; | |||||
} | |||||
if (strlen($user['phone']) && strlen($user['email'])) { | |||||
$html .= '<br />'; | |||||
} | |||||
if (strlen($user['email'])) { | |||||
$html .= $user['email']; | |||||
} | |||||
return $html; | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'producers', | |||||
'label' => 'Producteurs', | |||||
'format' => 'raw', | |||||
'contentOptions' => ['class' => 'column-hide-on-mobile align-center'], | |||||
'value' => function ($user) use ($userProducerModule) { | |||||
$html = ''; | |||||
$userProducersArray = $userProducerModule->getRepository()->findUserProducersByUser($user); | |||||
foreach($userProducersArray as $userProducer) { | |||||
$html .= '<a href="'.Yii::$app->urlManager->createUrl(['user-admin/redirect-view', 'idUserProducer' => $userProducer->id]).'" class="btn btn-default"><span class="glyphicon glyphicon-eye-open"></span> '.$userProducer->producer->name.'</a> '; | |||||
} | |||||
return $html; | |||||
} | |||||
] | |||||
], | |||||
]); ?> |
], | ], | ||||
[ | [ | ||||
'class' => 'yii\grid\ActionColumn', | 'class' => 'yii\grid\ActionColumn', | ||||
'template' => '{switch} ', | |||||
'template' => '{problemReceivingEmails} {switch}', | |||||
'headerOptions' => ['class' => 'column-actions'], | 'headerOptions' => ['class' => 'column-actions'], | ||||
'contentOptions' => ['class' => 'column-actions'], | 'contentOptions' => ['class' => 'column-actions'], | ||||
'buttons' => [ | 'buttons' => [ | ||||
'class' => 'btn btn-default' | 'class' => 'btn btn-default' | ||||
]); | ]); | ||||
}, | }, | ||||
'problemReceivingEmails' => function($url, $model) use ($userModule, $userCurrent) { | |||||
if(!$model->getProblemReceivingEmails()) { | |||||
return Html::a('<i class="fa fa-life-ring"></i>', | |||||
Yii::$app->urlManager->createUrl(['user-admin/report-problem-receiving-emails', 'id' => $model->id]), | |||||
[ | |||||
'title' => ((int) $model->getProblemReceivingEmails()).' Signaler comme ayant des problèmes de réception des emails', | |||||
'class' => 'btn btn-default', | |||||
]); | |||||
} | |||||
}, | |||||
'switch' => function($url, $model) use ($userModule, $userCurrent) { | 'switch' => function($url, $model) use ($userModule, $userCurrent) { | ||||
if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)) { | if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)) { | ||||
return Html::a('<i class="fa fa-fw fa-user-secret"></i>', | return Html::a('<i class="fa fa-fw fa-user-secret"></i>', |
'data-on' => 'Oui', | 'data-on' => 'Oui', | ||||
'data-off' => 'Non', | 'data-off' => 'Non', | ||||
'data-onstyle' => 'danger', | 'data-onstyle' => 'danger', | ||||
'data-offstyle' => 'success', | |||||
'data-offstyle' => 'default', | |||||
], | ], | ||||
] | ] | ||||
); ?> | ); ?> | ||||
'data-id' => $model->id, | 'data-id' => $model->id, | ||||
'data-on' => 'Oui', | 'data-on' => 'Oui', | ||||
'data-off' => 'Non', | 'data-off' => 'Non', | ||||
'data-onstyle' => 'danger', | |||||
'data-offstyle' => 'default', | |||||
], | ], | ||||
] | ] | ||||
)->hint('Si activé, le nom du client sera mis en avant dans la liste des commandes'); ?> | )->hint('Si activé, le nom du client sera mis en avant dans la liste des commandes'); ?> |
$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); | |||||
?> | ?> | ||||
<?= 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) ?> | |||||
</ul> | </ul> | ||||
return Html::a('<i class="fa fa-life-ring"></i> Réception emails', | return Html::a('<i class="fa fa-life-ring"></i> Réception emails', | ||||
Yii::$app->urlManager->createUrl(['user/report-problem-receiving-emails', 'id' => $model->id]), | Yii::$app->urlManager->createUrl(['user/report-problem-receiving-emails', 'id' => $model->id]), | ||||
[ | [ | ||||
'title' => 'Signaler comme ayant des problèmes de réception des emails', | |||||
'class' => '' | |||||
'title' => ((int) $model->getProblemReceivingEmails()).' Signaler comme ayant des problèmes de réception des emails', | |||||
'class' => '', | |||||
]); | ]); | ||||
} | } | ||||
}, | }, |
<?php | |||||
/** | |||||
* Copyright Souke (2018) | |||||
* | |||||
* contact@souke.fr | |||||
* | |||||
* Ce logiciel est un programme informatique servant à aider les producteurs | |||||
* à distribuer leur production en circuits courts. | |||||
* | |||||
* Ce logiciel est régi par la licence CeCILL soumise au droit français et | |||||
* respectant les principes de diffusion des logiciels libres. Vous pouvez | |||||
* utiliser, modifier et/ou redistribuer ce programme sous les conditions | |||||
* de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA | |||||
* sur le site "http://www.cecill.info". | |||||
* | |||||
* En contrepartie de l'accessibilité au code source et des droits de copie, | |||||
* de modification et de redistribution accordés par cette licence, il n'est | |||||
* offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, | |||||
* seule une responsabilité restreinte pèse sur l'auteur du programme, le | |||||
* titulaire des droits patrimoniaux et les concédants successifs. | |||||
* | |||||
* A cet égard l'attention de l'utilisateur est attirée sur les risques | |||||
* associés au chargement, à l'utilisation, à la modification et/ou au | |||||
* développement et à la reproduction du logiciel par l'utilisateur étant | |||||
* donné sa spécificité de logiciel libre, qui peut le rendre complexe à | |||||
* manipuler et qui le réserve donc à des développeurs et des professionnels | |||||
* avertis possédant des connaissances informatiques approfondies. Les | |||||
* utilisateurs sont donc invités à charger et tester l'adéquation du | |||||
* logiciel à leurs besoins dans des conditions permettant d'assurer la | |||||
* sécurité de leurs systèmes et ou de leurs données et, plus généralement, | |||||
* à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. | |||||
* | |||||
* Le fait que vous puissiez accéder à cet en-tête signifie que vous avez | |||||
* pris connaissance de la licence CeCILL, et que vous en avez accepté les | |||||
* termes. | |||||
*/ | |||||
use domain\User\User\UserModule; | |||||
use yii\grid\GridView; | |||||
use yii\helpers\Html; | |||||
use yii\widgets\ActiveForm; | |||||
$userModule = $this->getUserModule(); | |||||
$orderModule = $this->getOrderModule(); | |||||
$userModule = $this->getUserModule(); | |||||
$username = Html::encode($userModule->getSolver()->getUsername($user)); | |||||
$this->setTitle($username.' (#'.$user->id.')') ; | |||||
$this->addBreadcrumb(['label' => 'Utilisateurs', 'url' => ['index']]) ; | |||||
$this->addBreadcrumb(['label' => $username]) ; | |||||
$this->addBreadcrumb('Messages') ; | |||||
?> | |||||
<?= $this->render('_menu_navigation', [ | |||||
'action' => 'messages', | |||||
'user' => $user | |||||
]); ?> | |||||
<div class="user-messages tab-content"> | |||||
<?php $form = ActiveForm::begin([ | |||||
'enableClientValidation' => false | |||||
]); ?> | |||||
<?= $form->field($userMessageModel, 'message')->textarea(['rows' => 4]) ?> | |||||
<?= Html::submitButton('Envoyer', ['class' => 'btn btn-primary', 'name' => 'save']) ?> | |||||
<?php ActiveForm::end(); ?> | |||||
<br /> | |||||
<?= GridView::widget([ | |||||
'dataProvider' => $userMessagesDataProvider, | |||||
'columns' => [ | |||||
[ | |||||
'label' => 'Message', | |||||
'format' => 'raw', | |||||
'value' => function ($userMessage) { | |||||
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>'; | |||||
} | |||||
else { | |||||
return '<span class="label label-default">Non</span>'; | |||||
} | |||||
} | |||||
], | |||||
], | |||||
]); ?> | |||||
</div> |
</span> | </span> | ||||
</li> | </li> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
<li class="list-group-item"> | |||||
<strong>Problème réception emails</strong> | |||||
<span class="pull-right"> | |||||
<?php $hasProblemReceivingEmails = $model->problem_receiving_emails; ?> | |||||
<span class="label label-<?= $hasProblemReceivingEmails ? 'danger' : 'default' ?>"> | |||||
<?= $hasProblemReceivingEmails ? 'Oui' : 'Non' ?> | |||||
</span> | |||||
</span> | |||||
</li> | |||||
<?php if($model->userPointSale): ?> | <?php if($model->userPointSale): ?> | ||||
<li class="list-group-item"> | <li class="list-group-item"> | ||||
<strong>Points de vente</strong> | <strong>Points de vente</strong> |
$this->getUserProducerModule(), | $this->getUserProducerModule(), | ||||
$this->getUserPointSaleModule(), | $this->getUserPointSaleModule(), | ||||
$this->getUserModule(), | $this->getUserModule(), | ||||
$this->getUserMessageModule(), | |||||
$this->getPointSaleDistributionModule(), | $this->getPointSaleDistributionModule(), | ||||
$this->getProductDistributionModule(), | $this->getProductDistributionModule(), | ||||
$this->getProductCategoryModule(), | $this->getProductCategoryModule(), |
use domain\Ticket\TicketUser\TicketUserModule; | use domain\Ticket\TicketUser\TicketUserModule; | ||||
use domain\User\User\UserModule; | use domain\User\User\UserModule; | ||||
use domain\User\UserGroup\UserGroupModule; | use domain\User\UserGroup\UserGroupModule; | ||||
use domain\User\UserMessage\UserMessageModule; | |||||
use domain\User\UserProducer\UserProducerModule; | use domain\User\UserProducer\UserProducerModule; | ||||
use domain\User\UserUserGroup\UserUserGroupModule; | use domain\User\UserUserGroup\UserUserGroupModule; | ||||
return UserModule::getInstance(); | return UserModule::getInstance(); | ||||
} | } | ||||
public function getUserMessageModule(): UserMessageModule | |||||
{ | |||||
return UserMessageModule::getInstance(); | |||||
} | |||||
public function getUserGroupModule(): UserGroupModule | public function getUserGroupModule(): UserGroupModule | ||||
{ | { | ||||
return UserGroupModule::getInstance(); | return UserGroupModule::getInstance(); |
<?php | |||||
use yii\db\Migration; | |||||
use yii\db\Schema; | |||||
/** | |||||
* Class m240611_125313_create_table_user_message | |||||
*/ | |||||
class m240611_125313_create_table_user_message extends Migration | |||||
{ | |||||
/** | |||||
* {@inheritdoc} | |||||
*/ | |||||
public function safeUp() | |||||
{ | |||||
$this->createTable('user_message', [ | |||||
'id' => 'pk', | |||||
'id_user' => Schema::TYPE_INTEGER, | |||||
'message' => Schema::TYPE_TEXT, | |||||
'created_at' => Schema::TYPE_DATETIME, | |||||
'created_by' => Schema::TYPE_INTEGER, | |||||
'read_at' => Schema::TYPE_DATETIME, | |||||
]); | |||||
$this->addForeignKey('fk_user_message_id_user', 'user_message', 'id_user', 'user', 'id'); | |||||
$this->addForeignKey('fk_user_message_created_by', 'user_message', 'created_by', 'user', 'id'); | |||||
} | |||||
/** | |||||
* {@inheritdoc} | |||||
*/ | |||||
public function safeDown() | |||||
{ | |||||
$this->dropTable('user_message'); | |||||
$this->dropForeignKey('fk_user_message_id_user', 'user_message'); | |||||
$this->dropForeignKey('fk_user_message_created_by', 'user_message'); | |||||
} | |||||
} |
return $userSystem; | return $userSystem; | ||||
} | } | ||||
public function findUsersWithProblemReceivingEmails() | |||||
{ | |||||
return $this->createQuery() | |||||
->filterHasProblemReceivingEmails() | |||||
->find(); | |||||
} | |||||
public function countUsersWithProblemReceivingEmails(): int | |||||
{ | |||||
return count($this->findUsersWithProblemReceivingEmails()); | |||||
} | |||||
} | } |
->addParams(['date' => $date->format('Y-m-d H:i:s')]); | ->addParams(['date' => $date->format('Y-m-d H:i:s')]); | ||||
return $this; | return $this; | ||||
} | } | ||||
public function filterHasProblemReceivingEmails(): self | |||||
{ | |||||
$this->andWhere(['problem_receiving_emails' => true]); | |||||
return $this; | |||||
} | |||||
} | } |
public function rules() | public function rules() | ||||
{ | { | ||||
return [ | return [ | ||||
[['no_mail', 'mail_distribution_monday', 'mail_distribution_tuesday', 'mail_distribution_wednesday', 'mail_distribution_thursday', 'mail_distribution_friday', 'mail_distribution_saturday', 'mail_distribution_sunday'], 'boolean'], | |||||
[['no_mail', 'mail_distribution_monday', 'mail_distribution_tuesday', 'mail_distribution_wednesday', | |||||
'mail_distribution_thursday', 'mail_distribution_friday', 'mail_distribution_saturday', | |||||
'mail_distribution_sunday', 'problem_receiving_emails'], 'boolean'], | |||||
[['lastname', 'name', 'phone', 'address', 'type', 'newsletter', 'contacts'], 'string'], | [['lastname', 'name', 'phone', 'address', 'type', 'newsletter', 'contacts'], 'string'], | ||||
[['id_point_sale', 'inactive', 'subscribers', 'id_user_user_group'], 'integer'], | [['id_point_sale', 'inactive', 'subscribers', 'id_user_user_group'], 'integer'], | ||||
[['date_last_connection', 'id_point_sale', 'username'], 'safe'], | [['date_last_connection', 'id_point_sale', 'username'], 'safe'], | ||||
. '`user`.date_last_connection, ' | . '`user`.date_last_connection, ' | ||||
. '`user`.name_legal_person, ' | . '`user`.name_legal_person, ' | ||||
. '`user`.type, ' | . '`user`.type, ' | ||||
. '`user`.problem_receiving_emails, ' | |||||
. '(SELECT COUNT(*) FROM `order` WHERE `user`.id = `order`.id_user) AS count_orders'); | . '(SELECT COUNT(*) FROM `order` WHERE `user`.id = `order`.id_user) AS count_orders'); | ||||
if($producer) { | if($producer) { | ||||
]); | ]); | ||||
} | } | ||||
if(isset($this->problem_receiving_emails)) { | |||||
$query->andWhere([ | |||||
'user.problem_receiving_emails' => (bool) $this->problem_receiving_emails | |||||
]); | |||||
} | |||||
return $dataProvider; | return $dataProvider; | ||||
} | } | ||||
} | } |
<?php | |||||
namespace domain\User\UserMessage; | |||||
use common\components\ActiveRecordCommon; | |||||
use domain\User\User\User; | |||||
class UserMessage extends ActiveRecordCommon | |||||
{ | |||||
public static function tableName() | |||||
{ | |||||
return 'user_message'; | |||||
} | |||||
public function rules() | |||||
{ | |||||
return [ | |||||
[['id_user', 'message', 'created_at', 'created_by'], 'required'], | |||||
[['message'], 'string'], | |||||
[['id_user', 'created_by'], 'integer'], | |||||
[['created_at', 'read_at'], 'safe'] | |||||
]; | |||||
} | |||||
public function attributeLabels() | |||||
{ | |||||
return [ | |||||
'id_user' => 'Utilisateur', | |||||
'message' => 'Message', | |||||
'created_at' => 'Date de création', | |||||
'created_by' => 'Créé par', | |||||
'read_at', 'Date de lecture' | |||||
]; | |||||
} | |||||
/* Getters / Setters */ | |||||
public function getId(): ?int | |||||
{ | |||||
return $this->id; | |||||
} | |||||
public function getUser(): User | |||||
{ | |||||
return $this->userRelation; | |||||
} | |||||
public function setUser(User $user): self | |||||
{ | |||||
$this->populateFieldObject('id_user', 'userRelation', $user); | |||||
return $this; | |||||
} | |||||
public function getMessage(): string | |||||
{ | |||||
return $this->message; | |||||
} | |||||
public function setMessage(string $message): self | |||||
{ | |||||
$this->message = $message; | |||||
return $this; | |||||
} | |||||
public function getCreatedAt(): \DateTime | |||||
{ | |||||
return new \DateTime($this->created_at); | |||||
} | |||||
public function setCreatedAt(\DateTime $createdAt): self | |||||
{ | |||||
$this->created_at = $createdAt->format('Y-m-d H:i:s'); | |||||
return $this; | |||||
} | |||||
public function getCreatedBy(): User | |||||
{ | |||||
return $this->createdByRelation; | |||||
} | |||||
public function setCreatedBy(User $createdBy): self | |||||
{ | |||||
$this->populateFieldObject('created_by', 'createdByRelation', $createdBy); | |||||
return $this; | |||||
} | |||||
public function getReadAt(): ?\DateTime | |||||
{ | |||||
if($this->read_at) { | |||||
return new \DateTime($this->read_at); | |||||
} | |||||
return null; | |||||
} | |||||
public function setReadAt(\DateTime $readAt): self | |||||
{ | |||||
$this->read_at = $readAt->format('Y-m-d H:i:s'); | |||||
return $this; | |||||
} | |||||
/* Relations */ | |||||
public function getCreatedByRelation() | |||||
{ | |||||
return $this->hasOne(User::class, ['id' => 'created_by']); | |||||
} | |||||
} |
<?php | |||||
namespace domain\User\UserMessage; | |||||
use domain\_\AbstractBuilder; | |||||
use domain\User\User\User; | |||||
class UserMessageBuilder extends AbstractBuilder | |||||
{ | |||||
public function instanciateUserMessage(User $user, User $createdBy): UserMessage | |||||
{ | |||||
$userMessage = new UserMessage(); | |||||
$userMessage->setUser($user); | |||||
$userMessage->setCreatedAt(new \DateTime()); | |||||
$userMessage->setCreatedBy($createdBy); | |||||
return $userMessage; | |||||
} | |||||
} |
<?php | |||||
namespace domain\User\UserMessage; | |||||
use domain\_\AbstractDefinition; | |||||
class UserMessageDefinition extends AbstractDefinition | |||||
{ | |||||
public function getEntityFqcn(): string | |||||
{ | |||||
return UserMessage::class; | |||||
} | |||||
} |
<?php | |||||
namespace domain\User\UserMessage; | |||||
use domain\_\AbstractManager; | |||||
use domain\User\User\User; | |||||
class UserMessageManager extends AbstractManager | |||||
{ | |||||
protected UserMessageBuilder $userMessageBuilder; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->userMessageBuilder = $this->loadService(UserMessageBuilder::class); | |||||
} | |||||
public function createUserMessage(User $user, string $message, User $createdBy): UserMessage | |||||
{ | |||||
$userMessage = $this->userMessageBuilder->instanciateUserMessage($user, $createdBy); | |||||
$userMessage->setMessage($message); | |||||
$userMessage->save(); | |||||
return $userMessage; | |||||
} | |||||
public function deleteUserMessage(UserMessage $userMessage): bool | |||||
{ | |||||
return $userMessage->delete(); | |||||
} | |||||
} |
<?php | |||||
namespace domain\User\UserMessage; | |||||
use domain\_\AbstractModule; | |||||
class UserMessageModule extends AbstractModule | |||||
{ | |||||
public function getServices(): array | |||||
{ | |||||
return [ | |||||
UserMessageDefinition::class, | |||||
UserMessageBuilder::class, | |||||
UserMessageRepository::class, | |||||
UserMessageManager::class | |||||
]; | |||||
} | |||||
public function getDefinition(): UserMessageDefinition | |||||
{ | |||||
return UserMessageDefinition::getInstance(); | |||||
} | |||||
public function getBuilder(): UserMessageBuilder | |||||
{ | |||||
return UserMessageBuilder::getInstance(); | |||||
} | |||||
public function getRepository(): UserMessageRepository | |||||
{ | |||||
return UserMessageRepository::getInstance(); | |||||
} | |||||
public function getManager(): UserMessageManager | |||||
{ | |||||
return UserMessageManager::getInstance(); | |||||
} | |||||
} |
<?php | |||||
namespace domain\User\UserMessage; | |||||
use domain\_\AbstractRepository; | |||||
use domain\User\User\User; | |||||
class UserMessageRepository extends AbstractRepository | |||||
{ | |||||
protected UserMessageRepositoryQuery $query; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->loadQuery(UserMessageRepositoryQuery::class); | |||||
} | |||||
public function getDefaultOptionsSearch(): array | |||||
{ | |||||
return [ | |||||
self::WITH => [], | |||||
self::JOIN_WITH => [], | |||||
self::ORDER_BY => 'created_at DESC', | |||||
self::ATTRIBUTE_ID_PRODUCER => '' | |||||
]; | |||||
} | |||||
public function queryUserMessagesByUser(User $user) | |||||
{ | |||||
return $this->createDefaultQuery() | |||||
->filterByUser($user); | |||||
} | |||||
public function findUserMessagesByUser(User $user): array | |||||
{ | |||||
return $this->queryUserMessagesByUser($user)->find(); | |||||
} | |||||
public function findUserMessagesUnreadByUser(User $user) | |||||
{ | |||||
return $this->queryUserMessagesByUser($user) | |||||
->filterIsUnread() | |||||
->find(); | |||||
} | |||||
public function countUserMessagesUnreadByUser(User $user): int | |||||
{ | |||||
return count($this->findUserMessagesUnreadByUser($user)); | |||||
} | |||||
} |
<?php | |||||
namespace domain\User\UserMessage; | |||||
use domain\_\AbstractRepositoryQuery; | |||||
use domain\User\User\User; | |||||
class UserMessageRepositoryQuery extends AbstractRepositoryQuery | |||||
{ | |||||
protected UserMessageDefinition $definition; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->loadDefinition(UserMessageDefinition::class); | |||||
} | |||||
public function filterByUser(User $user): self | |||||
{ | |||||
$this->andWhere(['user_message.id_user' => $user->id]); | |||||
return $this; | |||||
} | |||||
public function filterIsUnread(): self | |||||
{ | |||||
$this->andWhere('user_message.read_at IS NULL'); | |||||
return $this; | |||||
} | |||||
} |