mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
⚡ enrich computed data
This commit is contained in:
parent
58c28474f8
commit
510e5303be
@ -87,7 +87,6 @@
|
|||||||
->setTo( $founduser->getEmail() )
|
->setTo( $founduser->getEmail() )
|
||||||
->setBody(
|
->setBody(
|
||||||
$this->renderView(
|
$this->renderView(
|
||||||
// templates/hello/email.txt.twig
|
|
||||||
'emails/owner-list.html.twig',
|
'emails/owner-list.html.twig',
|
||||||
$templateVars
|
$templateVars
|
||||||
)
|
)
|
||||||
@ -95,11 +94,7 @@
|
|||||||
$mailer->send( $message );
|
$mailer->send( $message );
|
||||||
|
|
||||||
return $this->render( 'emails/owner-list.html.twig', $templateVars );
|
return $this->render( 'emails/owner-list.html.twig', $templateVars );
|
||||||
// return $this->json( [
|
|
||||||
// 'message' => 'here are your polls, ' . $email,
|
|
||||||
// 'data' => 'email was sent with a list of ' . count( $polls ) . ' polls',
|
|
||||||
// ],
|
|
||||||
// 200 );
|
|
||||||
} else {
|
} else {
|
||||||
return $this->json( [
|
return $this->json( [
|
||||||
'message' => 'no user found for email ' . $email,
|
'message' => 'no user found for email ' . $email,
|
||||||
@ -535,11 +530,27 @@
|
|||||||
if ( $existingOwner ) {
|
if ( $existingOwner ) {
|
||||||
$precision = ' from an existing owner : ' . $foundOwner->getEmail();
|
$precision = ' from an existing owner : ' . $foundOwner->getEmail();
|
||||||
}
|
}
|
||||||
|
$comments = [];
|
||||||
|
$stacks = [];
|
||||||
|
$choices = [];
|
||||||
|
foreach ( $poll->getComments() as $c ) {
|
||||||
|
$comments[] = $c->display();
|
||||||
|
}
|
||||||
|
foreach ( $poll->getStacksOfVotes() as $c ) {
|
||||||
|
$stacks[] = $c->display();
|
||||||
|
}
|
||||||
|
foreach ( $poll->getChoices() as $c ) {
|
||||||
|
$choices[] = $c->display();
|
||||||
|
}
|
||||||
|
|
||||||
return $this->json( [
|
return $this->json( [
|
||||||
'message' => 'you created a vote stack' . $precision,
|
'message' => 'you created a vote stack' . $precision,
|
||||||
'poll' => $poll,
|
'poll' => $poll,
|
||||||
'vote_stack' => $stack->display(),
|
'vote_stack' => $stack->display(),
|
||||||
|
'stacks' => $stacks,
|
||||||
|
'comments' => $comments,
|
||||||
|
'choices' => $choices,
|
||||||
|
'choices_count' => $poll->computeAnswers(),
|
||||||
'vote_count' => count( $poll->getStacksOfVotes() ),
|
'vote_count' => count( $poll->getStacksOfVotes() ),
|
||||||
'owner_modifier_token' => $foundOwner->getModifierToken(),
|
'owner_modifier_token' => $foundOwner->getModifierToken(),
|
||||||
'admin_key' => $poll->getAdminKey(),
|
'admin_key' => $poll->getAdminKey(),
|
||||||
|
@ -155,34 +155,51 @@
|
|||||||
public function computeAnswers() {
|
public function computeAnswers() {
|
||||||
// counts each number of answer for this choice
|
// counts each number of answer for this choice
|
||||||
$computedArray = [];
|
$computedArray = [];
|
||||||
$people = [];
|
$maxScore = 0;
|
||||||
|
|
||||||
foreach ( $this->getStacksOfVotes() as $stack_of_vote ) {
|
foreach ( $this->getStacksOfVotes() as $stack_of_vote ) {
|
||||||
foreach ( $stack_of_vote->getVotes() as $vote ) {
|
foreach ( $stack_of_vote->getVotes() as $vote ) {
|
||||||
if ( ! isset( $computedArray[ $vote->getChoice()->getId() ] ) ) {
|
$answer = $vote->getValue();
|
||||||
$computedArray[ $vote->getChoice()->getId() ] = [
|
$choice_id = $vote->getChoice()->getId();
|
||||||
'yes' => [
|
|
||||||
|
if ( ! isset( $computedArray[ $choice_id ] ) ) {
|
||||||
|
$computedArray[ $choice_id ] = [
|
||||||
|
'choice_id' => $choice_id,
|
||||||
|
'choice_text' => $vote->getChoice()->getName(),
|
||||||
|
'id' => $vote->getId(),
|
||||||
|
'score' => 0,
|
||||||
|
'yes' => [
|
||||||
'count' => 0,
|
'count' => 0,
|
||||||
'people' => [],
|
'people' => [],
|
||||||
],
|
],
|
||||||
'maybe' => [
|
'maybe' => [
|
||||||
'count' => 0,
|
'count' => 0,
|
||||||
'people' => [],
|
'people' => [],
|
||||||
],
|
],
|
||||||
'no' => [
|
'no' => [
|
||||||
'count' => 0,
|
'count' => 0,
|
||||||
'people' => [],
|
'people' => [],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$computedArray[ $vote->getChoice()->getId() ][ $vote->getValue() ][ 'count' ] ++;
|
$computedArray[ $choice_id ][ $answer ][ 'count' ] ++;
|
||||||
$computedArray[ $vote->getChoice()->getId() ][ $vote->getValue() ][ 'people' ][] = $stack_of_vote->getOwner()->getPseudo();
|
$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' ];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'counts' => $computedArray,
|
'counts' => $computedArray,
|
||||||
|
'maxScore' => $maxScore,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user