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

fixture with polls and owner

This commit is contained in:
Baptiste Lemoine 2019-11-05 17:22:30 +01:00
parent 85f643bcce
commit 452083c74c
4 changed files with 305 additions and 87 deletions

View File

@ -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',
] );
}
} }

View File

@ -2,21 +2,65 @@
namespace App\DataFixtures; namespace App\DataFixtures;
use App\Entity\Owner;
use App\Entity\Poll; use App\Entity\Poll;
use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager;
class AppPollFixtures extends Fixture { class AppPollFixtures extends Fixture {
public function load( ObjectManager $manager ) { public function load( ObjectManager $manager ) {
$owner = new Owner();
$owner->setEmail( 'tktest@tktest.com' )
->setPseudo( 'tk_TEST' );
// $product = new Product(); // $product = new Product();
$poll = new Poll(); $poll = new Poll();
$poll->setTitle( 'démo sondage de texte' ); $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->setCreationDate( new \DateTime() );
$poll->setExpiracyDate( new \DateTime() );
$poll->setExpiracyDate( new \DateTime( ( time() + 3600 * 24 ) ) ); $poll->setMailOnVote( true );
$poll->setOwner( $owner );
$owner->addPoll( $poll );
$manager->persist( $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(); $manager->flush();
} }
} }

View File

@ -21,6 +21,20 @@ class Poll {
* @ORM\Column(type="string", length=255) * @ORM\Column(type="string", length=255)
*/ */
private $title; 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") * @ORM\Column(type="datetime")
@ -43,14 +57,46 @@ class Poll {
* @ORM\Column(type="string", length=255) * @ORM\Column(type="string", length=255)
*/ */
private $adminKey; 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) * @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true)
*/ */
private $votes; private $votes;
public function __construct() public function __construct() {
{
$this->votes = new ArrayCollection(); $this->votes = new ArrayCollection();
} }
@ -101,31 +147,128 @@ class Poll {
/** /**
* @return Collection|Vote[] * @return Collection|Vote[]
*/ */
public function getVotes(): Collection public function getVotes(): Collection {
{
return $this->votes; return $this->votes;
} }
public function addVote(Vote $vote): self public function addVote( Vote $vote ): self {
{ if ( ! $this->votes->contains( $vote ) ) {
if (!$this->votes->contains($vote)) {
$this->votes[] = $vote; $this->votes[] = $vote;
$vote->setPoll($this); $vote->setPoll( $this );
} }
return $this; return $this;
} }
public function removeVote(Vote $vote): self public function removeVote( Vote $vote ): self {
{ if ( $this->votes->contains( $vote ) ) {
if ($this->votes->contains($vote)) { $this->votes->removeElement( $vote );
$this->votes->removeElement($vote);
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ($vote->getPoll() === $this) { if ( $vote->getPoll() === $this ) {
$vote->setPoll(null); $vote->setPoll( null );
} }
} }
return $this; 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;
}
} }

View File

@ -81,6 +81,18 @@ class Vote {
public function setPoll( ?Poll $poll ): self { public function setPoll( ?Poll $poll ): self {
$this->poll = $poll; $this->poll = $poll;
return $this;
}
public function getPseudo(): ?string
{
return $this->pseudo;
}
public function setPseudo(?string $pseudo): self
{
$this->pseudo = $pseudo;
return $this; return $this;
} }
} }