mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
🐛 fix vote stack adding
This commit is contained in:
parent
fceb2be35d
commit
087fbafd6a
@ -329,10 +329,16 @@ class DefaultController extends AbstractController {
|
||||
$stack
|
||||
->setPseudo( $data[ 'pseudo' ] )
|
||||
->setPoll( $poll );
|
||||
|
||||
foreach ( $data[ 'votes' ] as $voteInfo ) {
|
||||
$vote = new Vote();
|
||||
$foundChoice = $poll->findChoiceById( $voteInfo[ 'choice_id' ] );
|
||||
if ( ! $foundChoice ) {
|
||||
return $this->json( [
|
||||
'message' => 'choice ' . $voteInfo[ 'choice_id' ] . ' was not found',
|
||||
'vote_stack' => $stack,
|
||||
],
|
||||
404 );
|
||||
}
|
||||
$vote->setPoll( $poll )
|
||||
->setChoice( $foundChoice )
|
||||
->setValue( $voteInfo[ 'value' ] );
|
||||
@ -350,20 +356,13 @@ class DefaultController extends AbstractController {
|
||||
$em->flush();
|
||||
|
||||
return $this->json( [
|
||||
'message' => 'you created a vote',
|
||||
'message' => 'you created a vote stack',
|
||||
'vote_stack' => $stack,
|
||||
'json_you_sent' => $data,
|
||||
],
|
||||
201 );
|
||||
}
|
||||
|
||||
function newVoteAction( Poll $poll ) {
|
||||
return $this->json( [
|
||||
'message' => 'you voted on the poll',
|
||||
],
|
||||
201 );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Delete(
|
||||
|
@ -143,6 +143,7 @@ class Poll {
|
||||
* @var int
|
||||
*/
|
||||
public $defaultExpiracyDaysFromNow = 60;
|
||||
private $maxChoicesLimit = 25;
|
||||
|
||||
public function __construct() {
|
||||
$this->votes = new ArrayCollection();
|
||||
@ -203,17 +204,21 @@ class Poll {
|
||||
|
||||
public function findChoiceById( int $id ) {
|
||||
|
||||
error_reporting( E_ALL ^ E_NOTICE );
|
||||
$choices = $this->getChoices();
|
||||
var_dump( count( $choices ) );
|
||||
$counter = 0;
|
||||
// there must be something cleaner than this in Doctrine ArrayCollection
|
||||
foreach ( $choices as $choice ) {
|
||||
$counter ++;
|
||||
if ( $counter > $this->maxChoicesLimit ) {
|
||||
throw new \ErrorException( "max number of choices reached for this poll" );
|
||||
}
|
||||
if ( $choice && $choice->getId() == $id ) {
|
||||
return $choice;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function addDaysToDate( \DateTime $date, int $days ) {
|
||||
|
Loading…
Reference in New Issue
Block a user