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
|
$stack
|
||||||
->setPseudo( $data[ 'pseudo' ] )
|
->setPseudo( $data[ 'pseudo' ] )
|
||||||
->setPoll( $poll );
|
->setPoll( $poll );
|
||||||
|
|
||||||
foreach ( $data[ 'votes' ] as $voteInfo ) {
|
foreach ( $data[ 'votes' ] as $voteInfo ) {
|
||||||
$vote = new Vote();
|
$vote = new Vote();
|
||||||
$foundChoice = $poll->findChoiceById( $voteInfo[ 'choice_id' ] );
|
$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 )
|
$vote->setPoll( $poll )
|
||||||
->setChoice( $foundChoice )
|
->setChoice( $foundChoice )
|
||||||
->setValue( $voteInfo[ 'value' ] );
|
->setValue( $voteInfo[ 'value' ] );
|
||||||
@ -350,20 +356,13 @@ class DefaultController extends AbstractController {
|
|||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
return $this->json( [
|
return $this->json( [
|
||||||
'message' => 'you created a vote',
|
'message' => 'you created a vote stack',
|
||||||
'vote_stack' => $stack,
|
'vote_stack' => $stack,
|
||||||
'json_you_sent' => $data,
|
'json_you_sent' => $data,
|
||||||
],
|
],
|
||||||
201 );
|
201 );
|
||||||
}
|
}
|
||||||
|
|
||||||
function newVoteAction( Poll $poll ) {
|
|
||||||
return $this->json( [
|
|
||||||
'message' => 'you voted on the poll',
|
|
||||||
],
|
|
||||||
201 );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Delete(
|
* @Delete(
|
||||||
|
@ -143,6 +143,7 @@ class Poll {
|
|||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
public $defaultExpiracyDaysFromNow = 60;
|
public $defaultExpiracyDaysFromNow = 60;
|
||||||
|
private $maxChoicesLimit = 25;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->votes = new ArrayCollection();
|
$this->votes = new ArrayCollection();
|
||||||
@ -203,17 +204,21 @@ class Poll {
|
|||||||
|
|
||||||
public function findChoiceById( int $id ) {
|
public function findChoiceById( int $id ) {
|
||||||
|
|
||||||
error_reporting( E_ALL ^ E_NOTICE );
|
|
||||||
$choices = $this->getChoices();
|
$choices = $this->getChoices();
|
||||||
var_dump( count( $choices ) );
|
$counter = 0;
|
||||||
// there must be something cleaner than this in Doctrine ArrayCollection
|
// there must be something cleaner than this in Doctrine ArrayCollection
|
||||||
foreach ( $choices as $choice ) {
|
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 ) {
|
if ( $choice && $choice->getId() == $id ) {
|
||||||
return $choice;
|
return $choice;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addDaysToDate( \DateTime $date, int $days ) {
|
public function addDaysToDate( \DateTime $date, int $days ) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user