1
0
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:
Tykayn 2021-04-27 11:26:54 +02:00 committed by tykayn
parent 8c2ad610a5
commit ecdbf3fb33
2 changed files with 9 additions and 3 deletions

View File

@ -67,13 +67,19 @@ class Choice {
return $this;
}
public function display() {
return [
public function display( $kind = 'text' ) {
$fields = [
'id' => $this->getId(),
'created_at' => $this->getCreatedAtAsString(),
'name' => $this->getName(),
'url' => $this->getUrl(),
];
if ( $kind === 'date' ) {
$date = new DateTime( $this->getName() );
$fields[ 'name' ] = $date->format( 'c' );
}
return $fields;
}
public function getId(): ?int {

View File

@ -290,7 +290,7 @@ class Poll {
// first, prefill all choices
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
foreach ( $this->getStacksOfVotes() as $stack_of_vote ) {