createdAt = new \DateTimeImmutable('now'); $this->createdBy = new NullProfile(); $this->question = new NullQAQuestion(); } /** * Get the total vote score * * @return int * * @since 1.0.0 */ public function getVoteScore() : int { $score = 0; foreach ($this->votes as $vote) { $score += $vote->score; } return $score; } /** * Get the vote score from an account * * @param int $account Account id * * @return int * * @since 1.0.0 */ public function getAccountVoteScore(int $account) : int { foreach ($this->votes as $vote) { if ($vote->createdBy->id === $account) { return $vote->score; } } return 0; } /** * Get all votes * * @return QAAnswerVote[] * * @since 1.0.0 */ public function getVotes() : array { return $this->votes; } /** * Add vote * * @param QAAnswerVote $vote Vote * * @return void * * @since 1.0.0 */ public function addVote(QAAnswerVote $vote) : void { $this->votes[] = $vote; } /** * {@inheritdoc} */ public function toArray() : array { return [ 'id' => $this->id, 'status' => $this->status, 'answer' => $this->answer, 'answerRaw' => $this->answerRaw, 'question' => $this->question, 'isAccepted' => $this->isAccepted, 'createdBy' => $this->createdBy, 'createdAt' => $this->createdAt, 'votes' => $this->votes, 'media' => $this->files, ]; } /** * {@inheritdoc} */ public function jsonSerialize() : mixed { return $this->toArray(); } use \Modules\Media\Models\MediaListTrait; }