mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
parent
5716642c09
commit
f2edaa49f0
@ -47,14 +47,22 @@ class VoteController extends EmailsController {
|
||||
) {
|
||||
|
||||
|
||||
/***
|
||||
* checks before persisting
|
||||
*/
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$emPol = $em->getRepository( Poll::class );
|
||||
$poll = $emPol->findOneByCustomUrl( $custom_url );
|
||||
|
||||
// check : existence of poll
|
||||
if ( ! $poll ) {
|
||||
return $this->json( [ 'message' => 'poll "' . $custom_url . '" not found' ], 404 );
|
||||
}
|
||||
|
||||
// check : limit of number of participation max
|
||||
if ( count( $poll->getStacksOfVotes() ) == $poll->getVotesMax() ) {
|
||||
return $this->json( [ 'message' => 'poll "' . $custom_url . '" not allowed to have more stack of votes than ' . $poll->getVotesMax() ],
|
||||
403 );
|
||||
}
|
||||
$data = $request->getContent();
|
||||
$data = json_decode( $data, true );
|
||||
|
||||
@ -63,32 +71,30 @@ class VoteController extends EmailsController {
|
||||
|
||||
$owner = new Owner();
|
||||
$owner
|
||||
->addPoll( $poll )
|
||||
|
||||
;
|
||||
->addPoll( $poll );
|
||||
$newStack = new StackOfVotes();
|
||||
$newStack
|
||||
->setPoll($poll)
|
||||
->setPoll( $poll )
|
||||
->setIp( $_SERVER[ 'REMOTE_ADDR' ] )
|
||||
->setPseudo( $data[ "pseudo" ] )
|
||||
->setOwner( $owner );
|
||||
$owner
|
||||
->setPseudo($data['owner'][ "pseudo" ])
|
||||
->setPseudo($data['owner'][ "email" ])
|
||||
->addStackOfVote($newStack);
|
||||
->setPseudo( $data[ 'owner' ][ "pseudo" ] )
|
||||
->setPseudo( $data[ 'owner' ][ "email" ] )
|
||||
->addStackOfVote( $newStack );
|
||||
|
||||
// TODO manage new comment
|
||||
$emChoice = $choice_repository;
|
||||
$newComment = new Comment();
|
||||
$newComment->setPseudo($data ['pseudo'])
|
||||
->setPoll($poll)
|
||||
->setText($data['comment']);
|
||||
$owner->addComment($newComment);
|
||||
$newComment->setPseudo( $data [ 'pseudo' ] )
|
||||
->setPoll( $poll )
|
||||
->setText( $data[ 'comment' ] );
|
||||
$owner->addComment( $newComment );
|
||||
|
||||
$em->persist($newComment);
|
||||
$em->persist( $newComment );
|
||||
|
||||
foreach ( $data[ 'votes' ] as $vote ) {
|
||||
if(!$vote[ 'value' ]){
|
||||
if ( ! $vote[ 'value' ] ) {
|
||||
continue;
|
||||
}
|
||||
$newVote = new Vote();
|
||||
|
Loading…
Reference in New Issue
Block a user