From 452083c74c235934304c63da6c516c88352b28ed Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Tue, 5 Nov 2019 17:22:30 +0100 Subject: [PATCH] :zap: fixture with polls and owner --- src/Controller/DefaultController.php | 19 ++ src/DataFixtures/AppPollFixtures.php | 48 ++++- src/Entity/Poll.php | 263 +++++++++++++++++++++------ src/Entity/Vote.php | 62 ++++--- 4 files changed, 305 insertions(+), 87 deletions(-) diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index 486bf14..dd3fec7 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -131,4 +131,23 @@ class DefaultController extends AbstractController { ] ); } + + public function deletePollAction() { + return $this->json( [ + 'message' => 'boom', + ] ); + } + + public function deletePollCommentsAction() { + return $this->json( [ + 'message' => 'boom', + ] ); + } + + public function deletePollVotesAction() { + return $this->json( [ + 'message' => 'boom', + ] ); + } + } diff --git a/src/DataFixtures/AppPollFixtures.php b/src/DataFixtures/AppPollFixtures.php index 1bf6e4e..26c17d2 100644 --- a/src/DataFixtures/AppPollFixtures.php +++ b/src/DataFixtures/AppPollFixtures.php @@ -2,21 +2,65 @@ namespace App\DataFixtures; +use App\Entity\Owner; use App\Entity\Poll; use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Common\Persistence\ObjectManager; class AppPollFixtures extends Fixture { public function load( ObjectManager $manager ) { + + $owner = new Owner(); + $owner->setEmail( 'tktest@tktest.com' ) + ->setPseudo( 'tk_TEST' ); + // $product = new Product(); $poll = new Poll(); $poll->setTitle( 'démo sondage de texte' ); + $poll->setKind( 'text' ); + $poll->setDescription( 'description du sondage' ); + $poll->setAdminKey( 'dskjfsfdljkdsjlkdsfkjdsjdlkfs' ); + $poll->setModificationPolicy( 'nobody' ); $poll->setCreationDate( new \DateTime() ); - - $poll->setExpiracyDate( new \DateTime( ( time() + 3600 * 24 ) ) ); + $poll->setExpiracyDate( new \DateTime() ); + $poll->setMailOnVote( true ); + $poll->setOwner( $owner ); + $owner->addPoll( $poll ); $manager->persist( $poll ); + + $poll = new Poll(); + $poll->setTitle( 'démo sondage de texte 2' ); + $poll->setDescription( 'description du sondage 2' ); + $poll->setKind( 'date' ); + $poll->setAdminKey( 'dskjfsfdljkdsjlkdsfkjdsjdlkfs' ); + $poll->setModificationPolicy( 'self' ); + $poll->setMailOnComment( true ); + $poll->setCreationDate( new \DateTime() ); + $poll->setExpiracyDate( new \DateTime() ); + $poll->setOwner( $owner ); + $owner->addPoll( $poll ); + + $manager->persist( $poll ); + + $poll = new Poll(); + $poll->setTitle( 'accès restreint sondage de texte' ); + $poll->setKind( 'text' ); + $poll->setPassword( md5( 'mot_de_passe_super' ) ); + $poll->setModificationPolicy( 'everybody' ); + $poll->setDescription( 'description du sondage' ); + $poll->setAdminKey( 'dskjfsfdljkdsjlkdsfkjdsjdlkfs' ); + $poll->setCreationDate( new \DateTime() ); + $poll->setExpiracyDate( new \DateTime() ); + $poll->setMailOnComment( true ); + $poll->setMailOnVote( true ); + $poll->setOwner( $owner ); + $owner->addPoll( $poll ); + + $manager->persist( $poll ); + $manager->persist( $owner ); + $manager->flush(); } } diff --git a/src/Entity/Poll.php b/src/Entity/Poll.php index 245f9aa..b4f2343 100644 --- a/src/Entity/Poll.php +++ b/src/Entity/Poll.php @@ -21,6 +21,20 @@ class Poll { * @ORM\Column(type="string", length=255) */ private $title; + /** + * @ORM\Column(type="string", length=255, nullable=true) + */ + private $customUrl; + + /** + * vote restricted by a password + * @ORM\Column(type="string", length=255, nullable=true) + */ + private $password; + /** + * @ORM\Column(type="string", length=1000) + */ + private $description; /** * @ORM\Column(type="datetime") @@ -43,89 +57,218 @@ class Poll { * @ORM\Column(type="string", length=255) */ private $adminKey; + /** + * kind of poll, text or date + * @ORM\Column(type="string", length=255) + */ + private $kind; + /** + * kind of way the people can modify the poll + * everybody - can modify votes + * self - one can only modify its own vote + * nobody - no one can modify the votes (excepted admin), pray to have it right at first + * @ORM\Column(type="string", length=255) + */ + private $modificationPolicy; + /** + * send a mail on a new comment + * @ORM\Column(type="boolean", nullable=true) + */ + private $mailOnComment; + /** + * send a mail on a new vote + * @ORM\Column(type="boolean", nullable=true) + */ + private $mailOnVote; + /** + * hide publicly results + * @ORM\Column(type="boolean", nullable=true) + */ + private $hideResults; + /** + * show publicly results even if there is a password to access the vote + * @ORM\Column(type="boolean", nullable=true) + */ + private $showResultEvenIfPasswords; - /** - * @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true) - */ - private $votes; + /** + * @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true) + */ + private $votes; - public function __construct() - { - $this->votes = new ArrayCollection(); - } + public function __construct() { + $this->votes = 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 Collection|Vote[] - */ - public function getVotes(): Collection - { - return $this->votes; - } + return $this; + } - public function addVote(Vote $vote): self - { - if (!$this->votes->contains($vote)) { - $this->votes[] = $vote; - $vote->setPoll($this); - } + /** + * @return Collection|Vote[] + */ + public function getVotes(): Collection { + return $this->votes; + } - return $this; - } + public function addVote( Vote $vote ): self { + if ( ! $this->votes->contains( $vote ) ) { + $this->votes[] = $vote; + $vote->setPoll( $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; + } - 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; + } + + public function getAdminKey(): ?string { + return $this->adminKey; + } + + public function setAdminKey( string $adminKey ): self { + $this->adminKey = $adminKey; + + return $this; + } + + public function getDescription(): ?string { + return $this->description; + } + + public function setDescription( string $description ): self { + $this->description = $description; + + return $this; + } + + public function getKind(): ?string { + return $this->kind; + } + + public function setKind( string $kind ): self { + $this->kind = $kind; + + return $this; + } + + public function getCustomUrl(): ?string { + return $this->customUrl; + } + + public function setCustomUrl( string $customUrl ): self { + $this->customUrl = $customUrl; + + return $this; + } + + public function getPassword(): ?string { + return $this->password; + } + + public function setPassword( string $password ): self { + $this->password = $password; + + return $this; + } + + public function getModificationPolicy(): ?string { + return $this->modificationPolicy; + } + + public function setModificationPolicy( string $modificationPolicy ): self { + $this->modificationPolicy = $modificationPolicy; + + return $this; + } + + public function getMailOnComment(): ?bool { + return $this->mailOnComment; + } + + public function setMailOnComment( bool $mailOnComment ): self { + $this->mailOnComment = $mailOnComment; + + return $this; + } + + public function getMailOnVote(): ?bool { + return $this->mailOnVote; + } + + public function setMailOnVote( bool $mailOnVote ): self { + $this->mailOnVote = $mailOnVote; + + return $this; + } + + public function getHideResults(): ?bool { + return $this->hideResults; + } + + public function setHideResults( bool $hideResults ): self { + $this->hideResults = $hideResults; + + return $this; + } + + public function getShowResultEvenIfPasswords(): ?bool { + return $this->showResultEvenIfPasswords; + } + + public function setShowResultEvenIfPasswords( bool $showResultEvenIfPasswords ): self { + $this->showResultEvenIfPasswords = $showResultEvenIfPasswords; + + return $this; + } } diff --git a/src/Entity/Vote.php b/src/Entity/Vote.php index 83f8b15..83bfe00 100644 --- a/src/Entity/Vote.php +++ b/src/Entity/Vote.php @@ -41,46 +41,58 @@ class Vote { private $poll; public function getId(): ?int { - return $this->id; - } + return $this->id; + } public function getAnswerTxt(): ?string { - return $this->answerTxt; - } + return $this->answerTxt; + } public function setAnswerTxt( ?string $answerTxt ): self { - $this->answerTxt = $answerTxt; - - return $this; - } + $this->answerTxt = $answerTxt; + + return $this; + } public function getAnswerDate(): ?\DateTimeInterface { - return $this->answerDate; - } + return $this->answerDate; + } public function setAnswerDate( ?\DateTimeInterface $answerDate ): self { - $this->answerDate = $answerDate; - - return $this; - } + $this->answerDate = $answerDate; + + 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 getPoll(): ?Poll { - return $this->poll; - } + return $this->poll; + } public function setPoll( ?Poll $poll ): self { - $this->poll = $poll; + $this->poll = $poll; + + return $this; + } - return $this; - } + public function getPseudo(): ?string + { + return $this->pseudo; + } + + public function setPseudo(?string $pseudo): self + { + $this->pseudo = $pseudo; + + return $this; + } }