expose config for poll

This commit is contained in:
Baptiste Lemoine 2019-11-06 14:54:04 +01:00
parent 9123faf3f1
commit 7e79048b59
7 changed files with 349 additions and 147 deletions

View File

@ -42,19 +42,6 @@ class DefaultController extends AbstractController {
] ); ] );
} }
/**
* @Get(
* path = "/poll/{id}/comments",
* name = "get_poll_comment",
* requirements = {"id"="\d+"}
* )
*/
public function getPollCommentsAction() {
return $this->json( [
'message' => 'here are your comments of the poll',
] );
}
/** /**
* @Get( * @Get(
* path = "/poll/all", * path = "/poll/all",
@ -109,7 +96,6 @@ class DefaultController extends AbstractController {
$owner->setEmail( $data[ 'owner' ][ 'email' ] ); $owner->setEmail( $data[ 'owner' ][ 'email' ] );
$foundOwner = $owner; $foundOwner = $owner;
} else { } else {
// die( $foundOwner->getPseudo() );
$userWasFound = true; $userWasFound = true;
} }
// link the owner and the poll // link the owner and the poll
@ -133,6 +119,20 @@ class DefaultController extends AbstractController {
} }
/**
* @Get(
* path = "/poll/{id}/comments",
* name = "get_poll_comment",
* requirements = {"id"="\d+"}
* )
*/
public function getPollCommentsAction( Poll $poll ) {
return $this->json( [
'message' => 'here are your comments of the poll',
'data' => $poll->getComments(),
] );
}
/** /**
* @Get( * @Get(
* path = "/poll/{id}", * path = "/poll/{id}",

View File

@ -5,6 +5,7 @@ namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
/** /**
* @ORM\Entity(repositoryClass="App\Repository\ChoiceRepository") * @ORM\Entity(repositoryClass="App\Repository\ChoiceRepository")
@ -19,113 +20,110 @@ class Choice {
/** /**
* @ORM\Column(type="string", length=255, nullable=true) * @ORM\Column(type="string", length=255, nullable=true)
* @Serializer\Type("string")
*/ */
private $name; private $name;
/** /**
* @ORM\Column(type="datetime", nullable=true) * @ORM\Column(type="datetime", nullable=true)
* @Serializer\Type("datetime")
*/ */
private $dateTime; private $dateTime;
/** /**
* @ORM\OneToMany(targetEntity="App\Entity\Poll", mappedBy="choices") * @ORM\OneToMany(targetEntity="App\Entity\Poll", mappedBy="choices")
* @Serializer\Type("App\Entity\Poll")
*/ */
private $poll; private $poll;
/** /**
* @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="choice") * @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="choice")
* @Serializer\Type("App\Entity\Choice")
*/ */
private $votes; private $votes;
public function __construct() public function __construct() {
{ $this->poll = new ArrayCollection();
$this->poll = new ArrayCollection(); $this->votes = new ArrayCollection();
$this->votes = new ArrayCollection(); }
}
public function getId(): ?int { public function getId(): ?int {
return $this->id; return $this->id;
} }
public function getName(): ?string { public function getName(): ?string {
return $this->name; return $this->name;
} }
public function setName( string $name ): self { public function setName( string $name ): self {
$this->name = $name; $this->name = $name;
return $this; return $this;
} }
public function getDateTime(): ?\DateTimeInterface { public function getDateTime(): ?\DateTimeInterface {
return $this->dateTime; return $this->dateTime;
} }
public function setDateTime( ?\DateTimeInterface $dateTime ): self { public function setDateTime( ?\DateTimeInterface $dateTime ): self {
$this->dateTime = $dateTime; $this->dateTime = $dateTime;
return $this;
}
/** return $this;
* @return Collection|Poll[] }
*/
public function getPoll(): Collection
{
return $this->poll;
}
public function addPoll(Poll $poll): self /**
{ * @return Collection|Poll[]
if (!$this->poll->contains($poll)) { */
$this->poll[] = $poll; public function getPoll(): Collection {
$poll->setChoices($this); return $this->poll;
} }
return $this; public function addPoll( Poll $poll ): self {
} if ( ! $this->poll->contains( $poll ) ) {
$this->poll[] = $poll;
$poll->setChoices( $this );
}
public function removePoll(Poll $poll): self return $this;
{ }
if ($this->poll->contains($poll)) {
$this->poll->removeElement($poll);
// set the owning side to null (unless already changed)
if ($poll->getChoices() === $this) {
$poll->setChoices(null);
}
}
return $this; public function removePoll( Poll $poll ): self {
} if ( $this->poll->contains( $poll ) ) {
$this->poll->removeElement( $poll );
// set the owning side to null (unless already changed)
if ( $poll->getChoices() === $this ) {
$poll->setChoices( null );
}
}
/** return $this;
* @return Collection|Choice[] }
*/
public function getVotes(): Collection
{
return $this->votes;
}
public function addVote(Choice $vote): self /**
{ * @return Collection|Choice[]
if (!$this->votes->contains($vote)) { */
$this->votes[] = $vote; public function getVotes(): Collection {
$vote->setChoice($this); return $this->votes;
} }
return $this; public function addVote( Choice $vote ): self {
} if ( ! $this->votes->contains( $vote ) ) {
$this->votes[] = $vote;
$vote->setChoice( $this );
}
public function removeVote(Choice $vote): self return $this;
{ }
if ($this->votes->contains($vote)) {
$this->votes->removeElement($vote);
// set the owning side to null (unless already changed)
if ($vote->getChoice() === $this) {
$vote->setChoice(null);
}
}
return $this; public function removeVote( Choice $vote ): self {
} if ( $this->votes->contains( $vote ) ) {
$this->votes->removeElement( $vote );
// set the owning side to null (unless already changed)
if ( $vote->getChoice() === $this ) {
$vote->setChoice( null );
}
}
return $this;
}
} }

