mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
format date string for choices in poll of date kind
This commit is contained in:
parent
8c2ad610a5
commit
ecdbf3fb33
@ -67,13 +67,19 @@ class Choice {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function display() {
|
public function display( $kind = 'text' ) {
|
||||||
return [
|
$fields = [
|
||||||
'id' => $this->getId(),
|
'id' => $this->getId(),
|
||||||
'created_at' => $this->getCreatedAtAsString(),
|
'created_at' => $this->getCreatedAtAsString(),
|
||||||
'name' => $this->getName(),
|
'name' => $this->getName(),
|
||||||
'url' => $this->getUrl(),
|
'url' => $this->getUrl(),
|
||||||
];
|
];
|
||||||
|
if ( $kind === 'date' ) {
|
||||||
|
$date = new DateTime( $this->getName() );
|
||||||
|
$fields[ 'name' ] = $date->format( 'c' );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): ?int {
|
public function getId(): ?int {
|
||||||
|
@ -290,7 +290,7 @@ class Poll {
|
|||||||
|
|
||||||
// first, prefill all choices
|
// first, prefill all choices
|
||||||
foreach ( $this->getChoices() as $choice ) {
|
foreach ( $this->getChoices() as $choice ) {
|
||||||
$computedArray[ $choice->getId() ] = array_merge($scoreInfos, $choice->display());
|
$computedArray[ $choice->getId() ] = array_merge($scoreInfos, $choice->display($this->getKind()));
|
||||||
}
|
}
|
||||||
// then, compute stack of votes scores on each choice
|
// then, compute stack of votes scores on each choice
|
||||||
foreach ( $this->getStacksOfVotes() as $stack_of_vote ) {
|
foreach ( $this->getStacksOfVotes() as $stack_of_vote ) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user