mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
Merge branch 'master' of https://framagit.org/tykayn/date-poll-api
This commit is contained in:
commit
1341b06478
File diff suppressed because it is too large
Load Diff
@ -1,144 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
namespace App\Entity;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* one poll choice, could be a text or a date
|
||||
* @ORM\Entity(repositoryClass="App\Repository\ChoiceRepository")
|
||||
* @Serializer\ExclusionPolicy("all")
|
||||
*/
|
||||
class Choice {
|
||||
/**
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue()
|
||||
* @ORM\Column(type="integer")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $id;
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @Serializer\Type("string")
|
||||
* @Serializer\Expose()
|
||||
* one poll choice, could be a text or a date
|
||||
* @ORM\Entity(repositoryClass="App\Repository\ChoiceRepository")
|
||||
* @Serializer\ExclusionPolicy("all")
|
||||
*/
|
||||
public $name;
|
||||
/**
|
||||
* @ORM\Column(type="string", length=1024, nullable=true)
|
||||
* @Serializer\Type("string")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $url;
|
||||
class Choice {
|
||||
/**
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue()
|
||||
* @ORM\Column(type="integer")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @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\Column(type="string", length=255, nullable=true)
|
||||
* @Serializer\Type("string")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $name;
|
||||
/**
|
||||
* @ORM\Column(type="string", length=1024, nullable=true)
|
||||
* @Serializer\Type("string")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $url;
|
||||
|
||||
public function __construct( $optionalName = null ) {
|
||||
$this->poll = new ArrayCollection();
|
||||
$this->votes = new ArrayCollection();
|
||||
$this->setDateTime( new DateTime() );
|
||||
if ( $optionalName ) {
|
||||
$this->setName( $optionalName );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @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;
|
||||
|
||||
public function display() {
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'date' => $this->getDateTime(),
|
||||
'text' => $this->getName(),
|
||||
'url' => $this->getUrl(),
|
||||
];
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public function setName( ?string $name ): self {
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPoll(): ?Poll {
|
||||
return $this->poll;
|
||||
}
|
||||
|
||||
public function setPoll( ?Poll $poll ): self {
|
||||
$this->poll = $poll;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|Vote[]
|
||||
*/
|
||||
public function getVotes(): Collection {
|
||||
return $this->votes;
|
||||
}
|
||||
|
||||
public function addVote( Vote $vote ): self {
|
||||
if ( ! $this->votes->contains( $vote ) ) {
|
||||
$this->votes[] = $vote;
|
||||
$vote->setChoice( $this );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeVote( Vote $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 );
|
||||
public function __construct( $optionalName = null ) {
|
||||
$this->poll = new ArrayCollection();
|
||||
$this->votes = new ArrayCollection();
|
||||
$this->setDateTime( new DateTime() );
|
||||
if ( $optionalName ) {
|
||||
$this->setName( $optionalName );
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUrl(): ?string {
|
||||
return $this->url;
|
||||
}
|
||||
public function display() {
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'date' => $this->getDateTime(),
|
||||
'text' => $this->getName(),
|
||||
'url' => $this->getUrl(),
|
||||
];
|
||||
}
|
||||
|
||||
public function setUrl( ?string $url ): self {
|
||||
$this->url = $url;
|
||||
public function getId(): ?int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
return $this;
|
||||
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;
|
||||
}
|
||||
|
||||
public function setName( ?string $name ): self {
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPoll(): ?Poll {
|
||||
return $this->poll;
|
||||
}
|
||||
|
||||
public function setPoll( ?Poll $poll ): self {
|
||||
$this->poll = $poll;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|Vote[]
|
||||
*/
|
||||
public function getVotes(): Collection {
|
||||
return $this->votes;
|
||||
}
|
||||
|
||||
public function addVote( Vote $vote ): self {
|
||||
if ( ! $this->votes->contains( $vote ) ) {
|
||||
$this->votes[] = $vote;
|
||||
$vote->setChoice( $this );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeVote( Vote $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;
|
||||
}
|
||||
|
||||
public function getUrl(): ?string {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function setUrl( ?string $url ): self {
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1044
src/Entity/Poll.php
1044
src/Entity/Poll.php
File diff suppressed because it is too large
Load Diff
@ -1,134 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* contains the votes for one answer to a poll
|
||||
* @ORM\Entity(repositoryClass="App\Repository\StackOfVotesRepository")
|
||||
*/
|
||||
class StackOfVotes {
|
||||
/**
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue()
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $id;
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255)
|
||||
* @Serializer\Type("string")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $pseudo;
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="stacksOfVotes", cascade={"persist","remove"})
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $votes;
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="stacksOfVotes", cascade={"persist"})
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
private $poll;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="stackOfVotes", cascade={"persist"})
|
||||
* @Serializer\Expose()
|
||||
* contains the votes for one answer to a poll
|
||||
* @ORM\Entity(repositoryClass="App\Repository\StackOfVotesRepository")
|
||||
*/
|
||||
private $owner;
|
||||
class StackOfVotes {
|
||||
/**
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue()
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $id;
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255)
|
||||
* @Serializer\Type("string")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $pseudo;
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="stacksOfVotes", cascade={"persist","remove"})
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $votes;
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="stacksOfVotes", cascade={"persist"})
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
private $poll;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="stackOfVotes", cascade={"persist"})
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
private $owner;
|
||||
|
||||
|
||||
public function display() {
|
||||
$tab = [
|
||||
'id' => $this->getId(),
|
||||
'pseudo' => '',
|
||||
'creation_date' => '',
|
||||
'votes' => [],
|
||||
];
|
||||
foreach ( $this->getVotes() as $vote ) {
|
||||
$tab[ 'votes' ][] = [
|
||||
'id' => $this->getId(),
|
||||
'vote_id' => $vote->getId(),
|
||||
'value' => $vote->getValue(),
|
||||
'choice_id' => $vote->getChoice()->getId(),
|
||||
'text' => $vote->getChoice()->getName(),
|
||||
public function display() {
|
||||
$tab = [
|
||||
'id' => $this->getId(),
|
||||
'pseudo' => '',
|
||||
'creation_date' => '',
|
||||
'votes' => [],
|
||||
];
|
||||
$tab[ 'pseudo' ] = $this->getOwner()->getPseudo();
|
||||
$tab[ 'creation_date' ] = $vote->getCreationDate();
|
||||
}
|
||||
|
||||
return $tab;
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
$this->votes = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|poll[]
|
||||
*/
|
||||
public function getVotes(): Collection {
|
||||
return $this->votes;
|
||||
}
|
||||
|
||||
public function addVote( Vote $vote ): self {
|
||||
if ( ! $this->votes->contains( $vote ) ) {
|
||||
$vote->setPoll( $this->getPoll() );
|
||||
|
||||
$this->votes[] = $vote;
|
||||
$vote->setStacksOfVotes( $this );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeVote( Vote $vote ): self {
|
||||
if ( $this->votes->contains( $vote ) ) {
|
||||
$this->votes->removeElement( $vote );
|
||||
// set the owning side to null (unless already changed)
|
||||
if ( $vote->getStacksOfVotes() === $this ) {
|
||||
$vote->setStacksOfVotes( null );
|
||||
// prefill votes with all choices ids
|
||||
foreach ( $this->getPoll()->getChoices() as $choice ) {
|
||||
$tab[ 'votes' ][ $choice->getId() ] = [
|
||||
'choice_id' => $choice->getId(),
|
||||
];
|
||||
}
|
||||
|
||||
foreach ( $this->getVotes() as $vote ) {
|
||||
$tab[ 'votes' ][ $vote->getChoice()->getId() ] = [
|
||||
'id' => $this->getId(),
|
||||
'vote_id' => $vote->getId(),
|
||||
'value' => $vote->getValue(),
|
||||
'choice_id' => $vote->getChoice()->getId(),
|
||||
'text' => $vote->getChoice()->getName(),
|
||||
];
|
||||
$tab[ 'pseudo' ] = $this->getOwner()->getPseudo();
|
||||
$tab[ 'creation_date' ] = $vote->getCreationDate();
|
||||
}
|
||||
|
||||
return $tab;
|
||||
}
|
||||
|
||||
return $this;
|
||||
public function __construct() {
|
||||
$this->votes = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|poll[]
|
||||
*/
|
||||
public function getVotes(): Collection {
|
||||
return $this->votes;
|
||||
}
|
||||
|
||||
public function addVote( Vote $vote ): self {
|
||||
if ( ! $this->votes->contains( $vote ) ) {
|
||||
$vote->setPoll( $this->getPoll() );
|
||||
|
||||
$this->votes[] = $vote;
|
||||
$vote->setStacksOfVotes( $this );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeVote( Vote $vote ): self {
|
||||
if ( $this->votes->contains( $vote ) ) {
|
||||
$this->votes->removeElement( $vote );
|
||||
// set the owning side to null (unless already changed)
|
||||
if ( $vote->getStacksOfVotes() === $this ) {
|
||||
$vote->setStacksOfVotes( null );
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPseudo(): ?string {
|
||||
return $this->pseudo;
|
||||
}
|
||||
|
||||
public function setPseudo( ?string $pseudo ): self {
|
||||
$this->pseudo = $pseudo;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOwner(): ?Owner {
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
public function setOwner( ?Owner $owner ): self {
|
||||
$this->owner = $owner;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPoll(): ?Poll {
|
||||
return $this->poll;
|
||||
}
|
||||
|
||||
public function setPoll( ?Poll $poll ): self {
|
||||
$this->poll = $poll;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPseudo(): ?string {
|
||||
return $this->pseudo;
|
||||
}
|
||||
|
||||
public function setPseudo( ?string $pseudo ): self {
|
||||
$this->pseudo = $pseudo;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOwner(): ?Owner {
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
public function setOwner( ?Owner $owner ): self {
|
||||
$this->owner = $owner;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPoll(): ?Poll {
|
||||
return $this->poll;
|
||||
}
|
||||
|
||||
public function setPoll( ?Poll $poll ): self {
|
||||
$this->poll = $poll;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user