81
src/Entity/Comment.php Normal file
View File

@ -0,0 +1,81 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\CommentRepository")
*/
class Comment {
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="text")
*/
private $owner;
/**
* @ORM\Column(type="text")
*/
private $text;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="comments")
*/
private $poll;
public function getId(): ?int {
return $this->id;
}
public function getOwner(): ?Owner {
return $this->owner;
}
public function setOwner( ?Owner $owner ): self {
$this->owner = $owner;
return $this;
}
public function getText(): ?string {
return $this->text;
}
public function setText( string $text ): self {
$this->text = $text;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface {
return $this->createdAt;
}
public function setCreatedAt( \DateTimeInterface $createdAt ): self {
$this->createdAt = $createdAt;
return $this;
}
public function getPoll(): ?Poll {
return $this->poll;
}
public function setPoll( ?Poll $poll ): self {
$this->poll = $poll;
return $this;
}
}

View File

@ -38,8 +38,14 @@ class Owner {
*/ */
private $polls; private $polls;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="owner")
*/
private $comments;
public function __construct() { public function __construct() {
$this->polls = new ArrayCollection(); $this->polls = new ArrayCollection();
$this->comments = new ArrayCollection();
} }
public function getId(): ?int { public function getId(): ?int {
@ -93,4 +99,32 @@ class Owner {
return $this; return $this;
} }
/**
* @return Collection|Comment[]
*/
public function getComments(): Collection {
return $this->comments;
}
public function addText( Comment $text ): self {
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;
}
} }

View File

