diff --git a/.env b/.env index 80cadd5..8c2d4b0 100755 --- a/.env +++ b/.env @@ -44,3 +44,7 @@ SUPPORT_EMAIL=YOUR_EMAIL ###> nelmio/cors-bundle ### CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$' ###< nelmio/cors-bundle ### + +###> symfony/mailer ### +# MAILER_DSN=smtp://localhost +###< symfony/mailer ### diff --git a/composer.json b/composer.json index f1f6cb6..ae4b7b8 100644 --- a/composer.json +++ b/composer.json @@ -39,6 +39,7 @@ "php": ">=7.2.5", "ext-ctype": "*", "ext-iconv": "*", + "ext-json": "*", "composer/package-versions-deprecated": "1.11.99.1", "doctrine/annotations": "^1.12", "doctrine/doctrine-bundle": "^2.3", @@ -54,11 +55,11 @@ "symfony/flex": "^1.3.1", "symfony/form": "5.2.*", "symfony/framework-bundle": "5.2.*", + "symfony/mailer": "5.2.*", "symfony/proxy-manager-bridge": "5.2.*", "symfony/swiftmailer-bundle": "^3.5", "symfony/twig-bundle": "5.2.*", - "symfony/yaml": "5.2.*", - "ext-json": "*" + "symfony/yaml": "5.2.*" }, "require-dev": { "doctrine/doctrine-fixtures-bundle": "^3.4", diff --git a/composer.lock b/composer.lock index 182cbd9..12df905 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "76574cee43242167355502c759b6260c", + "content-hash": "9a37fb1f1119669bc5d2ebb272491699", "packages": [ { "name": "composer/package-versions-deprecated", @@ -4246,6 +4246,170 @@ ], "time": "2021-02-18T22:42:36+00:00" }, + { + "name": "symfony/mailer", + "version": "v5.2.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/mailer.git", + "reference": "c50b304246e56c8574c203bce440f0eafb107ae9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/mailer/zipball/c50b304246e56c8574c203bce440f0eafb107ae9", + "reference": "c50b304246e56c8574c203bce440f0eafb107ae9", + "shasum": "" + }, + "require": { + "egulias/email-validator": "^2.1.10|^3", + "php": ">=7.2.5", + "psr/log": "~1.0", + "symfony/event-dispatcher": "^4.4|^5.0", + "symfony/mime": "^5.2.6", + "symfony/polyfill-php80": "^1.15", + "symfony/service-contracts": "^1.1|^2" + }, + "conflict": { + "symfony/http-kernel": "<4.4" + }, + "require-dev": { + "symfony/amazon-mailer": "^4.4|^5.0", + "symfony/google-mailer": "^4.4|^5.0", + "symfony/http-client-contracts": "^1.1|^2", + "symfony/mailchimp-mailer": "^4.4|^5.0", + "symfony/mailgun-mailer": "^4.4|^5.0", + "symfony/mailjet-mailer": "^4.4|^5.0", + "symfony/messenger": "^4.4|^5.0", + "symfony/postmark-mailer": "^4.4|^5.0", + "symfony/sendgrid-mailer": "^4.4|^5.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Mailer\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Helps sending emails", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/mailer/tree/v5.2.7" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-04-23T11:25:09+00:00" + }, + { + "name": "symfony/mime", + "version": "v5.2.9", + "source": { + "type": "git", + "url": "https://github.com/symfony/mime.git", + "reference": "64258e870f8cc75c3dae986201ea2df58c210b52" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/mime/zipball/64258e870f8cc75c3dae986201ea2df58c210b52", + "reference": "64258e870f8cc75c3dae986201ea2df58c210b52", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1", + "symfony/polyfill-intl-idn": "^1.10", + "symfony/polyfill-mbstring": "^1.0", + "symfony/polyfill-php80": "^1.15" + }, + "conflict": { + "egulias/email-validator": "~3.0.0", + "phpdocumentor/reflection-docblock": "<3.2.2", + "phpdocumentor/type-resolver": "<1.4.0", + "symfony/mailer": "<4.4" + }, + "require-dev": { + "egulias/email-validator": "^2.1.10|^3.1", + "phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0", + "symfony/dependency-injection": "^4.4|^5.0", + "symfony/property-access": "^4.4|^5.1", + "symfony/property-info": "^4.4|^5.1", + "symfony/serializer": "^5.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Mime\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Allows manipulating MIME messages", + "homepage": "https://symfony.com", + "keywords": [ + "mime", + "mime-type" + ], + "support": { + "source": "https://github.com/symfony/mime/tree/v5.2.9" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-05-16T13:07:46+00:00" + }, { "name": "symfony/options-resolver", "version": "v5.2.4", @@ -6683,7 +6847,8 @@ "platform": { "php": ">=7.2.5", "ext-ctype": "*", - "ext-iconv": "*" + "ext-iconv": "*", + "ext-json": "*" }, "platform-dev": [], "plugin-api-version": "2.0.0" diff --git a/config/packages/mailer.yaml b/config/packages/mailer.yaml new file mode 100644 index 0000000..56a650d --- /dev/null +++ b/config/packages/mailer.yaml @@ -0,0 +1,3 @@ +framework: + mailer: + dsn: '%env(MAILER_DSN)%' diff --git a/src/Controller/api/v1/PollController.php b/src/Controller/api/v1/PollController.php index d14cb27..21b21f3 100644 --- a/src/Controller/api/v1/PollController.php +++ b/src/Controller/api/v1/PollController.php @@ -255,6 +255,7 @@ class PollController extends EmailsController { ->setKind( $data[ 'kind' ] ) ->setCustomUrl( $data[ 'custom_url' ] ); if ( count( $data[ 'allowed_answers' ] ) ) { + // TODO check this one $newpoll->setAllowedAnswers( $data[ 'allowed_answers' ] ); } $expiracyCalculated = $newpoll->addDaysToDate( new DateTime(), @@ -287,10 +288,11 @@ class PollController extends EmailsController { // emails $newpoll->setMailOnComment( true ); - if ( isset( $data[ 'isOwnerNotifiedByEmailOnNewVote' ] ) ) { + $newpoll->setMailOnVote( $data[ 'isOwnerNotifiedByEmailOnNewVote' ] ); + $newpoll->setMailOnComment( $data[ 'isOwnerNotifiedByEmailOnNewComment' ] ); - $newpoll->setMailOnVote( $data[ 'isOwnerNotifiedByEmailOnNewVote' ] ); - } + + $newpoll->setIsZeroKnowledge( $data[ 'is_zero_knowledge' ] ); $newpoll->setDescription( $data[ 'description' ] ); $newpoll->setHideResults( false ); // possible answers diff --git a/src/Controller/api/v1/VoteController.php b/src/Controller/api/v1/VoteController.php index a2a1830..2f02efa 100644 --- a/src/Controller/api/v1/VoteController.php +++ b/src/Controller/api/v1/VoteController.php @@ -66,8 +66,8 @@ class VoteController extends EmailsController { $data = $request->getContent(); $data = json_decode( $data, true ); -// var_dump($data); -// die(); + var_dump($data); + die(); $owner = new Owner(); $owner diff --git a/src/Entity/Poll.php b/src/Entity/Poll.php index 1ac2311..b0131b6 100755 --- a/src/Entity/Poll.php +++ b/src/Entity/Poll.php @@ -92,7 +92,7 @@ class Poll { * @Serializer\Type("boolean") * @Serializer\Expose() */ - public $isZeroKnowledge ; + public $isZeroKnowledge; /** * max number of stack of votes possible. @@ -202,587 +202,623 @@ class Poll { private $maxChoicesLimit = 25; public function __construct() { - - $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(); - } + + $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(); + } 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' ] ); - } + $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 setCreatedAt( DateTimeInterface $createdAt ): self { - $this->createdAt = $createdAt; - - return $this; - } + $this->createdAt = $createdAt; + + 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; - } + $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(); - } - - - $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' ]; - } - - return $resp; - } + + $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(); + } + + + $resp = [ + 'title' => $this->getTitle(), + 'description' => $this->getDescription(), + 'choices_grouped' => $computedAnswers[ 'grouped_dates' ], + '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(), + ] + , + 'choices' => $computedAnswers[ 'answers' ], + 'password_protected' => $this->getPassword() ? 'yes' : 'no', + 'max_score' => $computedAnswers[ 'max_score' ], + 'stacks' => $displayedStackOfVotes, + 'comments' => $displayedComments, + ]; + +// if ( $this->getKind() == 'text' ) { +// $resp[ 'choices' ] = $computedAnswers[ 'grouped_dates' ]; +// $resp[ 'choices_grouped' ] = $computedAnswers[ 'answers' ]; +// } elseif ( $this->getKind() == 'date' ) { +// $resp[ 'choices' ] = $computedAnswers[ 'answers' ]; +// $resp[ 'choices_grouped' ] = $computedAnswers[ 'grouped_dates' ]; +// } + + return $resp; + } public function computeAnswers() { - $computedArray = []; - $grouped_dates = []; - $maxScore = 0; - - if ( $this->getKind() == 'date' ) { - foreach ( $this->getChoices() as $choice ) { - $boom = explode( ' >>> ', $choice->getName() ); - - if ( count( $boom ) == 2 ) { - - - if ( ! isset( $grouped_dates[ $boom[ 0 ] ] ) ) { - - $grouped_dates[ $boom[ 0 ] ] = [ - - "date_string" => $boom[ 0 ], - "choices" => [], - ]; - } - $grouped_dates[ $boom[ 0 ] ][ "choices" ][] = [ - "choice_id" => $choice->getId(), - "name" => $boom[ 1 ], - ]; - } - } - } - $scoreInfos = [ - 'score' => 0, - 'yes' => [ - 'count' => 0, - 'people' => [], - ], - 'maybe' => [ - 'count' => 0, - 'people' => [], - ], - '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(); - - 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' ]; - } - } - } - $answersWithStats = []; - foreach ( $computedArray as $choice_stat ) { - $answersWithStats[] = $choice_stat; - } - $groupsOfDates = []; - foreach ( $grouped_dates as $group ) { - $ii = 0; - foreach ( $group[ "choices" ] 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' ]; - $slice[ 'id' ] = $slice[ 'choice_id' ]; - $group[ "choices" ][ $ii ] = $slice; - $ii ++; - } - - $groupsOfDates[] = $group; - } - - return [ - 'answers' => $answersWithStats, - 'grouped_dates' => $groupsOfDates, - 'max_score' => $maxScore, - ]; - } + $computedArray = []; + $grouped_dates = []; + $maxScore = 0; + + if ( $this->getKind() == 'date' ) { + foreach ( $this->getChoices() as $choice ) { + $boom = explode( ' >>> ', $choice->getName() ); + + // handle sub time slices + if ( count( $boom ) == 2 ) { + + + if ( ! isset( $grouped_dates[ $boom[ 0 ] ] ) ) { + + $grouped_dates[ $boom[ 0 ] ] = [ + + "date_string" => $boom[ 0 ], + "choices" => [], + ]; + } + $grouped_dates[ $boom[ 0 ] ][ "choices" ][] = [ + "choice_id" => $choice->getId(), + "name" => $boom[ 1 ], + ]; + } + elseif(count( $boom ) == 1){ + $name = $choice->getName(); + $grouped_dates[ $name ] = [ + + "date_string" => $name, + "choices" => [], + ]; + $grouped_dates[ $name ][ "choices" ][] = [ + "choice_id" => $choice->getId(), + "name" => $name, + ]; + } + } + } elseif ( $this->getKind() == 'text' ) { + foreach ( $this->getChoices() as $choice ) { + $name = $choice->getName(); + + + if ( ! isset( $grouped_dates[ $name ] ) ) { + + $grouped_dates[ $name ] = [ + + "date_string" => $name, + "choices" => [], + ]; + } + $grouped_dates[ $name ][ "choices" ][] = [ + "choice_id" => $choice->getId(), + "name" => $name, + ]; + } + } + $scoreInfos = [ + + 'id' => null, + 'name' => null, + 'score' => 0, + 'created_at' => null, + 'yes' => [ + 'count' => 0, + 'people' => [], + ], + 'maybe' => [ + 'count' => 0, + 'people' => [], + ], + '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(); + + 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' ]; + } + } + } + $answersWithStats = []; + foreach ( $computedArray as $choice_stat ) { + $answersWithStats[] = $choice_stat; + } + $groupsOfDates = []; + foreach ( $grouped_dates as $group ) { + $ii = 0; + foreach ( $group[ "choices" ] 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' ]; + $slice[ 'id' ] = $slice[ 'choice_id' ]; + $group[ "choices" ][ $ii ] = $slice; + $ii ++; + } + + $groupsOfDates[] = $group; + } + + return [ + 'answers' => $answersWithStats, + 'grouped_dates' => $groupsOfDates, + 'max_score' => $maxScore, + ]; + } /** * @return Collection|Choice[] */ public function getChoices(): Collection { - return $this->choices; - } + return $this->choices; + } 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 getStacksOfVotes() { - return $this->stacksOfVotes; - } + return $this->stacksOfVotes; + } public function setStacksOfVotes( ?StackOfVotes $stacksOfVotes ): self { - $this->stacksOfVotes = $stacksOfVotes; - - return $this; - } + $this->stacksOfVotes = $stacksOfVotes; + + return $this; + } /** * @return Collection|Comment[] */ public function getComments(): Collection { - return $this->comments; - } + return $this->comments; + } 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 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 getCreatedAt(): ?DateTimeInterface { - return $this->createdAt; - } + return $this->createdAt; + } 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 getVotesMax() { - return $this->votesMax; - } + return $this->votesMax; + } public function setVotesMax( $votesMax ): self { - $this->votesMax = $votesMax; - - return $this; - } + $this->votesMax = $votesMax; + + return $this; + } public function getChoicesMax() { - return $this->choicesMax; - } + return $this->choicesMax; + } public function setChoicesMax( $choicesMax ): self { - $this->choicesMax = $choicesMax; - - return $this; - } + $this->choicesMax = $choicesMax; + + return $this; + } public function getAllowedAnswers(): ?array { - return $this->allowedAnswers; - } + return $this->allowedAnswers; + } public function setAllowedAnswers( array $allowedAnswers ): self { - if ( ! count( $allowedAnswers ) ) { - $this->allowedAnswers = [ 'yes' ]; - } else { - $this->allowedAnswers = $allowedAnswers; - } - - return $this; - } + if ( ! count( $allowedAnswers ) ) { + $this->allowedAnswers = [ 'yes' ]; + } else { + $this->allowedAnswers = $allowedAnswers; + } + + return $this; + } public function getVotesAllowed(): ?bool { - return $this->votesAllowed; - } + return $this->votesAllowed; + } public function setVotesAllowed( ?bool $votesAllowed ): self { - $this->votesAllowed = $votesAllowed; - - return $this; - } + $this->votesAllowed = $votesAllowed; + + 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 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; + } 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; + } public function getPassword(): ?string { - return $this->password; - } + return $this->password; + } public function setPassword( string $password ): self { - $this->password = md5( $password ); - - return $this; - } + $this->password = md5( $password ); + + 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 getId(): ?int { - return $this->id; - } + return $this->id; + } 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; - } + + $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 $this->votes; + } 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 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 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 ); - } - } - - return $this; - } + 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; - } + 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; - } + 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 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 addTextChoiceArray( array $choiceTextArray ): self { - foreach ( $choiceTextArray as $text ) { - $newChoice = new Choice(); - $newChoice->setName( $text ); - $this->addChoice( $newChoice ); - } - - return $this; - } + 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 { - $this->choices[] = $choice; - $choice->setPoll( $this ); - } - - - return $this; - } + if ( ! is_null( $this->choices ) ) { + if ( ! $this->choices->contains( $choice ) ) { + $this->choices[] = $choice; + $choice->setPoll( $this ); + } + } else { + $this->choices[] = $choice; + $choice->setPoll( $this ); + } + + + return $this; + } public function addStacksOfVote( StackOfVotes $stacksOfVote ): self { - if ( ! $this->stacksOfVotes->contains( $stacksOfVote ) ) { - $this->stacksOfVotes[] = $stacksOfVote; - $stacksOfVote->setPoll( $this ); - } - - return $this; - } + 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; - } + 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; - } + 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; - } + return $this->commentsAllowed; + } public function setCommentsAllowed( ?bool $commentsAllowed ): self { - $this->commentsAllowed = $commentsAllowed; - - return $this; - } + $this->commentsAllowed = $commentsAllowed; - public function getIsZeroKnowledge(): ?bool - { - return $this->isZeroKnowledge; - } + return $this; + } - public function setIsZeroKnowledge(?bool $isZeroKnowledge): self - { - $this->isZeroKnowledge = $isZeroKnowledge; + public function getIsZeroKnowledge(): ?bool { + return $this->isZeroKnowledge; + } - return $this; - } + public function setIsZeroKnowledge( ?bool $isZeroKnowledge ): self { + $this->isZeroKnowledge = $isZeroKnowledge; + + return $this; + } } diff --git a/symfony.lock b/symfony.lock index 7a584ec..d943bd2 100644 --- a/symfony.lock +++ b/symfony.lock @@ -302,6 +302,18 @@ "symfony/intl": { "version": "v5.2.4" }, + "symfony/mailer": { + "version": "4.3", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "4.3", + "ref": "15658c2a0176cda2e7dba66276a2030b52bd81b2" + }, + "files": [ + "config/packages/mailer.yaml" + ] + }, "symfony/maker-bundle": { "version": "1.0", "recipe": { @@ -311,6 +323,9 @@ "ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f" } }, + "symfony/mime": { + "version": "v5.2.9" + }, "symfony/options-resolver": { "version": "v5.2.4" },