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 SerializerInterface $serializer
|
||||||
* @param Poll $poll
|
* @param string $custom_url
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
*
|
*
|
||||||
* @return JsonResponse|Response
|
* @return JsonResponse|Response
|
||||||
*/
|
*/
|
||||||
public function newVoteStackAction(
|
public function newVoteStackAction(
|
||||||
SerializerInterface $serializer,
|
SerializerInterface $serializer,
|
||||||
Poll $poll,
|
string $custom_url,
|
||||||
Request $request
|
Request $request
|
||||||
) {
|
) {
|
||||||
|
$entityManager = $this->getDoctrine()->getManager();
|
||||||
|
$poll = $entityManager->findOneByCustomUrl(Poll::class, $custom_url);
|
||||||
|
|
||||||
if ( ! $poll ) {
|
if ( ! $poll ) {
|
||||||
return $this->json( [ 'message' => 'poll not found' ], 404 );
|
return $this->json( [ 'message' => 'poll "'.$custom_url.'" not found' ], 404 );
|
||||||
}
|
}
|
||||||
|
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
@ -67,13 +70,13 @@ class VoteController extends EmailsController {
|
|||||||
}
|
}
|
||||||
// TODO anti flood
|
// TODO anti flood
|
||||||
$foundOwner
|
$foundOwner
|
||||||
->setModifierToken( $poll->generateRandomKey() );
|
->setModifierToken( $custom_url->generateRandomKey() );
|
||||||
$stack = new StackOfVotes();
|
$stack = new StackOfVotes();
|
||||||
$stack
|
$stack
|
||||||
->setOwner( $foundOwner )
|
->setOwner( $foundOwner )
|
||||||
->setIp( $_SERVER[ 'REMOTE_ADDR' ] )
|
->setIp( $_SERVER[ 'REMOTE_ADDR' ] )
|
||||||
->setPseudo( $data[ 'pseudo' ] )
|
->setPseudo( $data[ 'pseudo' ] )
|
||||||
->setPoll( $poll );
|
->setPoll( $custom_url );
|
||||||
foreach ( $data[ 'votes' ] as $voteInfo ) {
|
foreach ( $data[ 'votes' ] as $voteInfo ) {
|
||||||
|
|
||||||
if ( ! isset( $voteInfo[ 'value' ] ) ) {
|
if ( ! isset( $voteInfo[ 'value' ] ) ) {
|
||||||
@ -97,28 +100,28 @@ class VoteController extends EmailsController {
|
|||||||
],
|
],
|
||||||
404 );
|
404 );
|
||||||
}
|
}
|
||||||
$vote->setPoll( $poll )
|
$vote->setPoll( $custom_url )
|
||||||
->setChoice( $foundChoice )
|
->setChoice( $foundChoice )
|
||||||
->setValue( $voteInfo[ 'value' ] );
|
->setValue( $voteInfo[ 'value' ] );
|
||||||
$vote->setPoll( $poll );
|
$vote->setPoll( $custom_url );
|
||||||
$stack->addVote( $vote );
|
$stack->addVote( $vote );
|
||||||
$poll->addVote( $vote );
|
$custom_url->addVote( $vote );
|
||||||
$em->persist( $vote );
|
$em->persist( $vote );
|
||||||
$em->persist( $foundChoice );
|
$em->persist( $foundChoice );
|
||||||
}
|
}
|
||||||
|
|
||||||
// find poll from choices
|
// find poll from choices
|
||||||
$poll->addStackOfVote( $stack );
|
$custom_url->addStackOfVote( $stack );
|
||||||
$em->persist( $stack );
|
$em->persist( $stack );
|
||||||
$em->persist( $poll );
|
$em->persist( $custom_url );
|
||||||
$em->flush();
|
$em->flush();
|
||||||
$precision = '';
|
$precision = '';
|
||||||
if ( $existingOwner ) {
|
if ( $existingOwner ) {
|
||||||
$precision = ' from an existing owner : ' . $foundOwner->getEmail();
|
$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 );
|
$this->sendVoteNotificationAction( $stack->getOwner(), $stack );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user