système de suivi des invitations à un groupe (ref #221)

This commit is contained in:
afornerot 2021-03-19 13:29:03 +01:00
parent e9242e4b0c
commit 0102239e09
6 changed files with 160 additions and 1 deletions

View File

@ -1198,6 +1198,46 @@ class GroupController extends Controller
]);
}
public function invitationAction($id,Request $request, $access="config")
{
// Récupération de l'enregistrement courant
$em = $this->getDoctrine()->getManager();
$group=$this->getData($id);
$this->canManager($group,$access);
$invitations=$group->getInvitations();
if(!is_array($invitations)) $invitations=[];
foreach($invitations as $key => $mail) {
$user=$em->getRepository("CadolesCoreBundle:User")->findOneBy(["email"=>$mail]);
// Si l'utilisateur est inscript plus la peine de le suivre
if($user) {
$listinvitations[$key]=["email"=>$mail,"statut"=>"","relance"=>false];
$usergroup=$em->getRepository("CadolesCoreBundle:UserGroup")->findOneBy(["user"=>$user,"group"=>$group]);
if($usergroup)
$listinvitations[$key]["statut"]="Inscrit dans le groupe";
else
$listinvitations[$key]["statut"]="Inscrit sur ".$this->get('session')->get('appname')." mais pas dans le groupe";
}
else {
$listinvitations[$key]=["email"=>$mail,"statut"=>"Non inscrit sur ".$this->get('session')->get('appname'),"relance"=>true];
$user=$em->getRepository("CadolesCoreBundle:Registration")->findOneBy(["email"=>$mail]);
if($user) {
$listinvitations[$key]["statut"]=$user->getStatut()->getLabel();
$listinvitations[$key]["relance"]=false;
}
}
}
return $this->render('CadolesCoreBundle:Group:invitations.html.twig',[
'useheader' => false,
'usemenu' => false,
'usesidebar' => false,
'id' => $id,
'invitations' => $listinvitations,
]);
}
protected function canManager($group,$access) {
if($access!="config") {
$em = $this->getDoctrine()->getManager();

View File

@ -23,6 +23,10 @@ class MailController extends Controller
throw $this->createNotFoundException('Unable to find '.$this->labeldata);
}
// On récupère la liste des email invités
$invitations=$group->getInvitations();
if(!is_array($invitations)) $invitations=[];
// Création du formulaire
$form = $this->createForm(MailType::class);
@ -64,7 +68,14 @@ class MailController extends Controller
if($usergroup) array_push($usersin,$user);
else array_push($usersnotin,$user);
}
else {
// On enregistre l'invitation si elle n'existe pas déjà
if(!in_array($mail,$invitations)) {
array_push($invitations,$mail);
}
}
}
$text=$form->get("message")->getData();
$subject=$form->get("subject")->getData();
@ -78,6 +89,17 @@ class MailController extends Controller
$fromName = $this->getUser()->getFirstname()." ".$this->getUser()->getLastname();
$message = $this->container->get('cadoles.core.service.mail');
$message->sendEmail($template, $mail_params, $to, $from, $fromName);
// Sauvegarde des invitation
$group->setInvitations($invitations);
$em->persist($group);
$em->flush();
}
else {
$email=$request->get("email");
if($email) {
$form->get('destinataire')->setData($email);
}
}
if($closed && (!empty($usersin)||!empty($usersnotin))) {

View File

@ -103,6 +103,11 @@ class Group
*/
private $idonlyoffice;
/**
* @ORM\Column(name="invitations", type="array", nullable=true)
*/
private $invitations;
/**
* @ORM\ManyToOne(targetEntity="Cadoles\PortalBundle\Entity\Icon", inversedBy="groups")
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
@ -1085,4 +1090,28 @@ class Group
{
return $this->email;
}
/**
* Set invitations
*
* @param array $invitations
*
* @return Group
*/
public function setInvitations($invitations)
{
$this->invitations = $invitations;
return $this;
}
/**
* Get invitations
*
* @return array
*/
public function getInvitations()
{
return $this->invitations;
}
}

View File

@ -506,6 +506,10 @@ cadoles_core_config_group_usergroup_export:
path: /config/group/users/export/{id}
defaults: { _controller: CadolesCoreBundle:Group:usergroupexport, access: config }
cadoles_core_config_group_invitation:
path: /config/group/invitation/{id}
defaults: { _controller: CadolesCoreBundle:Group:invitation, access: config }
#-- Access user
cadoles_core_user_group:
path: /user/group
@ -563,6 +567,10 @@ cadoles_core_user_group_usergroup_export:
path: /user/group/users/export/{id}
defaults: { _controller: CadolesCoreBundle:Group:usergroupexport, access: user }
cadoles_core_user_group_invitation:
path: /user/group/invitation/{id}
defaults: { _controller: CadolesCoreBundle:Group:invitation, access: user }
#== Whitelist ============================================================================================================
cadoles_core_config_whitelist:

View File

@ -0,0 +1,52 @@
{% extends '@CadolesCore/base.html.twig' %}
{% block pagewrapper %}
<a class="btn btn-default" onClick="closeModal()">Fermer</a>
<br><br>
<table class="table table-striped table-bordered table-hover" id="dataTablesnotin" style="width:100%">
<thead>
<tr>
<th>Action</th>
<th>Email</th>
<th>Statut</th>
</tr>
</thead>
<tbody>
{% for invitation in invitations %}
<tr>
<td>
{% if invitation.relance %}
<a style='cursor:pointer' onClick='showMail("{{invitation.email}}")'><i class='fa fa-envelope fa-fw'></i></a>
{% endif %}
</td>
<td>{{invitation.email}}</td>
<td>{{invitation.statut}}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
{% block localjavascript %}
$(document).ready(function() {
});
function showMail(email) {
window.parent.$("#mymodal").hide();
$("#mymodal").find(".modal-title").html("INVITATION");
var url="{{ path('cadoles_core_mail_invitationgroup',{id:id,email:'xxx'}) }}";
url=url.replace('xxx',email);
window.parent.$("#mymodal").find("#framemodal").attr("src",url);
window.parent.$("#mymodal").modal().show();
}
function closeModal() {
url=window.parent.location;
window.parent.location=url;
}
{% endblock %}

View File

@ -11,6 +11,7 @@
{% if moderegistration!="none" and masteridentity=="SQL"%}
<a class="btn btn-primary" style="cursor:pointer" onClick="showMail();">Inviter des personnes non listées ci-dessous</a>
<a class="btn btn-primary" style="cursor:pointer" onClick="showInvitations();">Suivi des Invitations</a>
{%endif%}
<a class="btn btn-default pull-right" href={{ path('cadoles_core_'~access~'_group_usergroup_export',{'id':group.id}) }}>Exporter CSV</a>
<br><br>
@ -168,4 +169,11 @@
$("#mymodal").find("#framemodal").attr("src",url);
$("#mymodal").modal().show();
}
function showInvitations() {
$("#mymodal").find(".modal-title").html("SUVI DES INVITATIONS");
var url="{{ path('cadoles_core_'~access~'_group_invitation',{id:group.id}) }}";
$("#mymodal").find("#framemodal").attr("src",url);
$("#mymodal").modal().show();
}
{% endblock %}