This commit is contained in:
Kayn Ty 2020-01-23 15:19:17 +00:00
commit e9bfa38413
2 changed files with 32 additions and 1 deletions

View File

@ -162,6 +162,20 @@ class DefaultController extends AbstractController {
$em->persist( $newpoll );
$em->persist( $foundOwner );
// emails
$newpoll->setMailOnComment( true );
$newpoll->setMailOnVote( true );
$newpoll->setHideResults( false );
// possible answers
$newpoll->setAllowedAnswers( [ 'yes' ] );
if ( $data[ 'voteChoices' ] ) {
switch ( $data[ 'voteChoices' ] ) {
case "only_yes":
default:
break;
}
}
// setup the password, converting the raw with md5 hash
if ( $data[ 'password' ] ) {
$newpoll->setPassword( $data[ 'password' ] );
@ -423,6 +437,7 @@ class DefaultController extends AbstractController {
$emOwner = $this->getDoctrine()->getRepository( Owner::class );
$emChoice = $this->getDoctrine()->getRepository( Choice::class );
$existingOwner = false;
$foundOwner = $emOwner->findOneByEmail( trim( $data[ 'email' ] ) );
// manage existing or new Owner
@ -443,8 +458,21 @@ class DefaultController extends AbstractController {
->setPseudo( $data[ 'pseudo' ] )
->setPoll( $poll );
foreach ( $data[ 'votes' ] as $voteInfo ) {
if ( ! isset( $voteInfo[ 'value' ] ) ) {
continue;
}
$allowedValuesToAnswer = [ 'yes', 'maybe', 'no' ];
if ( ! in_array( $voteInfo[ 'value' ], $allowedValuesToAnswer ) ) {
return $this->json( [
'message' => 'answer ' . $voteInfo[ 'value' ] . ' is not allowed. should be yes, maybe, or no.',
'vote_stack' => $stack,
],
404 );
}
$vote = new Vote();
$foundChoice = $poll->findChoiceById( $voteInfo[ 'choice_id' ] );
$foundChoice = $emChoice->find( $voteInfo[ 'choice_id' ] );
if ( ! $foundChoice ) {
return $this->json( [
'message' => 'choice ' . $voteInfo[ 'choice_id' ] . ' was not found',
@ -474,6 +502,7 @@ class DefaultController extends AbstractController {
return $this->json( [
'message' => 'you created a vote stack' . $precision,
'poll' => $poll,
'vote_stack' => $stack->display(),
'vote_count' => count( $poll->getStacksOfVotes() ),
'owner_modifier_token' => $foundOwner->getModifierToken(),

View File

@ -112,6 +112,7 @@ class Poll {
public $showResultEvenIfPasswords;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
* @Serializer\Type("App\Entity\Vote")
* @Serializer\Expose()
*/
public $votes;
@ -128,6 +129,7 @@ class Poll {
/**
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
* @Serializer\Expose()
* @Serializer\Type("App\Entity\Comment")
*/
public $comments;
/**