mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
save kind of poll
This commit is contained in:
parent
e86606b543
commit
cc74a08603
@ -216,6 +216,7 @@ class PollController extends EmailsController {
|
|||||||
$newpoll
|
$newpoll
|
||||||
->setModificationPolicy( $data[ 'modification_policy' ] )
|
->setModificationPolicy( $data[ 'modification_policy' ] )
|
||||||
->setTitle( $data[ 'title' ] )
|
->setTitle( $data[ 'title' ] )
|
||||||
|
->setKind( $data[ 'kind' ] )
|
||||||
->setCustomUrl( $data[ 'custom_url' ] );
|
->setCustomUrl( $data[ 'custom_url' ] );
|
||||||
if ( count( $data[ 'allowed_answers' ] ) ) {
|
if ( count( $data[ 'allowed_answers' ] ) ) {
|
||||||
$newpoll->setAllowedAnswers( $data[ 'allowed_answers' ] );
|
$newpoll->setAllowedAnswers( $data[ 'allowed_answers' ] );
|
||||||
@ -257,7 +258,7 @@ class PollController extends EmailsController {
|
|||||||
$newpoll->setDescription( $data['description'] );
|
$newpoll->setDescription( $data['description'] );
|
||||||
$newpoll->setHideResults( false );
|
$newpoll->setHideResults( false );
|
||||||
// possible answers
|
// possible answers
|
||||||
$newpoll->setAllowedAnswers( [ 'yes' ] );
|
$newpoll->setAllowedAnswers( $data[ 'allowed_answers' ] );
|
||||||
$newpoll->setVotesMax( $data[ 'maxCountOfAnswers' ] );
|
$newpoll->setVotesMax( $data[ 'maxCountOfAnswers' ] );
|
||||||
$newpoll->setCommentsAllowed( $data['allowComments'] );
|
$newpoll->setCommentsAllowed( $data['allowComments'] );
|
||||||
|
|
||||||
|
@ -295,21 +295,22 @@ class Poll {
|
|||||||
foreach ( $this->getChoices() as $choice ) {
|
foreach ( $this->getChoices() as $choice ) {
|
||||||
$boom = explode( ' >>> ', $choice->getName() );
|
$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 ],
|
"date_string" => $boom[ 0 ],
|
||||||
"choices" => [],
|
"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 = [
|
$scoreInfos = [
|
||||||
@ -380,18 +381,18 @@ class Poll {
|
|||||||
}
|
}
|
||||||
$groupsOfDates = [];
|
$groupsOfDates = [];
|
||||||
foreach ( $grouped_dates as $group ) {
|
foreach ( $grouped_dates as $group ) {
|
||||||
$ii =0;
|
$ii = 0;
|
||||||
foreach ( $group["choices"] as $slice ) {
|
foreach ( $group[ "choices" ] as $slice ) {
|
||||||
$slice['score'] = $computedArray[ $slice['choice_id'] ]['score'];
|
$slice[ 'score' ] = $computedArray[ $slice[ 'choice_id' ] ][ 'score' ];
|
||||||
$slice['yes'] = $computedArray[ $slice['choice_id'] ]['yes'];
|
$slice[ 'yes' ] = $computedArray[ $slice[ 'choice_id' ] ][ 'yes' ];
|
||||||
$slice['maybe'] = $computedArray[ $slice['choice_id'] ]['maybe'];
|
$slice[ 'maybe' ] = $computedArray[ $slice[ 'choice_id' ] ][ 'maybe' ];
|
||||||
$slice['no'] = $computedArray[ $slice['choice_id'] ]['no'];
|
$slice[ 'no' ] = $computedArray[ $slice[ 'choice_id' ] ][ 'no' ];
|
||||||
$slice['id'] = $slice['choice_id'];
|
$slice[ 'id' ] = $slice[ 'choice_id' ];
|
||||||
$group["choices"][$ii] = $slice;
|
$group[ "choices" ][ $ii ] = $slice;
|
||||||
$ii++;
|
$ii ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$groupsOfDates[] = $group ;
|
$groupsOfDates[] = $group;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@ -494,7 +495,11 @@ class Poll {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function setAllowedAnswers( array $allowedAnswers ): self {
|
public function setAllowedAnswers( array $allowedAnswers ): self {
|
||||||
$this->allowedAnswers = $allowedAnswers;
|
if ( ! count( $allowedAnswers ) ) {
|
||||||
|
$this->allowedAnswers = [ 'yes' ];
|
||||||
|
} else {
|
||||||
|
$this->allowedAnswers = $allowedAnswers;
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user