mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
remove duplicate data
This commit is contained in:
parent
1d72bfe684
commit
30c99568dd
@ -103,30 +103,10 @@ class PollController extends EmailsController {
|
|||||||
$comments = $poll->getComments();
|
$comments = $poll->getComments();
|
||||||
$stacks = $poll->getStacksOfVotes();
|
$stacks = $poll->getStacksOfVotes();
|
||||||
|
|
||||||
$displayedComments = [];
|
|
||||||
foreach ( $comments as $comment ) {
|
|
||||||
$displayedComments[] = $comment->display();
|
|
||||||
}
|
|
||||||
$displayedStackOfVotes = [];
|
|
||||||
foreach ( $stacks as $stack ) {
|
|
||||||
$displayedStackOfVotes[] = $stack->display();
|
|
||||||
}
|
|
||||||
$displayedChoices = [];
|
|
||||||
foreach ( $poll->getChoices() as $choice
|
|
||||||
) {
|
|
||||||
$displayedChoices[] = $choice->display();
|
|
||||||
}
|
|
||||||
$pass = $poll->getPassword();
|
$pass = $poll->getPassword();
|
||||||
|
|
||||||
$returnedPoll = [
|
|
||||||
'message' => 'your poll config for ' . $poll->getTitle(),
|
|
||||||
|
|
||||||
'poll' => $poll->display(),
|
|
||||||
// TODO do not render sub objects of owner, it returns too many thing
|
|
||||||
'stacks' => $displayedStackOfVotes,
|
|
||||||
'choices' => $displayedChoices,
|
|
||||||
'comments' => $displayedComments,
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* password protected content
|
* password protected content
|
||||||
@ -140,9 +120,7 @@ class PollController extends EmailsController {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// free access to poll
|
// free access to poll
|
||||||
// return $this->returnPollData( $poll, $serializer );
|
return $this->json( $poll->display() );
|
||||||
return $this->json( $returnedPoll );
|
|
||||||
// return $this->json($poll);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -169,7 +147,7 @@ class PollController extends EmailsController {
|
|||||||
|
|
||||||
if ( $poll->getPassword() === $md5 ) {
|
if ( $poll->getPassword() === $md5 ) {
|
||||||
// good matching pass
|
// good matching pass
|
||||||
return $this->returnPollData( $poll, $serializer );
|
return $this->json( $poll->display() );
|
||||||
} else {
|
} else {
|
||||||
// wrong pass
|
// wrong pass
|
||||||
return $this->json( [
|
return $this->json( [
|
||||||
@ -218,10 +196,8 @@ class PollController extends EmailsController {
|
|||||||
$em->persist( $poll );
|
$em->persist( $poll );
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
return $this->json( [
|
return $this->json( $poll->displayForAdmin()
|
||||||
'message' => 'you updated the poll ' . $poll->getTitle(),
|
,
|
||||||
"poll" => $poll,
|
|
||||||
],
|
|
||||||
200 );
|
200 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,7 +279,6 @@ class PollController extends EmailsController {
|
|||||||
$newChoice = new Choice();
|
$newChoice = new Choice();
|
||||||
$newChoice
|
$newChoice
|
||||||
->setPoll( $newpoll )
|
->setPoll( $newpoll )
|
||||||
// ->setUrl( $c[ 'url' ] )
|
|
||||||
->setName( $c[ 'literal' ] );
|
->setName( $c[ 'literal' ] );
|
||||||
$em->persist( $newChoice );
|
$em->persist( $newChoice );
|
||||||
// TODO add also choices for each time range in a day
|
// TODO add also choices for each time range in a day
|
||||||
@ -331,10 +306,8 @@ class PollController extends EmailsController {
|
|||||||
|
|
||||||
return $this->json( [
|
return $this->json( [
|
||||||
'message' => 'you created a poll ' . $precision,
|
'message' => 'you created a poll ' . $precision,
|
||||||
'poll' => $newpoll,
|
'poll' => $newpoll->displayForAdmin,
|
||||||
'password_protected' => is_string( $newpoll->getPassword() ),
|
'password_protected' => is_string( $newpoll->getPassword() ),
|
||||||
'admin_key' => $newpoll->getAdminKey(),
|
|
||||||
'owner_modifier_token' => $foundOwner->getModifierToken(),
|
|
||||||
|
|
||||||
],
|
],
|
||||||
201 );
|
201 );
|
||||||
|
@ -197,12 +197,13 @@ class Poll {
|
|||||||
foreach ( $stack_of_vote->getVotes() as $vote ) {
|
foreach ( $stack_of_vote->getVotes() as $vote ) {
|
||||||
$answer = $vote->getValue();
|
$answer = $vote->getValue();
|
||||||
$choice_id = $vote->getChoice()->getId();
|
$choice_id = $vote->getChoice()->getId();
|
||||||
|
$choice_url = $vote->getChoice()->getUrl();
|
||||||
|
|
||||||
if ( ! isset( $computedArray[ $choice_id ] ) ) {
|
if ( ! isset( $computedArray[ $choice_id ] ) ) {
|
||||||
$computedArray[ $choice_id ] = [
|
$computedArray[ $choice_id ] = [
|
||||||
'choice_id' => $choice_id,
|
'id' => $choice_id,
|
||||||
'choice_text' => $vote->getChoice()->getName(),
|
'url' => $choice_url,
|
||||||
'id' => $vote->getId(),
|
'name' => $vote->getChoice()->getName(),
|
||||||
'score' => 0,
|
'score' => 0,
|
||||||
'yes' => [
|
'yes' => [
|
||||||
'count' => 0,
|
'count' => 0,
|
||||||
@ -233,16 +234,53 @@ class Poll {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
'counts' => $computedArray,
|
'answers' => $computedArray,
|
||||||
'maxScore' => $maxScore,
|
'max_score' => $maxScore,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function displayForAdmin() {
|
||||||
|
$content = $this->display();
|
||||||
|
$content['owner_modifier_token'] = $this->getOwner()->getModifierToken();
|
||||||
|
$content['admin_key'] = $this->getAdminKey();
|
||||||
|
$content['password_hash'] = $this->getPassword();
|
||||||
|
$content['id'] = $this->getId();
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
public function display() {
|
public function display() {
|
||||||
|
|
||||||
|
$computedAnswers = $this->computeAnswers();
|
||||||
|
$displayedStackOfVotes = [];
|
||||||
|
foreach ( $this->getStacksOfVotes() as $stack ) {
|
||||||
|
$displayedStackOfVotes[] = $stack->display();
|
||||||
|
}
|
||||||
|
$displayedComments = [];
|
||||||
|
foreach ( $this->getComments() as $comment ) {
|
||||||
|
$displayedComments[] = $comment->display();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'config' => $this,
|
'title' => $this->getTitle(),
|
||||||
|
'creation_date' => $this->getCreationDate()->format('c'),
|
||||||
|
'expiracy_date' => $this->getExpiracyDate()->format('c'),
|
||||||
|
'votes_max' => $this->getVotesMax(),
|
||||||
|
'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',
|
'password_protected' => $this->getPassword() ? 'yes' : 'no',
|
||||||
'answers' => $this->computeAnswers(),
|
'max_score' => $computedAnswers['max_score'],
|
||||||
|
'choices' => $computedAnswers['answers'],
|
||||||
|
'stacks' => $displayedStackOfVotes,
|
||||||
|
'comments' => $displayedComments,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user