System de mailing (ref #144)
This commit is contained in:
parent
a6e5cfbb81
commit
b49c25e07e
|
@ -4,7 +4,7 @@ cd /var/www/html/ninegate
|
|||
ninegate_activer_localmail=$(CreoleGet ninegate_activer_localmail non)
|
||||
if [[ "$ninegate_activer_localmail" = 'oui' ]]
|
||||
then
|
||||
php bin/console swiftmailer:spool:send --message-limit=100 --env=prod --transport swiftmailer.mailer.sendmail.transport
|
||||
php bin/console swiftmailer:spool:send --message-limit=200 --env=prod --transport swiftmailer.mailer.sendmail.transport
|
||||
else
|
||||
php bin/console swiftmailer:spool:send --message-limit=100 --env=prod
|
||||
php bin/console swiftmailer:spool:send --message-limit=200 --env=prod
|
||||
fi
|
|
@ -28,6 +28,7 @@ use Cadoles\CoreBundle\Entity\Niveau02;
|
|||
use Cadoles\WebsocketBundle\Entity\Message;
|
||||
|
||||
use Cadoles\CoreBundle\Form\UserType;
|
||||
use Cadoles\CoreBundle\Form\MailingType;
|
||||
|
||||
|
||||
class UserController extends Controller
|
||||
|
@ -778,6 +779,74 @@ class UserController extends Controller
|
|||
}
|
||||
|
||||
|
||||
public function mailingAction(Request $request) {
|
||||
$form = $this->createForm(MailingType::class,$this->getUser(),array(
|
||||
"perm"=>$this->isGranted('ROLE_ADMIN'),
|
||||
"userid"=>$this->get('security.token_storage')->getToken()->getUser()->getId(),
|
||||
));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Error si pas de message
|
||||
if ($form->get('submit')->isClicked()) {
|
||||
if(!$form->get('message')->getData()) {
|
||||
$form->addError(new FormError("Merci de renseigner un message à votre mail"));
|
||||
$errors = $form->getErrors();
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$users=[];
|
||||
if($this->isGranted('ROLE_ADMIN')) {
|
||||
$groups=$form->get('groups')->getData();
|
||||
foreach($groups as $group) {
|
||||
foreach($group->getUsers() as $usergroup) {
|
||||
if(!in_array($usergroup->getUser()->getEmail(),$users)) {
|
||||
array_push($users,$usergroup->getUser()->getEmail());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$niveau01s=$form->get('niveau01')->getData();
|
||||
foreach($niveau01s as $niveau01) {
|
||||
foreach($niveau01->getUsers() as $user) {
|
||||
if(!in_array($user->getEmail(),$users)) {
|
||||
array_push($users,$user->getEmail());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$text=$form->get("message")->getData();
|
||||
$subject=$form->get("subject")->getData();
|
||||
$template="template";
|
||||
$mail_params=array(
|
||||
"subject" => $subject,
|
||||
"body_html"=>nl2br($text),
|
||||
"body_text"=>$text
|
||||
);
|
||||
$from = $this->getParameter('noreply');
|
||||
$fromName = $this->getUser()->getFirstname()." ".$this->getUser()->getLastname();
|
||||
$message = $this->container->get('cadoles.core.service.mail');
|
||||
foreach($users as $to) {
|
||||
$message->sendEmail($template, $mail_params, $to, $from, $fromName);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute("cadoles_core_config");
|
||||
}
|
||||
|
||||
return $this->render('CadolesCoreBundle:Mail:mailing.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function exportuserAction(Request $request) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$dir = $this->get('kernel')->getRootDir() . '/../uploads/export/';
|
||||
|
|
|
@ -106,8 +106,9 @@
|
|||
// Chargement de la sidebar
|
||||
$iconniveau01 =$this->container->getParameter('iconniveau01');
|
||||
$labelsniveau01 =$this->container->getParameter('labelsniveau01');
|
||||
$labelniveau01 =$this->container->getParameter('labelsniveau01');
|
||||
$labelniveau01 =$this->container->getParameter('labelniveau01');
|
||||
$session->set('labelniveau01',$labelniveau01);
|
||||
$session->set('labelsniveau01',$labelsniveau01);
|
||||
|
||||
$viewniveau02 =$this->container->getParameter('viewniveau02');
|
||||
$iconniveau02 =$this->container->getParameter('iconniveau02');
|
||||
|
@ -115,6 +116,7 @@
|
|||
$labelniveau02 =$this->container->getParameter('labelniveau02');
|
||||
$session->set('viewniveau02',$viewniveau02);
|
||||
$session->set('labelniveau02',$labelniveau02);
|
||||
$session->set('labelsniveau02',$labelsniveau02);
|
||||
|
||||
$moderegistration =$this->container->getParameter('moderegistration');
|
||||
if($masteridentity!="SQL") $moderegistration="none";
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
namespace Cadoles\CoreBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;
|
||||
use Ivory\CKEditorBundle\Form\Type\CKEditorType;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
|
||||
class MailingType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$session = new Session();
|
||||
|
||||
$builder->add('submit',
|
||||
SubmitType::class, array(
|
||||
"label" => "Envoyer",
|
||||
"attr" => array("class" => "btn btn-success")
|
||||
)
|
||||
);
|
||||
|
||||
$perm=$options["perm"];
|
||||
$userid=$options["userid"];
|
||||
|
||||
$builder
|
||||
->add('niveau01',EntityType::class,[
|
||||
"mapped" => false,
|
||||
"required" => false,
|
||||
"class" => "CadolesCoreBundle:Niveau01",
|
||||
'multiple' => true,
|
||||
"label" => $session->get('labelsniveau01'),
|
||||
'placeholder' => '== Choisir '.$session->get('labelsniveau01').' ==',
|
||||
"choice_label" => "label",
|
||||
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px"),
|
||||
"query_builder"=> function (EntityRepository $er) use($perm,$userid) {
|
||||
if($perm)
|
||||
return $er->createQueryBuilder('niveau01');
|
||||
else {
|
||||
$result=$er->createQueryBuilder("table")->innerJoin("CadolesCoreBundle:UserModo", "usermodo", Join::WITH, "table.id = usermodo.niveau01");
|
||||
$result->andWhere("usermodo.user = :userid");
|
||||
$result->setParameter('userid', $userid);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
if($perm) {
|
||||
$builder
|
||||
->add('groups', Select2EntityType::class, [
|
||||
'mapped' => false,
|
||||
'label' => 'Groupes',
|
||||
'class' => 'CadolesCoreBundle:Group',
|
||||
'text_property' => 'label',
|
||||
'multiple' => true,
|
||||
'remote_route' => 'cadoles_core_ajax_group_list',
|
||||
'primary_key' => 'id',
|
||||
'text_property' => 'label',
|
||||
'minimum_input_length' => 0,
|
||||
'page_limit' => 100,
|
||||
'allow_clear' => true,
|
||||
'delay' => 250,
|
||||
'cache' => false,
|
||||
'cache_timeout' => 60000,
|
||||
'language' => 'fr',
|
||||
'placeholder' => 'Selectionner des groupes',
|
||||
]);
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('subject', TextType::class, [
|
||||
"label" =>"Sujet",
|
||||
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px"),
|
||||
"mapped" => false
|
||||
]);
|
||||
|
||||
$builder
|
||||
->add("message",CKEditorType::class,[
|
||||
'config_name' => 'small_config',
|
||||
'label' => "Message",
|
||||
'mapped'=> false,
|
||||
'required' => true,
|
||||
'attr' => array("class" => "form-control", "style" => "margin-bottom:15px"),
|
||||
'config' => ["height" => "400px",'filebrowserUploadRoute' => 'cadoles_portal_user_pagewidget_upload']
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Cadoles\CoreBundle\Entity\User',
|
||||
'perm' => "boolean",
|
||||
'userid' => "integer",
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -257,6 +257,10 @@ cadoles_core_config_user_ajax_selectlist:
|
|||
path: /config/user/ajax/selectlist
|
||||
defaults: { _controller: CadolesCoreBundle:User:selectlist, access: config }
|
||||
|
||||
cadoles_core_config_mailing:
|
||||
path: /config/mailing
|
||||
defaults: { _controller: CadolesCoreBundle:User:mailing }
|
||||
|
||||
cadoles_core_config_importuser:
|
||||
path: /config/importuser
|
||||
defaults: { _controller: CadolesCoreBundle:User:importuser }
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
{% extends '@CadolesCore/base.html.twig' %}
|
||||
|
||||
{% block pagewrapper %}
|
||||
{{ form_start(form) }}
|
||||
<h1 class="page-header">
|
||||
Mailing
|
||||
</h1>
|
||||
|
||||
{{ form_widget(form.submit) }}
|
||||
|
||||
<br><br>
|
||||
|
||||
{% if app.session.flashbag.has('error') %}
|
||||
<div class='alert alert-danger' style='margin: 5px 0px'>
|
||||
<strong>Erreur</strong><br>
|
||||
{% for flashMessage in app.session.flashbag.get('error') %}
|
||||
{{ flashMessage }}<br>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if app.session.flashbag.has('notice') %}
|
||||
<div class='alert alert-info' style='margin: 5px 0px'>
|
||||
<strong>Information</strong><br>
|
||||
{% for flashMessage in app.session.flashbag.get('notice') %}
|
||||
{{ flashMessage }}<br>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<i class="fa fa-pencil fa-fw"></i> Destinataires
|
||||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
{{ form_row(form.niveau01) }}
|
||||
{% if form.groups is defined %}
|
||||
{{ form_row(form.groups) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<i class="fa fa-envelop fa-fw"></i> Mail
|
||||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
{{ form_row(form.subject) }}
|
||||
{{ form_row(form.message) }}
|
||||
</div>
|
||||
</div>
|
||||
{{ form_end(form) }}
|
||||
{% endblock %}
|
|
@ -60,9 +60,9 @@ class InitDataCommand extends ContainerAwareCommand
|
|||
$entity->setRepeatexec(0);
|
||||
$entity->setRepeatinterval(60);
|
||||
$entity->setNextexecdate($entity->getSubmitdate());
|
||||
$entity->setJsonargument('{"message-limit":"100","env":"prod"}');
|
||||
$this->entityManager->persist($entity);
|
||||
}
|
||||
$entity->setJsonargument('{"message-limit":"200","env":"prod"}');
|
||||
$this->entityManager->persist($entity);
|
||||
|
||||
|
||||
// Job synchronisation des comptes utilisateur
|
||||
|
|
|
@ -40,7 +40,8 @@ INSERT IGNORE INTO `sidebar` (`id`, `parent_id`, `roworder`, `label`, `path`, `f
|
|||
(1240, 1200, 1240, 'Groupes', 'cadoles_core_config_group', 'fa-users', 'ROLE_ADMIN,ROLE_MODO', ''),
|
||||
(1250, 1200, 1250, 'Inscriptions', 'cadoles_core_config_registration', 'fa-pencil-square-o', 'ROLE_ADMIN,ROLE_MODO', ''),
|
||||
(1260, 1200, 1260, 'Utilisateurs', 'cadoles_core_config_user', 'fa-child', 'ROLE_ADMIN,ROLE_MODO', ''),
|
||||
(1270, 1200, 1270, 'Import Utilisateurs', 'cadoles_core_config_importuser', 'fa-download', 'ROLE_ADMIN,ROLE_MODO', 'importuser_activate'),
|
||||
(1270, 1200, 1270, 'Mailing', 'cadoles_core_config_mailing', 'fa-envelope', 'ROLE_ADMIN,ROLE_MODO', ''),
|
||||
(1280, 1200, 1280, 'Import Utilisateurs', 'cadoles_core_config_importuser', 'fa-download', 'ROLE_ADMIN,ROLE_MODO', 'importuser_activate'),
|
||||
|
||||
(1500, NULL, 1500, 'PORTAIL', NULL, 'fa-cubes', 'ROLE_ADMIN,ROLE_MODO', 'portal_activate'),
|
||||
(1510, 1500, 1510, 'Modèles de Page', 'cadoles_portal_config_pagetemplate', 'fa-copy', 'ROLE_ADMIN,ROLE_MODO', 'portal_activate'),
|
||||
|
@ -130,6 +131,7 @@ INSERT IGNORE permmodo (`route`, `visible`) VALUES
|
|||
('cadoles_core_config_group',1),
|
||||
('cadoles_core_config_registration',1),
|
||||
('cadoles_core_config_user',1),
|
||||
('cadoles_core_config_mailing',1),
|
||||
('cadoles_core_config_importuser',0),
|
||||
('cadoles_portal_config_pagetemplate',1),
|
||||
('cadoles_portal_config_page',1),
|
||||
|
|
Loading…
Reference in New Issue