controle existance user avant inviation groupe (ref #107)

This commit is contained in:
afornerot 2020-04-16 16:06:35 +02:00
parent e341a30f7f
commit 15ff441ca7
2 changed files with 130 additions and 10 deletions

View File

@ -50,7 +50,22 @@ class MailController extends Controller
$destinataires=$form->get("destinataire")->getData();
$to=explode(";",$destinataires);
$to=explode(";",$destinataires);
// On s'assure que les destinataires ne sont pas déjà inscrit dans le portail
$usersnotin=[];
$usersin=[];
foreach($to as $key => $mail) {
// Si le mail existe on l'enlève de la liste des utilisateurs à inviter
$user=$em->getRepository("CadolesCoreBundle:User")->findOneBy(["email"=>$mail]);
if($user) {
unset($to[$key]);
$usergroup=$em->getRepository("CadolesCoreBundle:UserGroup")->findOneBy(["user"=>$user,"group"=>$group]);
if($usergroup) array_push($usersin,$user);
else array_push($usersnotin,$user);
}
}
$text=$form->get("message")->getData();
$subject=$form->get("subject")->getData();
$template="template";
@ -65,15 +80,27 @@ class MailController extends Controller
$message->sendEmail($template, $mail_params, $to, $from, $fromName);
}
return $this->render('CadolesCoreBundle:Mail:mail.html.twig',[
'useheader' => false,
'usemenu' => false,
'usesidebar' => false,
'closed' => $closed,
'subject' => $subject,
'message' => $message,
'form' => $form->createView()
]);
if($closed && (!empty($usersin)||!empty($usersnotin))) {
return $this->render('CadolesCoreBundle:Mail:users.html.twig',[
'useheader' => false,
'usemenu' => false,
'usesidebar' => false,
'usersin' => $usersin,
'usersnotin' => $usersnotin,
'group' => $group
]);
}
else {
return $this->render('CadolesCoreBundle:Mail:mail.html.twig',[
'useheader' => false,
'usemenu' => false,
'usesidebar' => false,
'closed' => $closed,
'subject' => $subject,
'message' => $message,
'form' => $form->createView()
]);
}
}
}

View File

@ -0,0 +1,93 @@
{% extends '@CadolesCore/base.html.twig' %}
{% block pagewrapper %}
<a class="btn btn-default" onClick="closeModal()">Fermer</a>
<br><br>
{% if not usersnotin is empty %}
<h3>Les utilisateurs suivants existent déjà dans {{ app.session.get('appname') }}</h3>
Vous pouvez les ajouter dès maintenant à votre groupe<br>
<div class="dataTable_wrapper">
<table class="table table-striped table-bordered table-hover" id="dataTablesnotin" style="width:100%">
<thead>
<tr>
<th width="70px" class="no-sort">Action</th>
<th width="70px" class="no-sort">Avatar</th>
<th width="200px">Login</th>
<th>Email</th>
</tr>
</thead>
<tbody>
{% for user in usersnotin %}
<tr id="user{{user.id}}">
<td><a style='cursor:pointer' onClick='addUsers({{user.id}})'><i class='fa fa-plus fa-fw'></i></a></td>
<td><img onClick='seeUser({{user.id}})' src='/{{alias}}/uploads/avatar/{{user.avatar}}' style='width:30px;background-color:#337ab7;margin:auto;display:block;cursor:pointer;'></td>
<td>{{user.username}}</td>
<td>{{user.email}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
{% if not usersin is empty %}
<h3>Les utilisateurs suivants déjà rattachés à votre groupe</h3>
<div class="dataTable_wrapper">
<table class="table table-striped table-bordered table-hover" id="dataTablesin" style="width:100%">
<thead>
<tr>
<th width="70px" class="no-sort">Avatar</th>
<th width="200px">Login</th>
<th>Email</th>
</tr>
</thead>
<tbody>
{% for user in usersin %}
<tr>
<td><img onClick='seeUser({{user.id}})' src='/{{alias}}/uploads/avatar/{{user.avatar}}' style='width:30px;background-color:#337ab7;margin:auto;display:block;cursor:pointer;'></td>
<td>{{user.username}}</td>
<td>{{user.email}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
{% endblock %}
{% block localjavascript %}
$(document).ready(function() {
});
function addUsers(userid) {
$.ajax({
rowId: 2,
method: "POST",
url: "{{ path('cadoles_core_user_group_ajax_usergroup_add') }}",
data: "userid="+userid+"&groupid="+{{ group.id }},
success: function(data, dataType)
{
var row=$("#dataTablesnotin").DataTable().row("#user"+userid);
row.remove().draw();
},
error: function(XMLHttpRequest, textStatus, errorThrown)
{
}
});
}
function closeModal() {
window.parent.location.reload();
}
{% endblock %}