mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
⚡ ugly way to retrieve poll properties because of jsmserializer config not working as expected
This commit is contained in:
parent
a3cc53126f
commit
0ce0e4f427
@ -173,18 +173,36 @@ class DefaultController extends AbstractController {
|
|||||||
$pass = $poll->getPassword();
|
$pass = $poll->getPassword();
|
||||||
$data = $request->getContent();
|
$data = $request->getContent();
|
||||||
$data = json_decode( $data, true );
|
$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
|
* password protected content
|
||||||
*/
|
*/
|
||||||
if ( $pass ) {
|
if ( $pass ) {
|
||||||
|
|
||||||
if ( $pass == md5( $data[ 'password_input' ] ) ) {
|
if ( $pass == md5( $data[ 'password_input' ] ) ) {
|
||||||
return $this->json( [
|
return $this->json(
|
||||||
'message' => 'your poll config',
|
$returnedPoll,
|
||||||
'data' => $poll,
|
|
||||||
'stacks' => $poll->getStacksOfVotes(),
|
|
||||||
'comments' => $poll->getComments(),
|
|
||||||
],
|
|
||||||
200 );
|
200 );
|
||||||
} else {
|
} else {
|
||||||
return $this->json( [
|
return $this->json( [
|
||||||
@ -194,12 +212,9 @@ class DefaultController extends AbstractController {
|
|||||||
403 );
|
403 );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return $this->json( [
|
return $this->json(
|
||||||
'message' => 'your poll config',
|
$returnedPoll
|
||||||
'data' => $poll,
|
,
|
||||||
'stacks' => $poll->getStacksOfVotes(),
|
|
||||||
'comments' => $poll->getComments(),
|
|
||||||
],
|
|
||||||
200 );
|
200 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class Choice {
|
|||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
* @Serializer\Expose()
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
private $id;
|
public $id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=255, nullable=true)
|
* @ORM\Column(type="string", length=255, nullable=true)
|
||||||
|
@ -112,25 +112,21 @@ 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;
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
|
* @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
|
||||||
* @Serializer\Type("App\Entity\StackOfVotes")
|
|
||||||
* @Serializer\Expose()
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
public $stacksOfVotes;
|
public $stacksOfVotes;
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
|
* @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
|
||||||
* @Serializer\Type("App\Entity\Choice")
|
|
||||||
* @Serializer\Expose()
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
public $choices;
|
public $choices;
|
||||||
/**
|
/**
|
||||||
* @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\Type("App\Entity\Comment")
|
|
||||||
* @Serializer\Expose()
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
public $comments;
|
public $comments;
|
||||||
|
Loading…
Reference in New Issue
Block a user