@ -31,7 +31,7 @@ class Poll {
* @Serializer\Expose() * @Serializer\Expose()
* @Serializer\Type("string") * @Serializer\Type("string")
*/ */
private $customUrl; public $customUrl;
/** /**
* vote restricted by a password in md5 format * vote restricted by a password in md5 format
@ -44,25 +44,25 @@ class Poll {
* @Serializer\Expose() * @Serializer\Expose()
* @Serializer\Type("string") * @Serializer\Type("string")
*/ */
private $description; public $description;
/** /**
* @ORM\Column(type="datetime") * @ORM\Column(type="datetime")
* @Serializer\Expose() * @Serializer\Expose()
*/ */
private $creationDate; public $creationDate;
/** /**
* @ORM\Column(type="datetime") * @ORM\Column(type="datetime")
*/ */
private $expiracyDate; public $expiracyDate;
/** /**
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="polls",cascade={"persist"}) * @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="polls",cascade={"persist"})
* @ORM\JoinColumn(nullable=false) * @ORM\JoinColumn(nullable=false)
* @Serializer\Type("App\Entity\Owner") * @Serializer\Type("App\Entity\Owner")
*/ */
private $owner; public $owner;
/** /**
* used to allow administration * used to allow administration
@ -91,40 +91,47 @@ class Poll {
* @ORM\Column(type="boolean", nullable=true) * @ORM\Column(type="boolean", nullable=true)
* @Serializer\Type("boolean") * @Serializer\Type("boolean")
*/ */
private $mailOnComment; public $mailOnComment;
/** /**
* send a mail on a new vote * send a mail on a new vote
* @ORM\Column(type="boolean", nullable=true) * @ORM\Column(type="boolean", nullable=true)
* @Serializer\Type("boolean") * @Serializer\Type("boolean")
*/ */
private $mailOnVote; public $mailOnVote;
/** /**
* hide publicly results * hide publicly results
* @ORM\Column(type="boolean", nullable=true) * @ORM\Column(type="boolean", nullable=true)
* @Serializer\Type("boolean") * @Serializer\Type("boolean")
*/ */
private $hideResults; public $hideResults;
/** /**
* show publicly results even if there is a password to access the vote * show publicly results even if there is a password to access the vote
* @ORM\Column(type="boolean", nullable=true) * @ORM\Column(type="boolean", nullable=true)
* @Serializer\Type("boolean") * @Serializer\Type("boolean")
*/ */
private $showResultEvenIfPasswords; public $showResultEvenIfPasswords;
/** /**
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true,cascade={"persist"}) * @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true,cascade={"persist"})
* @Serializer\Type("App\Entity\Vote") * @Serializer\Type("App\Entity\Vote")
*/ */
private $votes; public $votes;
/** /**
* @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="poll", orphanRemoval=true,cascade={"persist"}) * @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="poll", orphanRemoval=true,cascade={"persist"})
* @Serializer\Type("App\Entity\Choice") * @Serializer\Type("App\Entity\Choice")
*/ */
private $choices; public $choices;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="poll")
* @Serializer\Type("App\Entity\Comment")
*/
public $comments;
public function __construct() { public function __construct() {
$this->votes = new ArrayCollection(); $this->votes = new ArrayCollection();
$this->choices = new ArrayCollection(); $this->choices = new ArrayCollection();
$this->comments = new ArrayCollection();
} }
public function getId(): ?int { public function getId(): ?int {
@ -326,4 +333,32 @@ class Poll {
return $this; return $this;
} }
/**
* @return Collection|Comment[]
*/
public function getComments(): Collection {
return $this->comments;
}
public function addComment( Comment $comment ): self {
if ( ! $this->comments->contains( $comment ) ) {
$this->comments[] = $comment;
$comment->setPoll( $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->getPoll() === $this ) {
$comment->setPoll( null );
}
}
return $this;
}
} }

View File

@ -3,6 +3,7 @@
namespace App\Entity; namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
/** /**
* @ORM\Entity(repositoryClass="App\Repository\VoteRepository") * @ORM\Entity(repositoryClass="App\Repository\VoteRepository")
@ -12,104 +13,107 @@ class Vote {
* @ORM\Id() * @ORM\Id()
* @ORM\GeneratedValue() * @ORM\GeneratedValue()
* @ORM\Column(type="integer") * @ORM\Column(type="integer")
* @Serializer\Type("integer")
*/ */
private $id; private $id;
/** /**
* @ORM\Column(type="string", length=255, nullable=true) * @ORM\Column(type="string", length=255, nullable=true)
* @Serializer\Type("string")
*/ */
private $pseudo; public $pseudo;
/** /**
* @ORM\Column(type="string", length=255, nullable=true) * @ORM\Column(type="string", length=255, nullable=true)
* @Serializer\Type("string")
*/ */
private $answerTxt; public $answerTxt;
/** /**
* @ORM\Column(type="datetime", nullable=true) * @ORM\Column(type="datetime", nullable=true)
* @Serializer\Type("datetime")
*/ */
private $answerDate; private $answerDate;
/** /**
* @ORM\Column(type="datetime") * @ORM\Column(type="datetime")
* @Serializer\Type("datetime")
*/ */
private $creationDate; public $creationDate;
/** /**
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="votes") * @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="votes")
* @ORM\JoinColumn(nullable=false) * @ORM\JoinColumn(nullable=false)
* @Serializer\Type("App\Entity\Poll")
*/ */
private $poll; private $poll;
/** /**
* @ORM\ManyToOne(targetEntity="App\Entity\Choice", inversedBy="votes") * @ORM\ManyToOne(targetEntity="App\Entity\Choice", inversedBy="votes")
* @ORM\JoinColumn(nullable=false) * @ORM\JoinColumn(nullable=false)
* @Serializer\Type("App\Entity\choice")
*/ */
private $choice; public $choice;
public function getId(): ?int { public function getId(): ?int {
return $this->id; return $this->id;
} }
public function getAnswerTxt(): ?string { public function getAnswerTxt(): ?string {
return $this->answerTxt; return $this->answerTxt;
} }
public function setAnswerTxt( ?string $answerTxt ): self { public function setAnswerTxt( ?string $answerTxt ): self {
$this->answerTxt = $answerTxt; $this->answerTxt = $answerTxt;
return $this; return $this;
} }
public function getAnswerDate(): ?\DateTimeInterface { public function getAnswerDate(): ?\DateTimeInterface {
return $this->answerDate; return $this->answerDate;
} }
public function setAnswerDate( ?\DateTimeInterface $answerDate ): self { public function setAnswerDate( ?\DateTimeInterface $answerDate ): self {
$this->answerDate = $answerDate; $this->answerDate = $answerDate;
return $this; return $this;
} }
public function getCreationDate(): ?\DateTimeInterface { public function getCreationDate(): ?\DateTimeInterface {
return $this->creationDate; return $this->creationDate;
} }
public function setCreationDate( \DateTimeInterface $creationDate ): self { public function setCreationDate( \DateTimeInterface $creationDate ): self {
$this->creationDate = $creationDate; $this->creationDate = $creationDate;
return $this; return $this;
} }
public function getPoll(): ?Poll { public function getPoll(): ?Poll {
return $this->poll; return $this->poll;
} }
public function setPoll( ?Poll $poll ): self { public function setPoll( ?Poll $poll ): self {
$this->poll = $poll; $this->poll = $poll;
return $this;
}
public function getPseudo(): ?string return $this;
{ }
return $this->pseudo;
}
public function setPseudo(?string $pseudo): self public function getPseudo(): ?string {
{ return $this->pseudo;
$this->pseudo = $pseudo; }
return $this; public function setPseudo( ?string $pseudo ): self {
} $this->pseudo = $pseudo;
public function getChoice(): ?Choice return $this;
{ }
return $this->choice;
}
public function setChoice(?Choice $choice): self public function getChoice(): ?Choice {
{ return $this->choice;
$this->choice = $choice; }
return $this; public function setChoice( ?Choice $choice ): self {
} $this->choice = $choice;
return $this;
}
} }

View File

@ -0,0 +1,50 @@
<?php
namespace App\Repository;
use App\Entity\Comment;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
/**
* @method Comment|null find($id, $lockMode = null, $lockVersion = null)
* @method Comment|null findOneBy(array $criteria, array $orderBy = null)
* @method Comment[] findAll()
* @method Comment[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class CommentRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Comment::class);
}
// /**
// * @return Comment[] Returns an array of Comment objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('c')
->andWhere('c.exampleField = :val')
->setParameter('val', $value)
->orderBy('c.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?Comment
{
return $this->createQueryBuilder('c')
->andWhere('c.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}