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

model of stack of votes

This commit is contained in:
Baptiste Lemoine 2019-11-11 10:44:19 +01:00
parent d6fe2a6285
commit b7d1a51e2a
5 changed files with 443 additions and 202 deletions

View File

@ -2,8 +2,10 @@
namespace App\DataFixtures;
use App\Entity\Choice;
use App\Entity\Owner;
use App\Entity\Poll;
use App\Entity\Vote;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
@ -16,9 +18,9 @@ class AppPollFixtures extends Fixture {
// $product = new Product();
$poll = new Poll();
$poll->setTitle( 'démo sondage de texte' );
$poll->setTitle( 'citron ou orange' );
$poll->setKind( 'text' );
$poll->setDescription( 'description du sondage' );
$poll->setDescription( 'votre sorbert préféré' );
$poll->setAdminKey( 'dskjfsfdljkdsjlkdsfkjdsjdlkfs' );
$poll->setModificationPolicy( 'nobody' );
$poll->setCreationDate( new \DateTime() );
@ -27,6 +29,24 @@ class AppPollFixtures extends Fixture {
$poll->setOwner( $owner );
$owner->addPoll( $poll );
$choiceA = new Choice();
$choiceA->setName( 'citron' );
$choiceB = new Choice();
$choiceA->setName( 'orange' );
$poll
->addChoice( $choiceA )
->addChoice( $choiceB );
$voteA = new Vote();
$voteA->setPseudo( 'chuck norris' )
->setCreationDate( new DateTime() )
->setChoice( $choiceA );
$voteA = new Vote();
$voteA->setPseudo( 'Néo' )
->setCreationDate( new DateTime() )
->setChoice( $choiceB );
$manager->persist( $poll );

View File

@ -43,88 +43,125 @@ class Owner {
*/
private $comments;
/**
* @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="owner")
*/
private $stackOfVotes;
public function __construct() {
$this->polls = new ArrayCollection();
$this->comments = new ArrayCollection();
}
$this->polls = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->stackOfVotes = new ArrayCollection();
}
public function getId(): ?int {
return $this->id;
}
return $this->id;
}
public function getEmail(): ?string {
return $this->email;
}
return $this->email;
}
public function setEmail( string $email ): self {
$this->email = $email;
return $this;
}
$this->email = $email;
return $this;
}
public function getPseudo(): ?string {
return $this->pseudo;
}
return $this->pseudo;
}
public function setPseudo( string $pseudo ): self {
$this->pseudo = $pseudo;
return $this;
}
$this->pseudo = $pseudo;
return $this;
}
/**
* @return Collection|Poll[]
*/
public function getPolls(): Collection {
return $this->polls;
}
return $this->polls;
}
public function addPoll( Poll $poll ): self {
if ( ! $this->polls->contains( $poll ) ) {
$this->polls[] = $poll;
$poll->setOwner( $this );
}
return $this;
}
if ( ! $this->polls->contains( $poll ) ) {
$this->polls[] = $poll;
$poll->setOwner( $this );
}
return $this;
}
public function removePoll( Poll $poll ): self {
if ( $this->polls->contains( $poll ) ) {
$this->polls->removeElement( $poll );
// set the owning side to null (unless already changed)
if ( $poll->getOwner() === $this ) {
$poll->setOwner( null );
}
}
return $this;
}
if ( $this->polls->contains( $poll ) ) {
$this->polls->removeElement( $poll );
// set the owning side to null (unless already changed)
if ( $poll->getOwner() === $this ) {
$poll->setOwner( null );
}
}
return $this;
}
/**
* @return Collection|Comment[]
*/
public function getComments(): Collection {
return $this->comments;
}
return $this->comments;
}
public function addText( Comment $text ): self {
if ( ! $this->comments->contains( $text ) ) {
$this->comments[] = $text;
$text->setOwner( $this );
}
return $this;
}
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 );
}
}
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;
}
return $this;
}
/**
* @return Collection|StackOfVotes[]
*/
public function getStackOfVotes(): Collection
{
return $this->stackOfVotes;
}
public function addStackOfVote(StackOfVotes $stackOfVote): self
{
if (!$this->stackOfVotes->contains($stackOfVote)) {
$this->stackOfVotes[] = $stackOfVote;
$stackOfVote->setOwner($this);
}
return $this;
}
public function removeStackOfVote(StackOfVotes $stackOfVote): self
{
if ($this->stackOfVotes->contains($stackOfVote)) {
$this->stackOfVotes->removeElement($stackOfVote);
// set the owning side to null (unless already changed)
if ($stackOfVote->getOwner() === $this) {
$stackOfVote->setOwner(null);
}
}
return $this;
}
}

