mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
Merge branch 'master' of https://framagit.org/tykayn/date-poll-api
This commit is contained in:
commit
e9bfa38413
@ -162,6 +162,20 @@ class DefaultController extends AbstractController {
|
|||||||
$em->persist( $newpoll );
|
$em->persist( $newpoll );
|
||||||
$em->persist( $foundOwner );
|
$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
|
// setup the password, converting the raw with md5 hash
|
||||||
if ( $data[ 'password' ] ) {
|
if ( $data[ 'password' ] ) {
|
||||||
$newpoll->setPassword( $data[ 'password' ] );
|
$newpoll->setPassword( $data[ 'password' ] );
|
||||||
@ -423,6 +437,7 @@ class DefaultController extends AbstractController {
|
|||||||
|
|
||||||
|
|
||||||
$emOwner = $this->getDoctrine()->getRepository( Owner::class );
|
$emOwner = $this->getDoctrine()->getRepository( Owner::class );
|
||||||
|
$emChoice = $this->getDoctrine()->getRepository( Choice::class );
|
||||||
$existingOwner = false;
|
$existingOwner = false;
|
||||||
$foundOwner = $emOwner->findOneByEmail( trim( $data[ 'email' ] ) );
|
$foundOwner = $emOwner->findOneByEmail( trim( $data[ 'email' ] ) );
|
||||||
// manage existing or new Owner
|
// manage existing or new Owner
|
||||||
@ -443,8 +458,21 @@ class DefaultController extends AbstractController {
|
|||||||
->setPseudo( $data[ 'pseudo' ] )
|
->setPseudo( $data[ 'pseudo' ] )
|
||||||
->setPoll( $poll );
|
->setPoll( $poll );
|
||||||
foreach ( $data[ 'votes' ] as $voteInfo ) {
|
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();
|
$vote = new Vote();
|
||||||
$foundChoice = $poll->findChoiceById( $voteInfo[ 'choice_id' ] );
|
$foundChoice = $emChoice->find( $voteInfo[ 'choice_id' ] );
|
||||||
if ( ! $foundChoice ) {
|
if ( ! $foundChoice ) {
|
||||||
return $this->json( [
|
return $this->json( [
|
||||||
'message' => 'choice ' . $voteInfo[ 'choice_id' ] . ' was not found',
|
'message' => 'choice ' . $voteInfo[ 'choice_id' ] . ' was not found',
|
||||||
@ -474,6 +502,7 @@ class DefaultController extends AbstractController {
|
|||||||
|
|
||||||
return $this->json( [
|
return $this->json( [
|
||||||
'message' => 'you created a vote stack' . $precision,
|
'message' => 'you created a vote stack' . $precision,
|
||||||
|
'poll' => $poll,
|
||||||
'vote_stack' => $stack->display(),
|
'vote_stack' => $stack->display(),
|
||||||
'vote_count' => count( $poll->getStacksOfVotes() ),
|
'vote_count' => count( $poll->getStacksOfVotes() ),
|
||||||
'owner_modifier_token' => $foundOwner->getModifierToken(),
|
'owner_modifier_token' => $foundOwner->getModifierToken(),
|
||||||
|
@ -112,6 +112,7 @@ class Poll {
|
|||||||
public $showResultEvenIfPasswords;
|
public $showResultEvenIfPasswords;
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
|
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
|
||||||
|
* @Serializer\Type("App\Entity\Vote")
|
||||||
* @Serializer\Expose()
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
public $votes;
|
public $votes;
|
||||||
@ -128,6 +129,7 @@ class Poll {
|
|||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
|
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
|
||||||
* @Serializer\Expose()
|
* @Serializer\Expose()
|
||||||
|
* @Serializer\Type("App\Entity\Comment")
|
||||||
*/
|
*/
|
||||||
public $comments;
|
public $comments;
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user