ugly way to retrieve poll properties because of jsmserializer config not working as expected

This commit is contained in:
Baptiste Lemoine 2019-12-01 15:36:31 +01:00
parent ee93cd5c26
commit 518373f591
3 changed files with 28 additions and 17 deletions

View File

@ -173,18 +173,36 @@ class DefaultController extends AbstractController {
$pass = $poll->getPassword();
$data = $request->getContent();
$data = json_decode( $data, true );
$comments = [];
$stacks = [];
$choices = [];
foreach ( $poll->getComments() as $c ) {
$comments[] = $c;
}
foreach ( $poll->getStacksOfVotes() as $c ) {
$stacks[] = $c;
}
foreach ( $poll->getChoices() as $c ) {
$choices[] = $c;
}
$returnedPoll = [
'message' => 'your poll config',
'data' => $poll,
'stacks_count' => count( $stacks ),
'stacks' => $stacks,
'choices_count' => count( $choices ),
'choices' => $choices,
'comments' => $comments,
];
/**
* password protected content
*/
if ( $pass ) {
if ( $pass == md5( $data[ 'password_input' ] ) ) {
return $this->json( [
'message' => 'your poll config',
'data' => $poll,
'stacks' => $poll->getStacksOfVotes(),
'comments' => $poll->getComments(),
],
return $this->json(
$returnedPoll,
200 );
} else {
return $this->json( [
@ -194,12 +212,9 @@ class DefaultController extends AbstractController {
403 );
}
} else {
return $this->json( [
'message' => 'your poll config',
'data' => $poll,
'stacks' => $poll->getStacksOfVotes(),
'comments' => $poll->getComments(),
],
return $this->json(
$returnedPoll
,
200 );
}

View File

@ -19,7 +19,7 @@ class Choice {
* @ORM\Column(type="integer")
* @Serializer\Expose()
*/
private $id;
public $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)

View File

@ -112,25 +112,21 @@ 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;
/**
* @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
* @Serializer\Type("App\Entity\StackOfVotes")
* @Serializer\Expose()
*/
public $stacksOfVotes;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
* @Serializer\Type("App\Entity\Choice")
* @Serializer\Expose()
*/
public $choices;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
* @Serializer\Type("App\Entity\Comment")
* @Serializer\Expose()
*/
public $comments;