Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mathieu
potage
Commits
e340555b
Commit
e340555b
authored
Aug 28, 2018
by
Mat
Browse files
Page de test, form avec submit pour déclencher l'envoi de l'infolettre
parent
83fd8f09
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/PotageBundle/Controller/DefaultController.php
View file @
e340555b
...
...
@@ -4,6 +4,8 @@ namespace PotageBundle\Controller;
use
PotageBundle\Entity\Lettre
;
use
PotageBundle\Services\Newsletter
;
use
Symfony\Component\Form\Extension\Core\Type\SubmitType
;
use
Symfony\Component\HttpFoundation\Request
;
class
DefaultController
extends
MasterController
{
...
...
@@ -16,14 +18,16 @@ class DefaultController extends MasterController
return
$this
->
render
(
'@Potage/Default/index.html.twig'
);
}
/**
* @param Newsletter $newsletter
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*/
public
function
testAction
(
Newsletter
$newsletter
)
public
function
testAction
(
Request
$request
,
Newsletter
$newsletter
)
{
/**
* @var Lettre $lettre
...
...
@@ -31,14 +35,41 @@ class DefaultController extends MasterController
$lettre
=
$this
->
get
(
'doctrine'
)
->
getManager
()
->
getRepository
(
'PotageBundle:Lettre'
)
->
findOneForSend
(
7
);
$retour
=
$newsletter
->
sendLettreToGroup
(
$lettre
);
$header
=
array
(
'id'
=>
$lettre
->
getId
(),
'start'
=>
$lettre
->
getStartedAt
(),
'end'
=>
$lettre
->
getEndedAt
(),
'status'
=>
$lettre
->
getStatus
(),
'subject'
=>
$lettre
->
getSubject
(),
'reference'
=>
$lettre
->
getReference
(),
);
/**
* Initilalise un formulaire simple pour déclencher l'envoi
*/
$form
=
$this
->
createFormBuilder
()
->
add
(
'envoyer'
,
SubmitType
::
class
)
->
getForm
();
$form
->
handleRequest
(
$request
);
/**
* Envoie la lettre lorsque le formulaire est soumis
*/
$retour
=
null
;
if
(
$form
->
isSubmitted
()
&&
$form
->
isValid
())
{
$retour
=
$newsletter
->
sendLettreToGroup
(
$lettre
);
}
return
$this
->
render
(
'@Potage/Default/test.html.twig'
,
array
(
'retour'
=>
$retour
'lettre'
=>
$header
,
'formEnvoi'
=>
$form
->
createView
(),
'retour'
=>
$retour
,
));
}
/**
* @return \Symfony\Component\HttpFoundation\Response
*/
...
...
src/PotageBundle/Resources/config/routing.yml
View file @
e340555b
...
...
@@ -7,6 +7,7 @@ potage_test:
path
:
/test
defaults
:
_controller
:
PotageBundle:Default:test
methods
:
[
GET
,
POST
]
potage_today
:
path
:
/member/today
...
...
src/PotageBundle/Resources/views/Default/test.html.twig
View file @
e340555b
...
...
@@ -6,15 +6,29 @@
{%
block
content
%}
<h1>
{{
block
(
'title'
)
}}
</h1>
<ul>
{%
for
item
in
retour
%}
<li>
{{
loop.index
}}
)
{{
item.to
}}
→
{{
item.result
}}
</li>
{%
endfor
%}
</ul>
{%
endblock
%}
<hr>
<h2>
Infolettre #
{{
lettre.id
}}
</h2>
<h3>
{{
lettre.subject
}}
</h3>
<h4>
Période du
{{
lettre.start
|
date
(
'd-m-Y'
)
}}
au
{{
lettre.end
|
date
(
'd-m-Y'
)
}}
</h4>
<h3>
Envoyer la lettre
</h3>
{{
form
(
formEnvoi
)
}}
{%
block
customJS
%}
<script
type=
"text/javascript"
>
{%
if
retour
%}
<hr>
<div>
<h4>
Référence:
{{
lettre.reference
}}
</h4>
<h5>
Statut:
{{
lettre.status
}}
</h5>
<h5>
Envoi à :
</h5>
<ul>
{%
for
item
in
retour
%}
<li>
{{
loop.index
}}
)
{{
item.to
}}
→
{{
item.result
}}
</li>
{%
endfor
%}
</ul>
</div>
{%
endif
%}
{%
endblock
%}
</script>
{%
endblock
%}
\ No newline at end of file
{%
block
customJS
%}{%
endblock
%}
\ No newline at end of file
src/PotageBundle/Resources/views/Mail/bodyMail.html.twig
100644 → 100755
View file @
e340555b
File mode changed from 100644 to 100755
src/PotageBundle/Services/Newsletter.php
100644 → 100755
View file @
e340555b
...
...
@@ -20,7 +20,11 @@ class Newsletter
$this
->
container
=
$container
;
}
/**
* Construit un email de la forme
* Prenom Nom<mbox@domain.tld>
*
* @param array $email
* @return string
*/
...
...
@@ -31,6 +35,60 @@ class Newsletter
/**
* Récupère le body de l'infolettre
*
* @param Lettre $lettre
* @return array
*/
private
function
getBody
(
Lettre
$lettre
)
{
$groupe
=
array
(
'nom'
=>
$lettre
->
getGroupe
()
->
getNom
(),
'slug'
=>
$lettre
->
getGroupe
()
->
getSlug
(),
'description'
=>
$lettre
->
getGroupe
()
->
getDescription
(),
);
$depot
=
array
(
'localisation'
=>
$lettre
->
getGroupe
()
->
getDepot
()
->
getLocalisation
(),
'responsable'
=>
$lettre
->
getGroupe
()
->
getDepot
()
->
getResponsable
(),
'jour'
=>
$lettre
->
getGroupe
()
->
getDepot
()
->
getJourPanier
(),
'heure'
=>
$lettre
->
getGroupe
()
->
getDepot
()
->
getHeurePanier
(),
);
$offre
=
array
(
'id'
=>
$lettre
->
getOffre
()
->
getId
(),
'reference'
=>
$lettre
->
getOffre
()
->
getReference
(),
'end'
=>
$lettre
->
getOffre
()
->
getEndedAt
(),
'status'
=>
$lettre
->
getOffre
()
->
getStatus
(),
'sorted'
=>
$lettre
->
getOffre
()
->
getSorted
(),
);
$infos
=
$this
->
container
->
get
(
'doctrine'
)
->
getRepository
(
'PotageBundle:Info'
)
->
findAllForLettreReadInfosSorted
(
$lettre
->
getId
(),
$lettre
->
getSorted
()
);
$legumes
=
$this
->
container
->
get
(
'doctrine'
)
->
getRepository
(
'PotageBundle:OffreLegumes'
)
->
findAllForSortedRead
(
$lettre
->
getOffre
()
->
getId
(),
$lettre
->
getOffre
()
->
getSorted
()
);
return
array
(
'reference'
=>
$lettre
->
getReference
(),
'start'
=>
$lettre
->
getStartedAt
(),
'end'
=>
$lettre
->
getEndedAt
(),
'status'
=>
$lettre
->
getStatus
(),
'groupe'
=>
$groupe
,
'depot'
=>
$depot
,
'infos'
=>
$infos
,
'offre'
=>
$offre
,
'legumes'
=>
$legumes
);
}
/**
* Potage (from) envoie un mail
*
* @param array $to
* @param $subject
* @param $body
...
...
@@ -65,8 +123,12 @@ class Newsletter
return
$mailer
->
send
(
$message
);
}
/**
* Envoie une infolettre
* (à son groupe d'utilisateurs)
*
* @param Lettre $lettre
* @return array
* @throws \Twig_Error_Loader
...
...
@@ -76,35 +138,8 @@ class Newsletter
public
function
sendLettreToGroup
(
Lettre
$lettre
)
{
$subject
=
$lettre
->
getSubject
();
$groupe
=
array
(
'nom'
=>
$lettre
->
getGroupe
()
->
getNom
(),
);
$depot
=
array
(
'localisation'
=>
$lettre
->
getGroupe
()
->
getDepot
()
->
getLocalisation
(),
'responsable'
=>
$lettre
->
getGroupe
()
->
getDepot
()
->
getResponsable
(),
'jour'
=>
$lettre
->
getGroupe
()
->
getDepot
()
->
getJourPanier
(),
'heure'
=>
$lettre
->
getGroupe
()
->
getDepot
()
->
getHeurePanier
(),
);
$offre
=
array
(
'id'
=>
$lettre
->
getOffre
()
->
getId
(),
'reference'
=>
$lettre
->
getOffre
()
->
getReference
(),
'end'
=>
$lettre
->
getOffre
()
->
getEndedAt
(),
'status'
=>
$lettre
->
getOffre
()
->
getStatus
(),
'sorted'
=>
$lettre
->
getOffre
()
->
getSorted
(),
);
$body
=
array
(
'reference'
=>
$lettre
->
getReference
(),
'start'
=>
$lettre
->
getStartedAt
(),
'end'
=>
$lettre
->
getEndedAt
(),
'status'
=>
$lettre
->
getStatus
(),
'sorted'
=>
$lettre
->
getSorted
(),
'groupe'
=>
$groupe
,
'depot'
=>
$depot
,
'offre'
=>
$offre
,
);
$body
=
$this
->
getBody
(
$lettre
);
/**
* A partir de l'infolettre on récupère les destinataires
* @var array $utilisateurs
...
...
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