Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
mathieu
potage
Commits
ac79ff07
Commit
ac79ff07
authored
Aug 27, 2018
by
Mat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
envoie un mail à tous les membres du groupe associé à une infolettre
parent
bee11672
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
98 additions
and
14 deletions
+98
-14
src/PotageBundle/Command/SendMailCommand.php
src/PotageBundle/Command/SendMailCommand.php
+12
-4
src/PotageBundle/Controller/DefaultController.php
src/PotageBundle/Controller/DefaultController.php
+10
-7
src/PotageBundle/Repository/LettreRepository.php
src/PotageBundle/Repository/LettreRepository.php
+15
-0
src/PotageBundle/Repository/UtilisateurRepository.php
src/PotageBundle/Repository/UtilisateurRepository.php
+14
-0
src/PotageBundle/Resources/views/Default/test.html.twig
src/PotageBundle/Resources/views/Default/test.html.twig
+5
-1
src/PotageBundle/Services/Newsletter.php
src/PotageBundle/Services/Newsletter.php
+42
-2
No files found.
src/PotageBundle/Command/SendMailCommand.php
View file @
ac79ff07
...
...
@@ -2,6 +2,8 @@
namespace
PotageBundle\Command
;
use
PotageBundle\Entity\Groupe
;
use
PotageBundle\Entity\Lettre
;
use
PotageBundle\Services\Newsletter
;
use
Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
;
use
Symfony\Component\Console\Input\InputInterface
;
...
...
@@ -44,10 +46,16 @@ class SendMailCommand extends ContainerAwareCommand
*/
protected
function
execute
(
InputInterface
$input
,
OutputInterface
$output
)
{
$ret
=
$this
->
newsletter
->
sendMail
(
'mat@collectifs.net'
,
'[Potage] envoi depuis la commande'
,
/**
* @var Lettre $lettre
*/
$lettre
=
$this
->
getContainer
()
->
get
(
'doctrine'
)
->
getManager
()
->
getRepository
(
'PotageBundle:Lettre'
)
->
findOneForSend
(
7
);
$ret
=
$this
->
newsletter
->
sendLettreToGroup
(
$lettre
,
'body du mail de test'
);
$retMsg
=
(
$ret
===
1
)
?
"
\e
[1;32mDone
\e
[0m
\n
"
:
"
\e
[1;31mError
\e
[0m
\n
"
;
...
...
src/PotageBundle/Controller/DefaultController.php
View file @
ac79ff07
...
...
@@ -2,6 +2,7 @@
namespace
PotageBundle\Controller
;
use
PotageBundle\Entity\Lettre
;
use
PotageBundle\Services\Newsletter
;
class
DefaultController
extends
MasterController
...
...
@@ -24,15 +25,17 @@ class DefaultController extends MasterController
*/
public
function
testAction
(
Newsletter
$newsletter
)
{
$ret
=
$newsletter
->
sendMail
(
'mat@collectifs.net'
,
'[Potage] envoyé depuis la page de test'
,
'body du mail de test'
);
/**
* @var Lettre $lettre
*/
$lettre
=
$this
->
get
(
'doctrine'
)
->
getManager
()
->
getRepository
(
'PotageBundle:Lettre'
)
->
findOneForSend
(
7
);
$retour
=
$newsletter
->
sendLettreToGroup
(
$lettre
,
'body du mail de test'
);
return
$this
->
render
(
'@Potage/Default/test.html.twig'
,
array
(
'retour'
=>
$ret
'retour'
=>
$ret
our
));
}
...
...
src/PotageBundle/Repository/LettreRepository.php
View file @
ac79ff07
...
...
@@ -229,4 +229,19 @@ class LettreRepository extends \Doctrine\ORM\EntityRepository
return
$qb
->
getQuery
()
->
getResult
();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
findOneForSend
(
$id
)
{
$qb
=
$this
->
createQueryBuilder
(
'l'
)
->
where
(
'l.id = :id'
)
->
setParameters
(
array
(
':id'
=>
$id
));
return
$qb
->
getQuery
()
->
getOneOrNullResult
();
}
}
src/PotageBundle/Repository/UtilisateurRepository.php
View file @
ac79ff07
...
...
@@ -117,4 +117,18 @@ class UtilisateurRepository extends \Doctrine\ORM\EntityRepository
return
$qb
->
getQuery
()
->
getResult
();
}
/**
* @param int $id_group
* @return array
*/
public
function
findAllByGroup
(
$id_group
)
{
$qb
=
$this
->
createQueryBuilder
(
'u'
)
->
select
(
'u.id'
,
'u.nom'
,
'u.prenom'
,
'u.email'
)
->
join
(
'u.groupes'
,
'g'
)
->
where
(
'g.id = :id'
)
->
setParameter
(
':id'
,
$id_group
);
return
$qb
->
getQuery
()
->
getResult
();
}
}
src/PotageBundle/Resources/views/Default/test.html.twig
View file @
ac79ff07
...
...
@@ -6,7 +6,11 @@
{%
block
content
%}
<h1>
{{
block
(
'title'
)
}}
</h1>
{{
retour
}}
<ul>
{%
for
item
in
retour
%}
<li>
{{
loop.index
}}
)
{{
item.to
}}
→
{{
item.result
}}
</li>
{%
endfor
%}
</ul>
{%
endblock
%}
{%
block
customJS
%}
...
...
src/PotageBundle/Services/Newsletter.php
View file @
ac79ff07
...
...
@@ -2,6 +2,7 @@
namespace
PotageBundle\Services
;
use
PotageBundle\Entity\Lettre
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
class
Newsletter
...
...
@@ -30,7 +31,6 @@ class Newsletter
*/
public
function
sendMail
(
$to
,
$subject
,
$body
)
{
$mailer
=
$this
->
container
->
get
(
'mailer'
);
$twig
=
$this
->
container
->
get
(
'twig'
);
...
...
@@ -55,4 +55,44 @@ class Newsletter
return
$mailer
->
send
(
$message
);
}
}
\ No newline at end of file
/**
* @param Lettre $lettre
* @param $body
* @return array
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*/
public
function
sendLettreToGroup
(
Lettre
$lettre
,
$body
)
{
$subject
=
"[Potage] Envoi de l'infolettre "
.
$lettre
->
getReference
();
$groupe
=
$lettre
->
getGroupe
()
->
getId
();
$utilisateurs
=
$this
->
container
->
get
(
'doctrine'
)
->
getRepository
(
'PotageBundle:Utilisateur'
)
->
findAllByGroup
(
$groupe
);
$ret
=
array
();
for
(
$i
=
0
;
$i
<
count
(
$utilisateurs
);
$i
++
)
{
//$email = array(
// $utilisateurs[$i]['email'] => $utilisateurs[$i]['prenom'] . ' ' . $utilisateurs[$i]['nom']
//);
$email
=
$utilisateurs
[
$i
][
'email'
];
//dump($email);
$ret
[
$i
]
=
array
(
'to'
=>
$email
,
'result'
=>
$this
->
sendMail
(
$email
,
$subject
,
$body
)
===
1
?
'done'
:
'error'
);
}
return
$ret
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment