diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index 37435af..b1f237d 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -169,12 +169,13 @@ class DefaultController extends AbstractController { $newpoll->setPassword( $data[ 'password' ] ); } // manage choices - $choices = $data[ 'choices_to_create' ]; + $choices = $data[ 'answers' ]; foreach ( $choices as $c ) { $newChoice = new Choice(); $newChoice ->setPoll( $newpoll ) - ->setName( $c ); + ->setUrl( $c[ 'url' ] ) + ->setName( $c[ 'text' ] ); $em->persist( $newChoice ); } $em->persist( $newpoll ); diff --git a/src/Entity/Choice.php b/src/Entity/Choice.php index 81da4ed..4b03863 100644 --- a/src/Entity/Choice.php +++ b/src/Entity/Choice.php @@ -2,6 +2,8 @@ namespace App\Entity; +use DateTime; +use DateTimeInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; @@ -27,53 +29,61 @@ class Choice { * @Serializer\Expose() */ public $name; + /** + * @ORM\Column(type="string", length=1024, nullable=true) + * @Serializer\Type("string") + * @Serializer\Expose() + */ + public $url; /** * @ORM\Column(type="datetime", nullable=true) * @Serializer\Type("datetime") */ public $dateTime; - + /** + * @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="choice", cascade={"persist"}) + * @Serializer\Type("App\Entity\Vote") + */ + public $votes; /** * @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="choices", cascade={"persist"}) * @Serializer\Type("App\Entity\Poll") */ private $poll; - /** - * @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="choice", cascade={"persist"}) - * @Serializer\Type("App\Entity\Vote") - */ - public $votes; + public function __construct( $optionalName = null ) { + $this->poll = new ArrayCollection(); + $this->votes = new ArrayCollection(); + $this->setDateTime( new DateTime() ); + if ( $optionalName ) { + $this->setName( $optionalName ); + } + } public function display() { return [ 'id' => $this->getId(), 'date' => $this->getDateTime(), 'text' => $this->getName(), + 'url' => $this->getUrl(), ]; } - public function __construct( $optionalName = null ) { - $this->poll = new ArrayCollection(); - $this->votes = new ArrayCollection(); - $this->setDateTime( new \DateTime() ); - if ( $optionalName ) { - $this->setName( $optionalName ); - } - } - - - public function setPoll( ?Poll $poll ): self { - $this->poll = $poll; - - return $this; - } - public function getId(): ?int { return $this->id; } + public function getDateTime(): ?DateTimeInterface { + return $this->dateTime; + } + + public function setDateTime( ?DateTimeInterface $dateTime ): self { + $this->dateTime = $dateTime; + + return $this; + } + public function getName(): ?string { return $this->name; } @@ -84,20 +94,16 @@ class Choice { return $this; } - public function getDateTime(): ?\DateTimeInterface { - return $this->dateTime; - } - - public function setDateTime( ?\DateTimeInterface $dateTime ): self { - $this->dateTime = $dateTime; - - return $this; - } - public function getPoll(): ?Poll { return $this->poll; } + public function setPoll( ?Poll $poll ): self { + $this->poll = $poll; + + return $this; + } + /** * @return Collection|Vote[] */ @@ -125,4 +131,14 @@ class Choice { return $this; } + + public function getUrl(): ?string { + return $this->url; + } + + public function setUrl( ?string $url ): self { + $this->url = $url; + + return $this; + } }