From c0791d52acb455566c05bfa0d32383a85892e149 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Fri, 30 Apr 2021 15:34:04 +0200 Subject: [PATCH] group date and slices in display of poll --- src/Entity/Choice.php | 23 +- src/Entity/Poll.php | 1237 +++++++++++++++++++++-------------------- 2 files changed, 655 insertions(+), 605 deletions(-) diff --git a/src/Entity/Choice.php b/src/Entity/Choice.php index 6e00c37..5cbec6b 100755 --- a/src/Entity/Choice.php +++ b/src/Entity/Choice.php @@ -61,12 +61,23 @@ class Choice { } public function display( $kind = 'text' ): array { - $fields = [ - 'id' => $this->getId(), - 'created_at' => $this->getCreatedAtAsString(), - 'name' => $this->getName(), - 'url' => $this->getUrl(), - ]; + if($kind == 'text'){ + $fields = [ + 'id' => $this->getId(), + 'created_at' => $this->getCreatedAtAsString(), + 'name' => $this->getName(), + 'url' => $this->getUrl(), + ]; + } + elseif($kind=='date'){ + $fields = [ + 'id' => $this->getId(), + 'created_at' => $this->getCreatedAtAsString(), + 'name' => $this->getName(), +// 'url' => $this->getUrl(), + ]; + } + return $fields; } diff --git a/src/Entity/Poll.php b/src/Entity/Poll.php index c6838b2..e349491 100755 --- a/src/Entity/Poll.php +++ b/src/Entity/Poll.php @@ -1,719 +1,758 @@ ") + * @Serializer\Expose() + */ + public $votes; + /** + * @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) + * @Serializer\Expose() + */ + public $stacksOfVotes; + /** + * @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) + * @Serializer\Expose() + * @Serializer\Type("ArrayCollection") + */ + public $choices; + /** + * @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) + * @Serializer\Expose() + * @Serializer\Type("ArrayCollection") + */ + public $comments; + /** + * number of days from now for default expiracy date + * @var int + * @Serializer\Expose() + */ + public $defaultExpiracyDaysFromNow = 60; + /** + * vote restricted by a password in md5 format + * @ORM\Column(type="string", length=255, nullable=true) + */ + private $password; + /** + * used to allow administration + * @ORM\Column(type="string", length=255) + * @Serializer\Type("string") + */ + private $adminKey; + private $maxChoicesLimit = 25; - /** - * max number of choices people can answer in a stack of vote. for text polls only, not date kind. - * by default, people can check as many answers as they want. - * If the question is "check your 3 favourite flavours" and displays 10 flavours, only the first 3 clicked will be taken into account. GUI should be able to make this clear and togglable so that people can change their 3 favourite flavours in their answer. - * @ORM\Column(type="smallint", nullable=true) - * @Serializer\Type("smallint") - * @Serializer\Expose() - */ - public $choicesMax = - 1; + public function __construct() { - /** - * people can add comments - * @ORM\Column(type="boolean", nullable=true) - * @Serializer\Type("boolean") - * @Serializer\Expose() - */ - public $commentsAllowed = true; + $this->initiate(); + $this->setCreatedAt( new DateTime() ); + $this->setAdminKey( $this->generateRandomKey() ); + $this->votes = new ArrayCollection(); + $this->stacksOfVotes = new ArrayCollection(); + $this->choices = new ArrayCollection(); + $this->comments = new ArrayCollection(); + } - /** - * 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) - * @Serializer\Type("string") - * @Serializer\Expose() - */ - public $modificationPolicy = 'everybody'; - /** - * send a mail on a new comment - * @ORM\Column(type="boolean", nullable=true) - * @Serializer\Type("boolean") - * @Serializer\Expose() - */ - public $mailOnComment = true; - /** - * send a mail on a new vote - * @ORM\Column(type="boolean", nullable=true) - * @Serializer\Type("boolean") - * @Serializer\Expose() - */ - public $mailOnVote = false; - /** - * hide publicly results - * @ORM\Column(type="boolean", nullable=true) - * @Serializer\Type("boolean") - * @Serializer\Expose() - */ - public $hideResults = false; - /** - * show publicly results even if there is a password to access the vote - * @ORM\Column(type="boolean", nullable=true) - * @Serializer\Type("boolean") - * @Serializer\Expose() - */ - public $showResultEvenIfPasswords = false; - /** - * @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) - * @Serializer\Type("ArrayCollection") - * @Serializer\Expose() - */ - public $votes; - /** - * @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) - * @Serializer\Expose() - */ - public $stacksOfVotes; - /** - * @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) - * @Serializer\Expose() - * @Serializer\Type("ArrayCollection") - */ - public $choices; - /** - * @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) - * @Serializer\Expose() - * @Serializer\Type("ArrayCollection") - */ - public $comments; - /** - * number of days from now for default expiracy date - * @var int - * @Serializer\Expose() - */ - public $defaultExpiracyDaysFromNow = 60; - /** - * vote restricted by a password in md5 format - * @ORM\Column(type="string", length=255, nullable=true) - */ - private $password; - /** - * used to allow administration - * @ORM\Column(type="string", length=255) - * @Serializer\Type("string") - */ - private $adminKey; - private $maxChoicesLimit = 25; + private function initiate() { + $this->votes = new ArrayCollection(); + $this->stacksOfVotes = new ArrayCollection(); + $this->choices = new ArrayCollection(); + $this->comments = new ArrayCollection(); + $this->setAdminKey( $this->generateRandomKey() ); + $this->setCreatedAt( new DateTime() ); + $this->setExpiracyDate( $this->addDaysToDate( + new DateTime(), + $this->defaultExpiracyDaysFromNow + ) ); + $this->setAllowedAnswers( [ 'yes', 'maybe', 'no' ] ); + } - public function __construct() { + public function setCreatedAt( DateTimeInterface $createdAt ): self { + $this->createdAt = $createdAt; - $this->initiate(); - $this->setCreatedAt( new DateTime() ); - $this->setAdminKey( $this->generateRandomKey() ); - $this->votes = new ArrayCollection(); - $this->stacksOfVotes = new ArrayCollection(); - $this->choices = new ArrayCollection(); - $this->comments = new ArrayCollection(); + return $this; + } + + public function displayForAdmin() { + $content = $this->display(); + $content[ 'owner' ] = $this->getOwner()->displayForAdmin(); + $content[ 'admin_key' ] = $this->getAdminKey(); + $content[ 'password_hash' ] = $this->getPassword(); + $content[ 'id' ] = $this->getId(); + + return $content; + } + + // counts each number of answer for this choice + + public function display() { + + $computedAnswers = $this->computeAnswers(); + $displayedStackOfVotes = []; + foreach ( $this->getStacksOfVotes() as $stack ) { + $displayedStackOfVotes[] = $stack->display(); + } + $displayedChoices = []; + foreach ( $this->getChoices() as $choice ) { + $displayedChoices[] = $choice->display( $this->getKind() ); + } + $displayedComments = []; + foreach ( $this->getComments() as $comment ) { + $displayedComments[] = $comment->display(); } - private function initiate() { - $this->votes = new ArrayCollection(); - $this->stacksOfVotes = new ArrayCollection(); - $this->choices = new ArrayCollection(); - $this->comments = new ArrayCollection(); - $this->setAdminKey( $this->generateRandomKey() ); - $this->setCreatedAt( new DateTime() ); - $this->setExpiracyDate( $this->addDaysToDate( - new DateTime(), - $this->defaultExpiracyDaysFromNow - ) ); - $this->setAllowedAnswers( [ 'yes', 'maybe', 'no' ] ); + + $resp = [ + 'title' => $this->getTitle(), + 'description' => $this->getDescription(), + 'created_at' => $this->getCreatedAt()->format( 'c' ), + 'expiracy_date' => $this->getExpiracyDate()->format( 'c' ), + 'votes_max' => $this->getVotesMax(), + 'custom_url' => $this->getCustomUrl(), + 'choices_max' => $this->getChoicesMax(), + 'kind' => $this->getKind(), + 'allowed_answers' => $this->getAllowedAnswers(), + 'votes_allowed' => $this->getVotesAllowed(), + 'modification_policy' => $this->getModificationPolicy(), + 'hide_results' => $this->getHideResults(), + 'show_results_even_if_password' => $this->getShowResultEvenIfPasswords(), + 'owner' => [ + 'pseudo' => $this->getOwner()->getPseudo(), + ] + , + 'password_protected' => $this->getPassword() ? 'yes' : 'no', + 'max_score' => $computedAnswers[ 'max_score' ], + 'choices' => $computedAnswers[ 'answers' ], + 'stacks' => $displayedStackOfVotes, + 'comments' => $displayedComments, + ]; + + if ( $this->getKind() == 'text' ) { + $resp[ 'choices' ] = $computedAnswers[ 'answers' ]; + } elseif ( $this->getKind() == 'date' ) { + $resp[ 'choices_grouped' ] = $computedAnswers[ 'grouped_dates' ]; } - public function setCreatedAt( DateTimeInterface $createdAt ): self { - $this->createdAt = $createdAt; + return $resp; + } - return $this; - } + public function computeAnswers() { + $computedArray = []; + $grouped_dates = []; + $maxScore = 0; - public function displayForAdmin() { - $content = $this->display(); - $content[ 'owner' ] = $this->getOwner()->displayForAdmin(); - $content[ 'admin_key' ] = $this->getAdminKey(); - $content[ 'password_hash' ] = $this->getPassword(); - $content[ 'id' ] = $this->getId(); - - return $content; - } - - // counts each number of answer for this choice - - public function display() { - - $computedAnswers = $this->computeAnswers(); - $displayedStackOfVotes = []; - foreach ( $this->getStacksOfVotes() as $stack ) { - $displayedStackOfVotes[] = $stack->display(); - } - $displayedChoices = []; + if ( $this->getKind() == 'date' ) { foreach ( $this->getChoices() as $choice ) { - $displayedChoices[] = $choice->display($this->getKind()); + $boom = explode( ' >>> ', $choice->getName() ); + + + if ( ! isset( $grouped_dates[ $boom[ 0 ] ] ) ) { + + $grouped_dates[ $boom[ 0 ] ] = [ + + "date_string" => $boom[ 0 ], + "time_slices" => [], + ]; + } + $grouped_dates[ $boom[ 0 ] ][ "time_slices" ][] = [ + "choice_id" => $choice->getId(), + "name" => $boom[ 1 ] ]; } - $displayedComments = []; - foreach ( $this->getComments() as $comment ) { - $displayedComments[] = $comment->display(); - } - - - $resp = [ - 'title' => $this->getTitle(), - 'description' => $this->getDescription(), - 'created_at' => $this->getCreatedAt()->format( 'c' ), - 'expiracy_date' => $this->getExpiracyDate()->format( 'c' ), - 'votes_max' => $this->getVotesMax(), - 'custom_url' => $this->getCustomUrl(), - 'choices_max' => $this->getChoicesMax(), - 'kind' => $this->getKind(), - 'allowed_answers' => $this->getAllowedAnswers(), - 'votes_allowed' => $this->getVotesAllowed(), - 'modification_policy' => $this->getModificationPolicy(), - 'hide_results' => $this->getHideResults(), - 'show_results_even_if_password' => $this->getShowResultEvenIfPasswords(), - 'owner' => [ - 'pseudo' => $this->getOwner()->getPseudo(), - ] - , - 'password_protected' => $this->getPassword() ? 'yes' : 'no', - 'max_score' => $computedAnswers[ 'max_score' ], - 'choices' => $computedAnswers[ 'answers' ], - 'stacks' => $displayedStackOfVotes, - 'comments' => $displayedComments, - ]; - - - return $resp; } + $scoreInfos = [ + 'score' => 0, + 'yes' => [ + 'count' => 0, + 'people' => [], + ], + 'maybe' => [ + 'count' => 0, + 'people' => [], + ], + 'no' => [ + 'count' => 0, + 'people' => [], + ], + ]; - public function computeAnswers() { - $computedArray = []; - $maxScore = 0; + // first, prefill all choices + foreach ( $this->getChoices() as $choice ) { + $computedArray[ $choice->getId() ] = array_merge( $scoreInfos, $choice->display( $this->getKind() ) ); + } + // then, compute stack of votes scores on each choice + foreach ( $this->getStacksOfVotes() as $stack_of_vote ) { + foreach ( $stack_of_vote->getVotes() as $vote ) { + $answer = $vote->getValue(); + $choice_id = $vote->getChoice()->getId(); + $choice_url = $vote->getChoice()->getUrl(); - $scoreInfos = [ - 'score' => 0, - 'yes' => [ + if ( ! isset( $computedArray[ $choice_id ] ) ) { + $computedArray[ $choice_id ] = [ + 'id' => $choice_id, + 'url' => $choice_url, + 'name' => $vote->getChoice()->getName(), + 'score' => 0, + 'yes' => [ 'count' => 0, 'people' => [], - ], - 'maybe' => [ + ], + 'maybe' => [ 'count' => 0, 'people' => [], - ], - 'no' => [ + ], + 'no' => [ 'count' => 0, 'people' => [], - ], - ]; + ], - // first, prefill all choices - foreach ( $this->getChoices() as $choice ) { - $computedArray[ $choice->getId() ] = array_merge( $scoreInfos, $choice->display( $this->getKind() ) ); - } - // then, compute stack of votes scores on each choice - foreach ( $this->getStacksOfVotes() as $stack_of_vote ) { - foreach ( $stack_of_vote->getVotes() as $vote ) { - $answer = $vote->getValue(); - $choice_id = $vote->getChoice()->getId(); - $choice_url = $vote->getChoice()->getUrl(); + ]; + } + $computedArray[ $choice_id ][ $answer ][ 'count' ] ++; + $computedArray[ $choice_id ][ $answer ][ 'people' ][] = $stack_of_vote->getOwner()->getPseudo(); - if ( ! isset( $computedArray[ $choice_id ] ) ) { - $computedArray[ $choice_id ] = [ - 'id' => $choice_id, - 'url' => $choice_url, - 'name' => $vote->getChoice()->getName(), - 'score' => 0, - 'yes' => [ - 'count' => 0, - 'people' => [], - ], - 'maybe' => [ - 'count' => 0, - 'people' => [], - ], - 'no' => [ - 'count' => 0, - 'people' => [], - ], - - ]; - } - $computedArray[ $choice_id ][ $answer ][ 'count' ] ++; - $computedArray[ $choice_id ][ $answer ][ 'people' ][] = $stack_of_vote->getOwner()->getPseudo(); - - if ( $answer == 'yes' ) { - $computedArray[ $choice_id ][ 'score' ] += 1; - } elseif ( $answer == 'maybe' ) { - $computedArray[ $choice_id ][ 'score' ] += 0.5; - } - // compare with max value - if ( $computedArray[ $choice_id ][ 'score' ] > $maxScore ) { - $maxScore = $computedArray[ $choice_id ][ 'score' ]; - } + if ( $answer == 'yes' ) { + $computedArray[ $choice_id ][ 'score' ] += 1; + } elseif ( $answer == 'maybe' ) { + $computedArray[ $choice_id ][ 'score' ] += 0.5; + } + // compare with max value + if ( $computedArray[ $choice_id ][ 'score' ] > $maxScore ) { + $maxScore = $computedArray[ $choice_id ][ 'score' ]; } } - $answersWithStats = []; - foreach ( $computedArray as $choice_stat ) { - $answersWithStats[] = $choice_stat; + } + $answersWithStats = []; + foreach ( $computedArray as $choice_stat ) { + $answersWithStats[] = $choice_stat; + } + $groupsOfDates = []; + foreach ( $grouped_dates as $group ) { + $ii =0; + foreach ( $group["time_slices"] as $slice ) { + $slice['score'] = $computedArray[ $slice['choice_id'] ]['score']; + $slice['yes'] = $computedArray[ $slice['choice_id'] ]['yes']; + $slice['maybe'] = $computedArray[ $slice['choice_id'] ]['maybe']; + $slice['no'] = $computedArray[ $slice['choice_id'] ]['no']; + $group["time_slices"][$ii] = $slice; + $ii++; } - return [ - 'answers' => $answersWithStats, - 'max_score' => $maxScore, - ]; + $groupsOfDates[] = $group ; } - /** - * @return Collection|Choice[] - */ - public function getChoices(): Collection { - return $this->choices; - } + return [ + 'answers' => $answersWithStats, + 'grouped_dates' => $groupsOfDates, + 'max_score' => $maxScore, + ]; + } - public function getKind(): ?string { - return $this->kind; - } + /** + * @return Collection|Choice[] + */ + public function getChoices(): Collection { + return $this->choices; + } - public function setKind( string $kind ): self { - $this->kind = $kind; + public function getKind(): ?string { + return $this->kind; + } - return $this; - } + public function setKind( string $kind ): self { + $this->kind = $kind; - public function getStacksOfVotes() { - return $this->stacksOfVotes; - } + return $this; + } - public function setStacksOfVotes( ?StackOfVotes $stacksOfVotes ): self { - $this->stacksOfVotes = $stacksOfVotes; + public function getStacksOfVotes() { + return $this->stacksOfVotes; + } - return $this; - } + public function setStacksOfVotes( ?StackOfVotes $stacksOfVotes ): self { + $this->stacksOfVotes = $stacksOfVotes; - /** - * @return Collection|Comment[] - */ - public function getComments(): Collection { - return $this->comments; - } + return $this; + } - public function getTitle(): ?string { - return $this->title; - } + /** + * @return Collection|Comment[] + */ + public function getComments(): Collection { + return $this->comments; + } - public function setTitle( string $title ): self { - $this->title = $title; + public function getTitle(): ?string { + return $this->title; + } - return $this; - } + public function setTitle( string $title ): self { + $this->title = $title; - public function getDescription(): ?string { - return $this->description; - } + return $this; + } - public function setDescription( string $description ): self { - $this->description = $description; + public function getDescription(): ?string { + return $this->description; + } - return $this; - } + public function setDescription( string $description ): self { + $this->description = $description; - public function getCreatedAt(): ?DateTimeInterface { - return $this->createdAt; - } + return $this; + } - public function getExpiracyDate(): ?DateTimeInterface { - return $this->expiracyDate; - } + public function getCreatedAt(): ?DateTimeInterface { + return $this->createdAt; + } - public function setExpiracyDate( DateTimeInterface $expiracyDate ): self { - $this->expiracyDate = $expiracyDate; + public function getExpiracyDate(): ?DateTimeInterface { + return $this->expiracyDate; + } - return $this; - } + public function setExpiracyDate( DateTimeInterface $expiracyDate ): self { + $this->expiracyDate = $expiracyDate; - public function getVotesMax() { - return $this->votesMax; - } + return $this; + } - public function setVotesMax( $votesMax ): self { - $this->votesMax = $votesMax; + public function getVotesMax() { + return $this->votesMax; + } - return $this; - } + public function setVotesMax( $votesMax ): self { + $this->votesMax = $votesMax; - public function getChoicesMax() { - return $this->choicesMax; - } + return $this; + } - public function setChoicesMax( $choicesMax ): self { - $this->choicesMax = $choicesMax; + public function getChoicesMax() { + return $this->choicesMax; + } - return $this; - } + public function setChoicesMax( $choicesMax ): self { + $this->choicesMax = $choicesMax; - public function getAllowedAnswers(): ?array { - return $this->allowedAnswers; - } + return $this; + } - public function setAllowedAnswers( array $allowedAnswers ): self { - $this->allowedAnswers = $allowedAnswers; + public function getAllowedAnswers(): ?array { + return $this->allowedAnswers; + } - return $this; - } + public function setAllowedAnswers( array $allowedAnswers ): self { + $this->allowedAnswers = $allowedAnswers; - public function getVotesAllowed(): ?bool { - return $this->votesAllowed; - } + return $this; + } - public function setVotesAllowed( ?bool $votesAllowed ): self { - $this->votesAllowed = $votesAllowed; + public function getVotesAllowed(): ?bool { + return $this->votesAllowed; + } - return $this; - } + public function setVotesAllowed( ?bool $votesAllowed ): self { + $this->votesAllowed = $votesAllowed; - public function getModificationPolicy(): ?string { - return $this->modificationPolicy; - } + return $this; + } - public function setModificationPolicy( string $modificationPolicy ): self { - $this->modificationPolicy = $modificationPolicy; + public function getModificationPolicy(): ?string { + return $this->modificationPolicy; + } - return $this; - } + public function setModificationPolicy( string $modificationPolicy ): self { + $this->modificationPolicy = $modificationPolicy; - public function getHideResults(): ?bool { - return $this->hideResults; - } + return $this; + } - public function setHideResults( bool $hideResults ): self { - $this->hideResults = $hideResults; + public function getHideResults(): ?bool { + return $this->hideResults; + } - return $this; - } + public function setHideResults( bool $hideResults ): self { + $this->hideResults = $hideResults; - public function getShowResultEvenIfPasswords(): ?bool { - return $this->showResultEvenIfPasswords; - } + return $this; + } - public function setShowResultEvenIfPasswords( bool $showResultEvenIfPasswords ): self { - $this->showResultEvenIfPasswords = $showResultEvenIfPasswords; + public function getShowResultEvenIfPasswords(): ?bool { + return $this->showResultEvenIfPasswords; + } - return $this; - } + public function setShowResultEvenIfPasswords( bool $showResultEvenIfPasswords ): self { + $this->showResultEvenIfPasswords = $showResultEvenIfPasswords; - public function getOwner(): ?Owner { - return $this->owner; - } + return $this; + } - public function setOwner( ?Owner $owner ): self { - $this->owner = $owner; + public function getOwner(): ?Owner { + return $this->owner; + } - return $this; - } + public function setOwner( ?Owner $owner ): self { + $this->owner = $owner; - public function getPassword(): ?string { - return $this->password; - } + return $this; + } - public function setPassword( string $password ): self { - $this->password = md5( $password ); + public function getPassword(): ?string { + return $this->password; + } - return $this; - } + public function setPassword( string $password ): self { + $this->password = md5( $password ); - public function getAdminKey(): ?string { - return $this->adminKey; - } + return $this; + } - public function setAdminKey( string $adminKey ): self { - $this->adminKey = $adminKey; + public function getAdminKey(): ?string { + return $this->adminKey; + } - return $this; - } + public function setAdminKey( string $adminKey ): self { + $this->adminKey = $adminKey; - public function getId(): ?int { - return $this->id; - } + return $this; + } - public function findChoiceById( int $id ) { + public function getId(): ?int { + return $this->id; + } - $choices = $this->getChoices(); - $counter = 0; - // there must be something cleaner than this in Doctrine ArrayCollection - foreach ( $choices as $choice ) { - $counter ++; - if ( $counter > $this->maxChoicesLimit ) { - throw new ErrorException( "max number of choices reached for this poll" ); - } - if ( $choice && $choice->getId() == $id ) { - return $choice; - } + public function findChoiceById( int $id ) { + $choices = $this->getChoices(); + $counter = 0; + // there must be something cleaner than this in Doctrine ArrayCollection + foreach ( $choices as $choice ) { + $counter ++; + if ( $counter > $this->maxChoicesLimit ) { + throw new ErrorException( "max number of choices reached for this poll" ); + } + if ( $choice && $choice->getId() == $id ) { + return $choice; } - return null; } - /** - * @return Collection|Vote[] - */ - public function getVotes(): Collection { - return $this->votes; + return null; + } + + /** + * @return Collection|Vote[] + */ + public function getVotes(): Collection { + return $this->votes; + } + + public function getCustomUrl(): ?string { + return $this->customUrl; + } + + public function setCustomUrl( string $customUrl ): self { + $this->customUrl = $customUrl; + + 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 addComment( Comment $comment ): self { + if ( ! $this->comments->contains( $comment ) ) { + $this->comments[] = $comment; + $comment->setPoll( $this ); } - public function getCustomUrl(): ?string { - return $this->customUrl; - } + return $this; + } - public function setCustomUrl( string $customUrl ): self { - $this->customUrl = $customUrl; - - 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 addComment( Comment $comment ): self { - if ( ! $this->comments->contains( $comment ) ) { - $this->comments[] = $comment; - $comment->setPoll( $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 ); } - - 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 ); - } + return $this; + } + + public function addStackOfVote( StackOfVotes $stackOfVote ): self { + if ( ! $this->stacksOfVotes->contains( $stackOfVote ) ) { + $this->stacksOfVotes[] = $stackOfVote; + $stackOfVote->setPoll( $this ); + } + + return $this; + } + + public function removeStackOfVote( StackOfVotes $stackOfVote ): self { + if ( $this->stacksOfVotes->contains( $stackOfVote ) ) { + $this->stacksOfVotes->removeElement( $stackOfVote ); + // set the owning side to null (unless already changed) + if ( $stackOfVote->getPoll() === $this ) { + $stackOfVote->setPoll( null ); } - - return $this; } - public function addStackOfVote( StackOfVotes $stackOfVote ): self { - if ( ! $this->stacksOfVotes->contains( $stackOfVote ) ) { - $this->stacksOfVotes[] = $stackOfVote; - $stackOfVote->setPoll( $this ); + return $this; + } + + public function addVote( Vote $vote ): self { + 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; } - public function removeStackOfVote( StackOfVotes $stackOfVote ): self { - if ( $this->stacksOfVotes->contains( $stackOfVote ) ) { - $this->stacksOfVotes->removeElement( $stackOfVote ); - // set the owning side to null (unless already changed) - if ( $stackOfVote->getPoll() === $this ) { - $stackOfVote->setPoll( null ); - } - } + return $this; + } - return $this; + public function addTextChoiceArray( array $choiceTextArray ): self { + foreach ( $choiceTextArray as $text ) { + $newChoice = new Choice(); + $newChoice->setName( $text ); + $this->addChoice( $newChoice ); } - public function addVote( Vote $vote ): self { - if ( ! $this->votes->contains( $vote ) ) { - $this->votes[] = $vote; - $vote->setPoll( $this ); - } + 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 addTextChoiceArray( array $choiceTextArray ): self { - foreach ( $choiceTextArray as $text ) { - $newChoice = new Choice(); - $newChoice->setName( $text ); - $this->addChoice( $newChoice ); - } - - return $this; - } - - public function addChoice( Choice $choice ): self { - if ( ! is_null( $this->choices ) ) { - if ( ! $this->choices->contains( $choice ) ) { - $this->choices[] = $choice; - $choice->setPoll( $this ); - } - } else { + public function addChoice( Choice $choice ): self { + if ( ! is_null( $this->choices ) ) { + if ( ! $this->choices->contains( $choice ) ) { $this->choices[] = $choice; $choice->setPoll( $this ); } - - - return $this; + } else { + $this->choices[] = $choice; + $choice->setPoll( $this ); } - public function addStacksOfVote( StackOfVotes $stacksOfVote ): self { - if ( ! $this->stacksOfVotes->contains( $stacksOfVote ) ) { - $this->stacksOfVotes[] = $stacksOfVote; - $stacksOfVote->setPoll( $this ); - } - return $this; - } - - public function removeStacksOfVote( StackOfVotes $stacksOfVote ): self { - if ( $this->stacksOfVotes->contains( $stacksOfVote ) ) { - $this->stacksOfVotes->removeElement( $stacksOfVote ); - // set the owning side to null (unless already changed) - if ( $stacksOfVote->getPoll() === $this ) { - $stacksOfVote->setPoll( null ); - } - } - - 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; - } - - public function getCommentsAllowed(): ?bool { - return $this->commentsAllowed; - } - - public function setCommentsAllowed( ?bool $commentsAllowed ): self { - $this->commentsAllowed = $commentsAllowed; - - return $this; - } + return $this; } + + public function addStacksOfVote( StackOfVotes $stacksOfVote ): self { + if ( ! $this->stacksOfVotes->contains( $stacksOfVote ) ) { + $this->stacksOfVotes[] = $stacksOfVote; + $stacksOfVote->setPoll( $this ); + } + + return $this; + } + + public function removeStacksOfVote( StackOfVotes $stacksOfVote ): self { + if ( $this->stacksOfVotes->contains( $stacksOfVote ) ) { + $this->stacksOfVotes->removeElement( $stacksOfVote ); + // set the owning side to null (unless already changed) + if ( $stacksOfVote->getPoll() === $this ) { + $stacksOfVote->setPoll( null ); + } + } + + 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; + } + + public function getCommentsAllowed(): ?bool { + return $this->commentsAllowed; + } + + public function setCommentsAllowed( ?bool $commentsAllowed ): self { + $this->commentsAllowed = $commentsAllowed; + + return $this; + } +}