mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
reorder fields for poll display
This commit is contained in:
parent
85efc2cbe5
commit
83978f1757
@ -104,7 +104,7 @@ class PollController extends EmailsController {
|
||||
|
||||
} else {
|
||||
// free access to poll
|
||||
return $this->json( $poll->display() );
|
||||
return $this->json( sort( $poll->display()) );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,8 @@ use JMS\Serializer\Annotation as Serializer;
|
||||
* @ORM\Entity(repositoryClass="App\Repository\PollRepository")
|
||||
* @Serializer\ExclusionPolicy("all")
|
||||
*/
|
||||
class Poll {
|
||||
class Poll
|
||||
{
|
||||
|
||||
use RandomTrait;
|
||||
|
||||
@ -201,7 +202,8 @@ class Poll {
|
||||
private $adminKey;
|
||||
private $maxChoicesLimit = 25;
|
||||
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
$this->initiate();
|
||||
$this->setCreatedAt(new DateTime());
|
||||
@ -212,7 +214,8 @@ class Poll {
|
||||
$this->comments = new ArrayCollection();
|
||||
}
|
||||
|
||||
private function initiate() {
|
||||
private function initiate()
|
||||
{
|
||||
$this->votes = new ArrayCollection();
|
||||
$this->stacksOfVotes = new ArrayCollection();
|
||||
$this->choices = new ArrayCollection();
|
||||
@ -226,13 +229,15 @@ class Poll {
|
||||
$this->setAllowedAnswers(['yes', 'maybe', 'no']);
|
||||
}
|
||||
|
||||
public function setCreatedAt( DateTimeInterface $createdAt ): self {
|
||||
public function setCreatedAt(DateTimeInterface $createdAt): self
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function displayForAdmin() {
|
||||
public function displayForAdmin()
|
||||
{
|
||||
$content = $this->display();
|
||||
$content['owner'] = $this->getOwner()->displayForAdmin();
|
||||
$content['admin_key'] = $this->getAdminKey();
|
||||
@ -244,7 +249,8 @@ class Poll {
|
||||
|
||||
// counts each number of answer for this choice
|
||||
|
||||
public function display() {
|
||||
public function display()
|
||||
{
|
||||
|
||||
$computedAnswers = $this->computeAnswers();
|
||||
$displayedStackOfVotes = [];
|
||||
@ -262,43 +268,33 @@ class Poll {
|
||||
|
||||
|
||||
$resp = [
|
||||
'title' => $this->getTitle(),
|
||||
'description' => $this->getDescription(),
|
||||
'choices_grouped' => $computedAnswers[ 'grouped_dates' ],
|
||||
'created_at' => $this->getCreatedAt()->format( 'c' ),
|
||||
'expiracy_date' => $this->getExpiracyDate()->format( 'c' ),
|
||||
'votes_max' => $this->getVotesMax(),
|
||||
'custom_url' => $this->getCustomUrl(),
|
||||
'choices_max' => $this->getChoicesMax(),
|
||||
'kind' => $this->getKind(),
|
||||
'allowed_answers' => $this->getAllowedAnswers(),
|
||||
'votes_allowed' => $this->getVotesAllowed(),
|
||||
'modification_policy' => $this->getModificationPolicy(),
|
||||
'hide_results' => $this->getHideResults(),
|
||||
'show_results_even_if_password' => $this->getShowResultEvenIfPasswords(),
|
||||
'owner' => [
|
||||
'pseudo' => $this->getOwner()->getPseudo(),
|
||||
]
|
||||
,
|
||||
'choices' => $computedAnswers['answers'],
|
||||
'password_protected' => $this->getPassword() ? 'yes' : 'no',
|
||||
'max_score' => $computedAnswers[ 'max_score' ],
|
||||
'stacks' => $displayedStackOfVotes,
|
||||
'choices_grouped' => $computedAnswers['grouped_dates'],
|
||||
'choices_max' => $this->getChoicesMax(),
|
||||
'comments' => $displayedComments,
|
||||
'created_at' => $this->getCreatedAt()->format('c'),
|
||||
'custom_url' => $this->getCustomUrl(),
|
||||
'description' => $this->getDescription(),
|
||||
'expiracy_date' => $this->getExpiracyDate()->format('c'),
|
||||
'hide_results' => $this->getHideResults(),
|
||||
'kind' => $this->getKind(),
|
||||
'max_score' => $computedAnswers['max_score'],
|
||||
'modification_policy' => $this->getModificationPolicy(),
|
||||
'owner' => ['pseudo' => $this->getOwner()->getPseudo(),],
|
||||
'password_protected' => $this->getPassword() ? 'yes' : 'no',
|
||||
'show_results_even_if_password' => $this->getShowResultEvenIfPasswords(),
|
||||
'stacks' => $displayedStackOfVotes,
|
||||
'title' => $this->getTitle(),
|
||||
'votes_allowed' => $this->getVotesAllowed(),
|
||||
'votes_max' => $this->getVotesMax(),
|
||||
];
|
||||
|
||||
// if ( $this->getKind() == 'text' ) {
|
||||
// $resp[ 'choices' ] = $computedAnswers[ 'grouped_dates' ];
|
||||
// $resp[ 'choices_grouped' ] = $computedAnswers[ 'answers' ];
|
||||
// } elseif ( $this->getKind() == 'date' ) {
|
||||
// $resp[ 'choices' ] = $computedAnswers[ 'answers' ];
|
||||
// $resp[ 'choices_grouped' ] = $computedAnswers[ 'grouped_dates' ];
|
||||
// }
|
||||
|
||||
return $resp;
|
||||
}
|
||||
|
||||
public function computeAnswers() {
|
||||
public function computeAnswers()
|
||||
{
|
||||
$computedArray = [];
|
||||
$grouped_dates = [];
|
||||
$maxScore = 0;
|
||||
@ -323,8 +319,7 @@ class Poll {
|
||||
"choice_id" => $choice->getId(),
|
||||
"name" => $boom[1],
|
||||
];
|
||||
}
|
||||
elseif(count( $boom ) == 1){
|
||||
} elseif (count($boom) == 1) {
|
||||
$name = $choice->getName();
|
||||
$grouped_dates[$name] = [
|
||||
|
||||
@ -452,25 +447,30 @@ class Poll {
|
||||
/**
|
||||
* @return Collection|Choice[]
|
||||
*/
|
||||
public function getChoices(): Collection {
|
||||
public function getChoices(): Collection
|
||||
{
|
||||
return $this->choices;
|
||||
}
|
||||
|
||||
public function getKind(): ?string {
|
||||
public function getKind(): ?string
|
||||
{
|
||||
return $this->kind;
|
||||
}
|
||||
|
||||
public function setKind( string $kind ): self {
|
||||
public function setKind(string $kind): self
|
||||
{
|
||||
$this->kind = $kind;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStacksOfVotes() {
|
||||
public function getStacksOfVotes()
|
||||
{
|
||||
return $this->stacksOfVotes;
|
||||
}
|
||||
|
||||
public function setStacksOfVotes( ?StackOfVotes $stacksOfVotes ): self {
|
||||
public function setStacksOfVotes(?StackOfVotes $stacksOfVotes): self
|
||||
{
|
||||
$this->stacksOfVotes = $stacksOfVotes;
|
||||
|
||||
return $this;
|
||||
@ -479,69 +479,83 @@ class Poll {
|
||||
/**
|
||||
* @return Collection|Comment[]
|
||||
*/
|
||||
public function getComments(): Collection {
|
||||
public function getComments(): Collection
|
||||
{
|
||||
return $this->comments;
|
||||
}
|
||||
|
||||
public function getTitle(): ?string {
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setTitle( string $title ): self {
|
||||
public function setTitle(string $title): self
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string {
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription( string $description ): self {
|
||||
public function setDescription(string $description): self
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): ?DateTimeInterface {
|
||||
public function getCreatedAt(): ?DateTimeInterface
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function getExpiracyDate(): ?DateTimeInterface {
|
||||
public function getExpiracyDate(): ?DateTimeInterface
|
||||
{
|
||||
return $this->expiracyDate;
|
||||
}
|
||||
|
||||
public function setExpiracyDate( DateTimeInterface $expiracyDate ): self {
|
||||
public function setExpiracyDate(DateTimeInterface $expiracyDate): self
|
||||
{
|
||||
$this->expiracyDate = $expiracyDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getVotesMax() {
|
||||
public function getVotesMax()
|
||||
{
|
||||
return $this->votesMax;
|
||||
}
|
||||
|
||||
public function setVotesMax( $votesMax ): self {
|
||||
public function setVotesMax($votesMax): self
|
||||
{
|
||||
$this->votesMax = $votesMax;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getChoicesMax() {
|
||||
public function getChoicesMax()
|
||||
{
|
||||
return $this->choicesMax;
|
||||
}
|
||||
|
||||
public function setChoicesMax( $choicesMax ): self {
|
||||
public function setChoicesMax($choicesMax): self
|
||||
{
|
||||
$this->choicesMax = $choicesMax;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAllowedAnswers(): ?array {
|
||||
public function getAllowedAnswers(): ?array
|
||||
{
|
||||
return $this->allowedAnswers;
|
||||
}
|
||||
|
||||
public function setAllowedAnswers( array $allowedAnswers ): self {
|
||||
public function setAllowedAnswers(array $allowedAnswers): self
|
||||
{
|
||||
if (!count($allowedAnswers)) {
|
||||
$this->allowedAnswers = ['yes'];
|
||||
} else {
|
||||
@ -551,81 +565,97 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getVotesAllowed(): ?bool {
|
||||
public function getVotesAllowed(): ?bool
|
||||
{
|
||||
return $this->votesAllowed;
|
||||
}
|
||||
|
||||
public function setVotesAllowed( ?bool $votesAllowed ): self {
|
||||
public function setVotesAllowed(?bool $votesAllowed): self
|
||||
{
|
||||
$this->votesAllowed = $votesAllowed;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getModificationPolicy(): ?string {
|
||||
public function getModificationPolicy(): ?string
|
||||
{
|
||||
return $this->modificationPolicy;
|
||||
}
|
||||
|
||||
public function setModificationPolicy( string $modificationPolicy ): self {
|
||||
public function setModificationPolicy(string $modificationPolicy): self
|
||||
{
|
||||
$this->modificationPolicy = $modificationPolicy;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHideResults(): ?bool {
|
||||
public function getHideResults(): ?bool
|
||||
{
|
||||
return $this->hideResults;
|
||||
}
|
||||
|
||||
public function setHideResults( bool $hideResults ): self {
|
||||
public function setHideResults(bool $hideResults): self
|
||||
{
|
||||
$this->hideResults = $hideResults;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getShowResultEvenIfPasswords(): ?bool {
|
||||
public function getShowResultEvenIfPasswords(): ?bool
|
||||
{
|
||||
return $this->showResultEvenIfPasswords;
|
||||
}
|
||||
|
||||
public function setShowResultEvenIfPasswords( bool $showResultEvenIfPasswords ): self {
|
||||
public function setShowResultEvenIfPasswords(bool $showResultEvenIfPasswords): self
|
||||
{
|
||||
$this->showResultEvenIfPasswords = $showResultEvenIfPasswords;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOwner(): ?Owner {
|
||||
public function getOwner(): ?Owner
|
||||
{
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
public function setOwner( ?Owner $owner ): self {
|
||||
public function setOwner(?Owner $owner): self
|
||||
{
|
||||
$this->owner = $owner;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPassword(): ?string {
|
||||
public function getPassword(): ?string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function setPassword( string $password ): self {
|
||||
public function setPassword(string $password): self
|
||||
{
|
||||
$this->password = md5($password);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAdminKey(): ?string {
|
||||
public function getAdminKey(): ?string
|
||||
{
|
||||
return $this->adminKey;
|
||||
}
|
||||
|
||||
public function setAdminKey( string $adminKey ): self {
|
||||
public function setAdminKey(string $adminKey): self
|
||||
{
|
||||
$this->adminKey = $adminKey;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getId(): ?int {
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function findChoiceById( int $id ) {
|
||||
public function findChoiceById(int $id)
|
||||
{
|
||||
|
||||
$choices = $this->getChoices();
|
||||
$counter = 0;
|
||||
@ -647,41 +677,49 @@ class Poll {
|
||||
/**
|
||||
* @return Collection|Vote[]
|
||||
*/
|
||||
public function getVotes(): Collection {
|
||||
public function getVotes(): Collection
|
||||
{
|
||||
return $this->votes;
|
||||
}
|
||||
|
||||
public function getCustomUrl(): ?string {
|
||||
public function getCustomUrl(): ?string
|
||||
{
|
||||
return $this->customUrl;
|
||||
}
|
||||
|
||||
public function setCustomUrl( string $customUrl ): self {
|
||||
public function setCustomUrl(string $customUrl): self
|
||||
{
|
||||
$this->customUrl = $customUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMailOnComment(): ?bool {
|
||||
public function getMailOnComment(): ?bool
|
||||
{
|
||||
return $this->mailOnComment;
|
||||
}
|
||||
|
||||
public function setMailOnComment( bool $mailOnComment ): self {
|
||||
public function setMailOnComment(bool $mailOnComment): self
|
||||
{
|
||||
$this->mailOnComment = $mailOnComment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMailOnVote(): ?bool {
|
||||
public function getMailOnVote(): ?bool
|
||||
{
|
||||
return $this->mailOnVote;
|
||||
}
|
||||
|
||||
public function setMailOnVote( bool $mailOnVote ): self {
|
||||
public function setMailOnVote(bool $mailOnVote): self
|
||||
{
|
||||
$this->mailOnVote = $mailOnVote;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addComment( Comment $comment ): self {
|
||||
public function addComment(Comment $comment): self
|
||||
{
|
||||
if (!$this->comments->contains($comment)) {
|
||||
$this->comments[] = $comment;
|
||||
$comment->setPoll($this);
|
||||
@ -690,7 +728,8 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeComment( Comment $comment ): self {
|
||||
public function removeComment(Comment $comment): self
|
||||
{
|
||||
if ($this->comments->contains($comment)) {
|
||||
$this->comments->removeElement($comment);
|
||||
// set the owning side to null (unless already changed)
|
||||
@ -702,7 +741,8 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addStackOfVote( StackOfVotes $stackOfVote ): self {
|
||||
public function addStackOfVote(StackOfVotes $stackOfVote): self
|
||||
{
|
||||
if (!$this->stacksOfVotes->contains($stackOfVote)) {
|
||||
$this->stacksOfVotes[] = $stackOfVote;
|
||||
$stackOfVote->setPoll($this);
|
||||
@ -711,7 +751,8 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeStackOfVote( StackOfVotes $stackOfVote ): self {
|
||||
public function removeStackOfVote(StackOfVotes $stackOfVote): self
|
||||
{
|
||||
if ($this->stacksOfVotes->contains($stackOfVote)) {
|
||||
$this->stacksOfVotes->removeElement($stackOfVote);
|
||||
// set the owning side to null (unless already changed)
|
||||
@ -723,7 +764,8 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addVote( Vote $vote ): self {
|
||||
public function addVote(Vote $vote): self
|
||||
{
|
||||
if (!$this->votes->contains($vote)) {
|
||||
$this->votes[] = $vote;
|
||||
$vote->setPoll($this);
|
||||
@ -732,7 +774,8 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeVote( Vote $vote ): self {
|
||||
public function removeVote(Vote $vote): self
|
||||
{
|
||||
if ($this->votes->contains($vote)) {
|
||||
$this->votes->removeElement($vote);
|
||||
// set the owning side to null (unless already changed)
|
||||
@ -744,7 +787,8 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addTextChoiceArray( array $choiceTextArray ): self {
|
||||
public function addTextChoiceArray(array $choiceTextArray): self
|
||||
{
|
||||
foreach ($choiceTextArray as $text) {
|
||||
$newChoice = new Choice();
|
||||
$newChoice->setName($text);
|
||||
@ -754,7 +798,8 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addChoice( Choice $choice ): self {
|
||||
public function addChoice(Choice $choice): self
|
||||
{
|
||||
if (!is_null($this->choices)) {
|
||||
if (!$this->choices->contains($choice)) {
|
||||
$this->choices[] = $choice;
|
||||
@ -769,7 +814,8 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addStacksOfVote( StackOfVotes $stacksOfVote ): self {
|
||||
public function addStacksOfVote(StackOfVotes $stacksOfVote): self
|
||||
{
|
||||
if (!$this->stacksOfVotes->contains($stacksOfVote)) {
|
||||
$this->stacksOfVotes[] = $stacksOfVote;
|
||||
$stacksOfVote->setPoll($this);
|
||||
@ -778,7 +824,8 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeStacksOfVote( StackOfVotes $stacksOfVote ): self {
|
||||
public function removeStacksOfVote(StackOfVotes $stacksOfVote): self
|
||||
{
|
||||
if ($this->stacksOfVotes->contains($stacksOfVote)) {
|
||||
$this->stacksOfVotes->removeElement($stacksOfVote);
|
||||
// set the owning side to null (unless already changed)
|
||||
@ -790,7 +837,8 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeChoice( Choice $choice ): self {
|
||||
public function removeChoice(Choice $choice): self
|
||||
{
|
||||
if ($this->choices->contains($choice)) {
|
||||
$this->choices->removeElement($choice);
|
||||
// set the owning side to null (unless already changed)
|
||||
@ -802,21 +850,25 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCommentsAllowed(): ?bool {
|
||||
public function getCommentsAllowed(): ?bool
|
||||
{
|
||||
return $this->commentsAllowed;
|
||||
}
|
||||
|
||||
public function setCommentsAllowed( ?bool $commentsAllowed ): self {
|
||||
public function setCommentsAllowed(?bool $commentsAllowed): self
|
||||
{
|
||||
$this->commentsAllowed = $commentsAllowed;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIsZeroKnowledge(): ?bool {
|
||||
public function getIsZeroKnowledge(): ?bool
|
||||
{
|
||||
return $this->isZeroKnowledge;
|
||||
}
|
||||
|
||||
public function setIsZeroKnowledge( ?bool $isZeroKnowledge ): self {
|
||||
public function setIsZeroKnowledge(?bool $isZeroKnowledge): self
|
||||
{
|
||||
$this->isZeroKnowledge = $isZeroKnowledge;
|
||||
|
||||
return $this;
|
||||
|
Loading…
Reference in New Issue
Block a user