From cc74a08603a5cd331c2ad34867e62dc2b21e4273 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Mon, 3 May 2021 13:42:19 +0200 Subject: [PATCH] save kind of poll --- src/Controller/api/v1/PollController.php | 3 +- src/Entity/Poll.php | 45 +++++++++++++----------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/Controller/api/v1/PollController.php b/src/Controller/api/v1/PollController.php index 2fce894..e1a0e3d 100644 --- a/src/Controller/api/v1/PollController.php +++ b/src/Controller/api/v1/PollController.php @@ -216,6 +216,7 @@ class PollController extends EmailsController { $newpoll ->setModificationPolicy( $data[ 'modification_policy' ] ) ->setTitle( $data[ 'title' ] ) + ->setKind( $data[ 'kind' ] ) ->setCustomUrl( $data[ 'custom_url' ] ); if ( count( $data[ 'allowed_answers' ] ) ) { $newpoll->setAllowedAnswers( $data[ 'allowed_answers' ] ); @@ -257,7 +258,7 @@ class PollController extends EmailsController { $newpoll->setDescription( $data['description'] ); $newpoll->setHideResults( false ); // possible answers - $newpoll->setAllowedAnswers( [ 'yes' ] ); + $newpoll->setAllowedAnswers( $data[ 'allowed_answers' ] ); $newpoll->setVotesMax( $data[ 'maxCountOfAnswers' ] ); $newpoll->setCommentsAllowed( $data['allowComments'] ); diff --git a/src/Entity/Poll.php b/src/Entity/Poll.php index a99ea0f..04deeb0 100755 --- a/src/Entity/Poll.php +++ b/src/Entity/Poll.php @@ -295,21 +295,22 @@ class Poll { foreach ( $this->getChoices() as $choice ) { $boom = explode( ' >>> ', $choice->getName() ); - if(count($boom) ==2){ + if ( count( $boom ) == 2 ) { - if ( ! isset( $grouped_dates[ $boom[ 0 ] ] ) ) { + if ( ! isset( $grouped_dates[ $boom[ 0 ] ] ) ) { - $grouped_dates[ $boom[ 0 ] ] = [ + $grouped_dates[ $boom[ 0 ] ] = [ - "date_string" => $boom[ 0 ], - "choices" => [], + "date_string" => $boom[ 0 ], + "choices" => [], + ]; + } + $grouped_dates[ $boom[ 0 ] ][ "choices" ][] = [ + "choice_id" => $choice->getId(), + "name" => $boom[ 1 ], ]; } - $grouped_dates[ $boom[ 0 ] ][ "choices" ][] = [ - "choice_id" => $choice->getId(), - "name" => $boom[ 1 ] ]; - } } } $scoreInfos = [ @@ -380,18 +381,18 @@ class Poll { } $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++; + $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 ; + $groupsOfDates[] = $group; } return [ @@ -494,7 +495,11 @@ class Poll { } public function setAllowedAnswers( array $allowedAnswers ): self { - $this->allowedAnswers = $allowedAnswers; + if ( ! count( $allowedAnswers ) ) { + $this->allowedAnswers = [ 'yes' ]; + } else { + $this->allowedAnswers = $allowedAnswers; + } return $this; }