mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
find a poll by custom url in vote stack add action
This commit is contained in:
parent
2733c1f2a3
commit
d63929eb93
@ -33,18 +33,21 @@ class VoteController extends EmailsController {
|
||||
* )
|
||||
*
|
||||
* @param SerializerInterface $serializer
|
||||
* @param Poll $poll
|
||||
* @param string $custom_url
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function newVoteStackAction(
|
||||
SerializerInterface $serializer,
|
||||
Poll $poll,
|
||||
string $custom_url,
|
||||
Request $request
|
||||
) {
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$poll = $entityManager->findOneByCustomUrl(Poll::class, $custom_url);
|
||||
|
||||
if ( ! $poll ) {
|
||||
return $this->json( [ 'message' => 'poll not found' ], 404 );
|
||||
return $this->json( [ 'message' => 'poll "'.$custom_url.'" not found' ], 404 );
|
||||
}
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
@ -67,13 +70,13 @@ class VoteController extends EmailsController {
|
||||
}
|
||||
// TODO anti flood
|
||||
$foundOwner
|
||||
->setModifierToken( $poll->generateRandomKey() );
|
||||
->setModifierToken( $custom_url->generateRandomKey() );
|
||||
$stack = new StackOfVotes();
|
||||
$stack
|
||||
->setOwner( $foundOwner )
|
||||
->setIp( $_SERVER[ 'REMOTE_ADDR' ] )
|
||||
->setPseudo( $data[ 'pseudo' ] )
|
||||
->setPoll( $poll );
|
||||
->setPoll( $custom_url );
|
||||
foreach ( $data[ 'votes' ] as $voteInfo ) {
|
||||
|
||||
if ( ! isset( $voteInfo[ 'value' ] ) ) {
|
||||
@ -97,28 +100,28 @@ class VoteController extends EmailsController {
|
||||
],
|
||||
404 );
|
||||
}
|
||||
$vote->setPoll( $poll )
|
||||
$vote->setPoll( $custom_url )
|
||||
->setChoice( $foundChoice )
|
||||
->setValue( $voteInfo[ 'value' ] );
|
||||
$vote->setPoll( $poll );
|
||||
$vote->setPoll( $custom_url );
|
||||
$stack->addVote( $vote );
|
||||
$poll->addVote( $vote );
|
||||
$custom_url->addVote( $vote );
|
||||
$em->persist( $vote );
|
||||
$em->persist( $foundChoice );
|
||||
}
|
||||
|
||||
// find poll from choices
|
||||
$poll->addStackOfVote( $stack );
|
||||
$custom_url->addStackOfVote( $stack );
|
||||
$em->persist( $stack );
|
||||
$em->persist( $poll );
|
||||
$em->persist( $custom_url );
|
||||
$em->flush();
|
||||
$precision = '';
|
||||
if ( $existingOwner ) {
|
||||
$precision = ' from an existing owner : ' . $foundOwner->getEmail();
|
||||
}
|
||||
$stacks = $poll->getStacksOfVotes();
|
||||
$stacks = $custom_url->getStacksOfVotes();
|
||||
|
||||
if ( $poll->getMailOnVote() ) {
|
||||
if ( $custom_url->getMailOnVote() ) {
|
||||
$this->sendVoteNotificationAction( $stack->getOwner(), $stack );
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user