View File

@ -128,237 +128,254 @@ class Poll {
*/
public $comments;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\StackOfVotes", inversedBy="votes")
*/
private $stacksOfVotes;
public function __construct() {
$this->votes = new ArrayCollection();
$this->choices = new ArrayCollection();
$this->comments = new ArrayCollection();
}
$this->votes = new ArrayCollection();
$this->choices = new ArrayCollection();
$this->comments = new ArrayCollection();
}
public function getId(): ?int {
return $this->id;
}
return $this->id;
}
public function getTitle(): ?string {
return $this->title;
}
return $this->title;
}
public function setTitle( string $title ): self {
$this->title = $title;
return $this;
}
$this->title = $title;
return $this;
}
public function getCreationDate(): ?\DateTimeInterface {
return $this->creationDate;
}
return $this->creationDate;
}
public function setCreationDate( \DateTimeInterface $creationDate ): self {
$this->creationDate = $creationDate;
return $this;
}
$this->creationDate = $creationDate;
return $this;
}
public function getExpiracyDate(): ?\DateTimeInterface {
return $this->expiracyDate;
}
return $this->expiracyDate;
}
public function setExpiracyDate( \DateTimeInterface $expiracyDate ): self {
$this->expiracyDate = $expiracyDate;
return $this;
}
$this->expiracyDate = $expiracyDate;
return $this;
}
public function getOwner(): ?Owner {
return $this->owner;
}
return $this->owner;
}
public function setOwner( ?Owner $owner ): self {
$this->owner = $owner;
return $this;
}
$this->owner = $owner;
return $this;
}
/**
* @return Collection|Vote[]
*/
public function getVotes(): Collection {
return $this->votes;
}
return $this->votes;
}
public function addVote( Vote $vote ): self {
if ( ! $this->votes->contains( $vote ) ) {
$this->votes[] = $vote;
$vote->setPoll( $this );
}
return $this;
}
if ( ! $this->votes->contains( $vote ) ) {
$this->votes[] = $vote;
$vote->setPoll( $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->getPoll() === $this ) {
$vote->setPoll( null );
}
}
return $this;
}
if ( $this->votes->contains( $vote ) ) {
$this->votes->removeElement( $vote );
// set the owning side to null (unless already changed)
if ( $vote->getPoll() === $this ) {
$vote->setPoll( null );
}
}
return $this;
}
public function getAdminKey(): ?string {
return $this->adminKey;
}
return $this->adminKey;
}
public function setAdminKey( string $adminKey ): self {
$this->adminKey = $adminKey;
return $this;
}
$this->adminKey = $adminKey;
return $this;
}
public function getDescription(): ?string {
return $this->description;
}
return $this->description;
}
public function setDescription( string $description ): self {
$this->description = $description;
return $this;
}
$this->description = $description;
return $this;
}
public function getKind(): ?string {
return $this->kind;
}
return $this->kind;
}
public function setKind( string $kind ): self {
$this->kind = $kind;
return $this;
}
$this->kind = $kind;
return $this;
}
public function getCustomUrl(): ?string {
return $this->customUrl;
}
return $this->customUrl;
}
public function setCustomUrl( string $customUrl ): self {
$this->customUrl = $customUrl;
return $this;
}
$this->customUrl = $customUrl;
return $this;
}
public function getPassword(): ?string {
return $this->password;
}
return $this->password;
}
public function setPassword( string $password ): self {
$this->password = $password;
return $this;
}
$this->password = $password;
return $this;
}
public function getModificationPolicy(): ?string {
return $this->modificationPolicy;
}
return $this->modificationPolicy;
}
public function setModificationPolicy( string $modificationPolicy ): self {
$this->modificationPolicy = $modificationPolicy;
return $this;
}
$this->modificationPolicy = $modificationPolicy;
return $this;
}
public function getMailOnComment(): ?bool {
return $this->mailOnComment;
}
return $this->mailOnComment;
}
public function setMailOnComment( bool $mailOnComment ): self {
$this->mailOnComment = $mailOnComment;
return $this;
}
$this->mailOnComment = $mailOnComment;
return $this;
}
public function getMailOnVote(): ?bool {
return $this->mailOnVote;
}
return $this->mailOnVote;
}
public function setMailOnVote( bool $mailOnVote ): self {
$this->mailOnVote = $mailOnVote;
return $this;
}
$this->mailOnVote = $mailOnVote;
return $this;
}
public function getHideResults(): ?bool {
return $this->hideResults;
}
return $this->hideResults;
}
public function setHideResults( bool $hideResults ): self {
$this->hideResults = $hideResults;
return $this;
}
$this->hideResults = $hideResults;
return $this;
}
public function getShowResultEvenIfPasswords(): ?bool {
return $this->showResultEvenIfPasswords;
}
return $this->showResultEvenIfPasswords;
}
public function setShowResultEvenIfPasswords( bool $showResultEvenIfPasswords ): self {
$this->showResultEvenIfPasswords = $showResultEvenIfPasswords;
return $this;
}
$this->showResultEvenIfPasswords = $showResultEvenIfPasswords;
return $this;
}
/**
* @return Collection|Choice[]
*/
public function getChoices(): Collection {
return $this->choices;
}
return $this->choices;
}
public function addChoice( Choice $choice ): self {
if ( ! $this->choices->contains( $choice ) ) {
$this->choices[] = $choice;
$choice->setPoll( $this );
}
return $this;
}
if ( ! $this->choices->contains( $choice ) ) {
$this->choices[] = $choice;
$choice->setPoll( $this );
}
return $this;
}
public function removeChoice( Choice $choice ): self {
if ( $this->choices->contains( $choice ) ) {
$this->choices->removeElement( $choice );
// set the owning side to null (unless already changed)
if ( $choice->getPoll() === $this ) {
$choice->setPoll( null );
}
}
return $this;
}
if ( $this->choices->contains( $choice ) ) {
$this->choices->removeElement( $choice );
// set the owning side to null (unless already changed)
if ( $choice->getPoll() === $this ) {
$choice->setPoll( null );
}
}
return $this;
}
/**
* @return Collection|Comment[]
*/
public function getComments(): Collection {
return $this->comments;
}
return $this->comments;
}
public function addComment( Comment $comment ): self {
if ( ! $this->comments->contains( $comment ) ) {
$this->comments[] = $comment;
$comment->setPoll( $this );
}
return $this;
}
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 );
}
}
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;
}
return $this;
}
public function getStacksOfVotes(): ?StackOfVotes
{
return $this->stacksOfVotes;
}
public function setStacksOfVotes(?StackOfVotes $stacksOfVotes): self
{
$this->stacksOfVotes = $stacksOfVotes;
return $this;
}
}

117
src/Entity/StackOfVotes.php Normal file
View File

@ -0,0 +1,117 @@
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\StackOfVotesRepository")
*/
class StackOfVotes
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity="App\Entity\poll", mappedBy="stacksOfVotes")
*/
private $votes;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $pseudo;
/**
* @ORM\Column(type="string", length=255)
*/
private $modifierToken;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="stackOfVotes")
*/
private $owner;
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(poll $vote): self
{
if (!$this->votes->contains($vote)) {
$this->votes[] = $vote;
$vote->setStacksOfVotes($this);
}
return $this;
}
public function removeVote(poll $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 getModifierToken(): ?string
{
return $this->modifierToken;
}
public function setModifierToken(string $modifierToken): self
{
$this->modifierToken = $modifierToken;
return $this;
}
public function getOwner(): ?Owner
{
return $this->owner;
}
public function setOwner(?Owner $owner): self
{
$this->owner = $owner;
return $this;
}
}

View File

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