mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
⚡ url support in choices
This commit is contained in:
parent
150dc50003
commit
9d4a20783d
@ -169,12 +169,13 @@ class DefaultController extends AbstractController {
|
|||||||
$newpoll->setPassword( $data[ 'password' ] );
|
$newpoll->setPassword( $data[ 'password' ] );
|
||||||
}
|
}
|
||||||
// manage choices
|
// manage choices
|
||||||
$choices = $data[ 'choices_to_create' ];
|
$choices = $data[ 'answers' ];
|
||||||
foreach ( $choices as $c ) {
|
foreach ( $choices as $c ) {
|
||||||
$newChoice = new Choice();
|
$newChoice = new Choice();
|
||||||
$newChoice
|
$newChoice
|
||||||
->setPoll( $newpoll )
|
->setPoll( $newpoll )
|
||||||
->setName( $c );
|
->setUrl( $c[ 'url' ] )
|
||||||
|
->setName( $c[ 'text' ] );
|
||||||
$em->persist( $newChoice );
|
$em->persist( $newChoice );
|
||||||
}
|
}
|
||||||
$em->persist( $newpoll );
|
$em->persist( $newpoll );
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use DateTimeInterface;
|
||||||
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;
|
||||||
@ -27,53 +29,61 @@ class Choice {
|
|||||||
* @Serializer\Expose()
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
public $name;
|
public $name;
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=1024, nullable=true)
|
||||||
|
* @Serializer\Type("string")
|
||||||
|
* @Serializer\Expose()
|
||||||
|
*/
|
||||||
|
public $url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="datetime", nullable=true)
|
* @ORM\Column(type="datetime", nullable=true)
|
||||||
* @Serializer\Type("datetime")
|
* @Serializer\Type("datetime")
|
||||||
*/
|
*/
|
||||||
public $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"})
|
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="choices", cascade={"persist"})
|
||||||
* @Serializer\Type("App\Entity\Poll")
|
* @Serializer\Type("App\Entity\Poll")
|
||||||
*/
|
*/
|
||||||
private $poll;
|
private $poll;
|
||||||
|
|
||||||
/**
|
public function __construct( $optionalName = null ) {
|
||||||
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="choice", cascade={"persist"})
|
$this->poll = new ArrayCollection();
|
||||||
* @Serializer\Type("App\Entity\Vote")
|
$this->votes = new ArrayCollection();
|
||||||
*/
|
$this->setDateTime( new DateTime() );
|
||||||
public $votes;
|
if ( $optionalName ) {
|
||||||
|
$this->setName( $optionalName );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function display() {
|
public function display() {
|
||||||
return [
|
return [
|
||||||
'id' => $this->getId(),
|
'id' => $this->getId(),
|
||||||
'date' => $this->getDateTime(),
|
'date' => $this->getDateTime(),
|
||||||
'text' => $this->getName(),
|
'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 {
|
public function getId(): ?int {
|
||||||
return $this->id;
|
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 {
|
public function getName(): ?string {
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
@ -84,20 +94,16 @@ class Choice {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDateTime(): ?\DateTimeInterface {
|
|
||||||
return $this->dateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setDateTime( ?\DateTimeInterface $dateTime ): self {
|
|
||||||
$this->dateTime = $dateTime;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPoll(): ?Poll {
|
public function getPoll(): ?Poll {
|
||||||
return $this->poll;
|
return $this->poll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setPoll( ?Poll $poll ): self {
|
||||||
|
$this->poll = $poll;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection|Vote[]
|
* @return Collection|Vote[]
|
||||||
*/
|
*/
|
||||||
@ -125,4 +131,14 @@ class Choice {
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUrl(): ?string {
|
||||||
|
return $this->url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUrl( ?string $url ): self {
|
||||||
|
$this->url = $url;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user