1
0
mirror of https://framagit.org/tykayn/date-poll-api synced 2023-08-25 08:23:11 +02:00

start email to owner listing polls

This commit is contained in:
Baptiste Lemoine 2020-01-02 16:34:23 +01:00
parent 54140bf859
commit 2d69b4a18d
3 changed files with 182 additions and 105 deletions

View File

@ -68,6 +68,53 @@ class DefaultController extends AbstractController {
200 ); 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( * @Post(
* path = "/poll", * path = "/poll",

View File

@ -53,162 +53,178 @@ class Owner {
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"}) * @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"})
*/ */
private $createdAt; private $createdAt;
/**
* @ORM\Column(type="requested_polls_date" , options={"default"="CURRENT_TIMESTAMP"},nullable=true)
*/
private $requestedPollsDate;
public function __construct() { public function __construct() {
$this->polls = new ArrayCollection(); $this->polls = new ArrayCollection();
$this->comments = new ArrayCollection(); $this->comments = new ArrayCollection();
$this->stackOfVotes = new ArrayCollection(); $this->stackOfVotes = new ArrayCollection();
$this->setCreatedAt( new \DateTime() ); $this->setCreatedAt( new \DateTime() );
$this->setModifierToken( uniqid() ); $this->setModifierToken( uniqid() );
} }
public function getId(): ?int { public function getId(): ?int {
return $this->id; return $this->id;
} }
public function getEmail(): ?string { public function getEmail(): ?string {
return $this->email; return $this->email;
} }
public function setEmail( string $email ): self { public function setEmail( string $email ): self {
$this->email = $email; $this->email = $email;
return $this; return $this;
} }
public function getPseudo(): ?string { public function getPseudo(): ?string {
return $this->pseudo; return $this->pseudo;
} }
public function setPseudo( string $pseudo ): self { public function setPseudo( string $pseudo ): self {
$this->pseudo = $pseudo; $this->pseudo = $pseudo;
return $this; return $this;
} }
/** /**
* @return Collection|Poll[] * @return Collection|Poll[]
*/ */
public function getPolls(): Collection { public function getPolls(): Collection {
return $this->polls; return $this->polls;
} }
public function addPoll( Poll $poll ): self { public function addPoll( Poll $poll ): self {
if ( ! $this->polls->contains( $poll ) ) { if ( ! $this->polls->contains( $poll ) ) {
$this->polls[] = $poll; $this->polls[] = $poll;
$poll->setOwner( $this ); $poll->setOwner( $this );
} }
return $this; return $this;
} }
public function removePoll( Poll $poll ): self { public function removePoll( Poll $poll ): self {
if ( $this->polls->contains( $poll ) ) { if ( $this->polls->contains( $poll ) ) {
$this->polls->removeElement( $poll ); $this->polls->removeElement( $poll );
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ( $poll->getOwner() === $this ) { if ( $poll->getOwner() === $this ) {
$poll->setOwner( null ); $poll->setOwner( null );
} }
} }
return $this; return $this;
} }
/** /**
* @return Collection|Comment[] * @return Collection|Comment[]
*/ */
public function getComments(): Collection { public function getComments(): Collection {
return $this->comments; return $this->comments;
} }
public function addText( Comment $text ): self { public function addText( Comment $text ): self {
if ( ! $this->comments->contains( $text ) ) { if ( ! $this->comments->contains( $text ) ) {
$this->comments[] = $text; $this->comments[] = $text;
$text->setOwner( $this ); $text->setOwner( $this );
} }
return $this; return $this;
} }
public function removeText( Comment $text ): self { public function removeText( Comment $text ): self {
if ( $this->comments->contains( $text ) ) { if ( $this->comments->contains( $text ) ) {
$this->comments->removeElement( $text ); $this->comments->removeElement( $text );
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ( $text->getOwner() === $this ) { if ( $text->getOwner() === $this ) {
$text->setOwner( null ); $text->setOwner( null );
} }
} }
return $this; return $this;
} }
/** /**
* @return Collection|StackOfVotes[] * @return Collection|StackOfVotes[]
*/ */
public function getStackOfVotes(): Collection { public function getStackOfVotes(): Collection {
return $this->stackOfVotes; return $this->stackOfVotes;
} }
public function addStackOfVote( StackOfVotes $stackOfVote ): self { public function addStackOfVote( StackOfVotes $stackOfVote ): self {
if ( ! $this->stackOfVotes->contains( $stackOfVote ) ) { if ( ! $this->stackOfVotes->contains( $stackOfVote ) ) {
$this->stackOfVotes[] = $stackOfVote; $this->stackOfVotes[] = $stackOfVote;
$stackOfVote->setOwner( $this ); $stackOfVote->setOwner( $this );
} }
return $this; return $this;
} }
public function removeStackOfVote( StackOfVotes $stackOfVote ): self { public function removeStackOfVote( StackOfVotes $stackOfVote ): self {
if ( $this->stackOfVotes->contains( $stackOfVote ) ) { if ( $this->stackOfVotes->contains( $stackOfVote ) ) {
$this->stackOfVotes->removeElement( $stackOfVote ); $this->stackOfVotes->removeElement( $stackOfVote );
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ( $stackOfVote->getOwner() === $this ) { if ( $stackOfVote->getOwner() === $this ) {
$stackOfVote->setOwner( null ); $stackOfVote->setOwner( null );
} }
} }
return $this; return $this;
} }
public function getModifierToken(): ?string { public function getModifierToken(): ?string {
return $this->modifierToken; return $this->modifierToken;
} }
public function setModifierToken( string $modifierToken ): self { public function setModifierToken( string $modifierToken ): self {
$this->modifierToken = $modifierToken; $this->modifierToken = $modifierToken;
return $this; return $this;
} }
public function addComment( Comment $comment ): self { public function addComment( Comment $comment ): self {
if ( ! $this->comments->contains( $comment ) ) { if ( ! $this->comments->contains( $comment ) ) {
$this->comments[] = $comment; $this->comments[] = $comment;
$comment->setOwner( $this ); $comment->setOwner( $this );
} }
return $this; return $this;
} }
public function removeComment( Comment $comment ): self { public function removeComment( Comment $comment ): self {
if ( $this->comments->contains( $comment ) ) { if ( $this->comments->contains( $comment ) ) {
$this->comments->removeElement( $comment ); $this->comments->removeElement( $comment );
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ( $comment->getOwner() === $this ) { if ( $comment->getOwner() === $this ) {
$comment->setOwner( null ); $comment->setOwner( null );
} }
} }
return $this; return $this;
} }
public function getCreatedAt(): ?\DateTimeInterface { public function getCreatedAt(): ?\DateTimeInterface {
return $this->createdAt; return $this->createdAt;
} }
public function setCreatedAt( \DateTimeInterface $createdAt ): self { 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;
}
} }

View File

@ -0,0 +1,14 @@
{#[Framadate][Réservé à l'auteur] Sondage: TESSSSSSSSSST#}
Voici la liste des {{ polls|length }} sondages Framadate que vous avez créé.
<hr>
<ul>
{% for p in polls %}
<li>
{{ p.title }}
{{ p.adminKey }}
</li>
{% endfor %}
</ul>
Merci de votre confiance.
Framadate