From 2d69b4a18d7eecc5efe6207783a7d1929552fe8b Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Thu, 2 Jan 2020 16:34:23 +0100 Subject: [PATCH] :zap: start email to owner listing polls --- src/Controller/DefaultController.php | 47 ++++++ src/Entity/Owner.php | 226 ++++++++++++++------------- src/templates/owner-list.html.twig | 14 ++ 3 files changed, 182 insertions(+), 105 deletions(-) create mode 100644 src/templates/owner-list.html.twig diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index d81bd40..f2fd3c3 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -68,6 +68,53 @@ class DefaultController extends AbstractController { 200 ); } + /** + * @Get( + * path = "/send-polls-to-user/{email}", + * name = "send_user_polls" + * ) + */ + public function sendPollsToUser( $email ) { + $repository = $this->getDoctrine()->getRepository( Owner::class ); + $founduser = $repository->findOneBy( [ 'email' => $email ] ); + + if ( $founduser ) { + $polls = $founduser->getPolls(); + + $message = ( new \Swift_Message( 'Framadate - mes sondages' ) ) + ->setFrom( 'ne-pas-repondre@framdate-api.cipherbliss.com' ) + ->setTo( $founduser->getEmail() ) + ->setBody( + $this->renderView( + // templates/hello/email.txt.twig + 'owner-list.html.twig', + [ + 'owner' => $founduser, + 'polls' => $polls, + ] + ) + ); + $mailer->send( $message ); + + return $this->json( [ + 'message' => 'here are your polls, ' . $email, + 'data' => 'email was sent with a list of ' . count( $polls ) . ' polls', + ], + 200 ); + } else { + return $this->json( [ + 'message' => 'no user found for email ' . $email, + 'data' => '', + ], + 400 ); + } + // find user by email + // send email + // user not found case + + + } + /** * @Post( * path = "/poll", diff --git a/src/Entity/Owner.php b/src/Entity/Owner.php index 64a8d3d..2af74ab 100644 --- a/src/Entity/Owner.php +++ b/src/Entity/Owner.php @@ -53,162 +53,178 @@ class Owner { * @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"}) */ private $createdAt; + /** + * @ORM\Column(type="requested_polls_date" , options={"default"="CURRENT_TIMESTAMP"},nullable=true) + */ + private $requestedPollsDate; public function __construct() { - $this->polls = new ArrayCollection(); - $this->comments = new ArrayCollection(); - $this->stackOfVotes = new ArrayCollection(); - $this->setCreatedAt( new \DateTime() ); - $this->setModifierToken( uniqid() ); - } + $this->polls = new ArrayCollection(); + $this->comments = new ArrayCollection(); + $this->stackOfVotes = new ArrayCollection(); + $this->setCreatedAt( new \DateTime() ); + $this->setModifierToken( uniqid() ); + } public function getId(): ?int { - return $this->id; - } + return $this->id; + } public function getEmail(): ?string { - return $this->email; - } + return $this->email; + } public function setEmail( string $email ): self { - $this->email = $email; - - return $this; - } + $this->email = $email; + + return $this; + } public function getPseudo(): ?string { - return $this->pseudo; - } + return $this->pseudo; + } public function setPseudo( string $pseudo ): self { - $this->pseudo = $pseudo; - - return $this; - } + $this->pseudo = $pseudo; + + return $this; + } /** * @return Collection|Poll[] */ public function getPolls(): Collection { - return $this->polls; - } + return $this->polls; + } public function addPoll( Poll $poll ): self { - if ( ! $this->polls->contains( $poll ) ) { - $this->polls[] = $poll; - $poll->setOwner( $this ); - } - - return $this; - } + if ( ! $this->polls->contains( $poll ) ) { + $this->polls[] = $poll; + $poll->setOwner( $this ); + } + + return $this; + } public function removePoll( Poll $poll ): self { - if ( $this->polls->contains( $poll ) ) { - $this->polls->removeElement( $poll ); - // set the owning side to null (unless already changed) - if ( $poll->getOwner() === $this ) { - $poll->setOwner( null ); - } - } - - return $this; - } + if ( $this->polls->contains( $poll ) ) { + $this->polls->removeElement( $poll ); + // set the owning side to null (unless already changed) + if ( $poll->getOwner() === $this ) { + $poll->setOwner( null ); + } + } + + return $this; + } /** * @return Collection|Comment[] */ public function getComments(): Collection { - return $this->comments; - } + return $this->comments; + } public function addText( Comment $text ): self { - if ( ! $this->comments->contains( $text ) ) { - $this->comments[] = $text; - $text->setOwner( $this ); - } - - return $this; - } + if ( ! $this->comments->contains( $text ) ) { + $this->comments[] = $text; + $text->setOwner( $this ); + } + + return $this; + } public function removeText( Comment $text ): self { - if ( $this->comments->contains( $text ) ) { - $this->comments->removeElement( $text ); - // set the owning side to null (unless already changed) - if ( $text->getOwner() === $this ) { - $text->setOwner( null ); - } - } - - return $this; - } + if ( $this->comments->contains( $text ) ) { + $this->comments->removeElement( $text ); + // set the owning side to null (unless already changed) + if ( $text->getOwner() === $this ) { + $text->setOwner( null ); + } + } + + return $this; + } /** * @return Collection|StackOfVotes[] */ public function getStackOfVotes(): Collection { - return $this->stackOfVotes; - } + return $this->stackOfVotes; + } public function addStackOfVote( StackOfVotes $stackOfVote ): self { - if ( ! $this->stackOfVotes->contains( $stackOfVote ) ) { - $this->stackOfVotes[] = $stackOfVote; - $stackOfVote->setOwner( $this ); - } - - return $this; - } + if ( ! $this->stackOfVotes->contains( $stackOfVote ) ) { + $this->stackOfVotes[] = $stackOfVote; + $stackOfVote->setOwner( $this ); + } + + return $this; + } public function removeStackOfVote( StackOfVotes $stackOfVote ): self { - if ( $this->stackOfVotes->contains( $stackOfVote ) ) { - $this->stackOfVotes->removeElement( $stackOfVote ); - // set the owning side to null (unless already changed) - if ( $stackOfVote->getOwner() === $this ) { - $stackOfVote->setOwner( null ); - } - } - - return $this; - } + if ( $this->stackOfVotes->contains( $stackOfVote ) ) { + $this->stackOfVotes->removeElement( $stackOfVote ); + // set the owning side to null (unless already changed) + if ( $stackOfVote->getOwner() === $this ) { + $stackOfVote->setOwner( null ); + } + } + + return $this; + } public function getModifierToken(): ?string { - return $this->modifierToken; - } + return $this->modifierToken; + } public function setModifierToken( string $modifierToken ): self { - $this->modifierToken = $modifierToken; - - return $this; - } + $this->modifierToken = $modifierToken; + + return $this; + } public function addComment( Comment $comment ): self { - if ( ! $this->comments->contains( $comment ) ) { - $this->comments[] = $comment; - $comment->setOwner( $this ); - } - - return $this; - } + if ( ! $this->comments->contains( $comment ) ) { + $this->comments[] = $comment; + $comment->setOwner( $this ); + } + + return $this; + } public function removeComment( Comment $comment ): self { - if ( $this->comments->contains( $comment ) ) { - $this->comments->removeElement( $comment ); - // set the owning side to null (unless already changed) - if ( $comment->getOwner() === $this ) { - $comment->setOwner( null ); - } - } - - return $this; - } + if ( $this->comments->contains( $comment ) ) { + $this->comments->removeElement( $comment ); + // set the owning side to null (unless already changed) + if ( $comment->getOwner() === $this ) { + $comment->setOwner( null ); + } + } + + return $this; + } public function getCreatedAt(): ?\DateTimeInterface { - return $this->createdAt; - } + return $this->createdAt; + } public function setCreatedAt( \DateTimeInterface $createdAt ): self { - $this->createdAt = $createdAt; + $this->createdAt = $createdAt; + + return $this; + } - return $this; - } + public function getRequestedPollsDate() + { + return $this->requestedPollsDate; + } + + public function setRequestedPollsDate($requestedPollsDate): self + { + $this->requestedPollsDate = $requestedPollsDate; + + return $this; + } } diff --git a/src/templates/owner-list.html.twig b/src/templates/owner-list.html.twig new file mode 100644 index 0000000..03dde73 --- /dev/null +++ b/src/templates/owner-list.html.twig @@ -0,0 +1,14 @@ +{#[Framadate][Réservé à l'auteur] Sondage: TESSSSSSSSSST#} +Voici la liste des {{ polls|length }} sondages Framadate que vous avez créé. +
+ + +Merci de votre confiance. +Framadate