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; 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 {

View File

@ -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 ) {