diff --git a/Controller/ApiController.php b/Controller/ApiController.php index e86f7a9..cdd9f61 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -242,13 +242,13 @@ final class ApiController extends Controller { $mardkownParser = new Markdown(); - $answer = new QAAnswer(); - $answer->answerRaw = (string) $request->getData('plain'); - $answer->answer = Markdown::parse((string) ($request->getData('plain') ?? '')); - $answer->question = new NullQAQuestion((int) $request->getData('question')); - $answer->isAccepted = false; + $answer = new QAAnswer(); + $answer->answerRaw = (string) $request->getData('plain'); + $answer->answer = Markdown::parse((string) ($request->getData('plain') ?? '')); + $answer->question = new NullQAQuestion((int) $request->getData('question')); + $answer->isAccepted = false; $answer->setStatus((int) $request->getData('status')); - $answer->createdBy = new NullAccount($request->header->account); + $answer->createdBy = new Profile(new NullAccount($request->header->account)); return $answer; } diff --git a/Models/QAAnswer.php b/Models/QAAnswer.php index 626ddfd..fba0b5f 100755 --- a/Models/QAAnswer.php +++ b/Models/QAAnswer.php @@ -215,6 +215,13 @@ class QAAnswer implements \JsonSerializable $this->isAccepted = $accepted; } + /** + * Get the total vote score + * + * @return int + * + * @since 1.0.0 + */ public function getVoteScore() : int { $score = 0; @@ -225,6 +232,15 @@ class QAAnswer implements \JsonSerializable 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) { @@ -236,18 +252,6 @@ class QAAnswer implements \JsonSerializable return 0; } - /** - * Is the answer accepted - * - * @return bool - * - * @since 1.0.0 - */ - public function isAccepted() : bool - { - return $this->isAccepted; - } - /** * {@inheritdoc} */ diff --git a/Models/QAAnswerVoteMapper.php b/Models/QAAnswerVoteMapper.php index afcb965..3c0aeb7 100644 --- a/Models/QAAnswerVoteMapper.php +++ b/Models/QAAnswerVoteMapper.php @@ -78,12 +78,22 @@ final class QAAnswerVoteMapper extends DataMapperAbstract */ protected static string $primaryField = 'qa_answer_vote_id'; - public static function findVote(int $question, int $account) + /** + * Find vote for answer from user + * + * @param int $answer Answer id + * @param int $account Account id + * + * @return QAAnswerVote + * + * @since 1.0.0 + */ + public static function findVote(int $answer, int $account) : QAAnswerVote { $depth = 3; $query = self::getQuery(); - $query->where(self::$table . '_' . $depth . '.qa_answer_vote_created_by', '=', $account) - ->andWhere(self::$table . '_' . $depth . '.qa_answer_vote_answer', '=', $question); + $query->where(self::$table . '_d' . $depth . '.qa_answer_vote_created_by', '=', $account) + ->andWhere(self::$table . '_d' . $depth . '.qa_answer_vote_answer', '=', $answer); $results = self::getAllByQuery($query); diff --git a/Models/QAQuestion.php b/Models/QAQuestion.php index 5a4b62a..bc0539f 100755 --- a/Models/QAQuestion.php +++ b/Models/QAQuestion.php @@ -267,6 +267,8 @@ class QAQuestion implements \JsonSerializable * @return array * * @since 1.0.0 + * + * @since 1.0.0 */ public function getTags() : array { @@ -277,8 +279,10 @@ class QAQuestion implements \JsonSerializable * Add tag to question * * @param int|Tag $tag Tag + * + * @since 1.0.0 */ - public function addTag($tag) : void + public function addTag(int|Tag $tag) : void { $this->tags[] = $tag; } @@ -287,17 +291,33 @@ class QAQuestion implements \JsonSerializable * Set tags to question * * @param array $tags Tags + * + * @since 1.0.0 */ public function setTags(array $tags) : void { $this->tags = $tags; } + /** + * Count the answers + * + * @return int + * + * @since 1.0.0 + */ public function getAnswerCount() : int { return \count($this->answers); } + /** + * Get the total vote score + * + * @return int + * + * @since 1.0.0 + */ public function getVoteScore() : int { $score = 0; @@ -308,6 +328,15 @@ class QAQuestion implements \JsonSerializable 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) { diff --git a/Models/QAQuestionVoteMapper.php b/Models/QAQuestionVoteMapper.php index 0e61014..8a84abe 100644 --- a/Models/QAQuestionVoteMapper.php +++ b/Models/QAQuestionVoteMapper.php @@ -78,12 +78,22 @@ final class QAQuestionVoteMapper extends DataMapperAbstract */ protected static string $primaryField = 'qa_question_vote_id'; - public static function findVote(int $question, int $account) + /** + * Find vote for question from user + * + * @param int $question Question id + * @param int $account Account id + * + * @return QAQuestionVote + * + * @since 1.0.0 + */ + public static function findVote(int $question, int $account) : QAQuestionVote { $depth = 3; $query = self::getQuery(); - $query->where(self::$table . '_' . $depth . '.qa_question_vote_created_by', '=', $account) - ->andWhere(self::$table . '_' . $depth . '.qa_question_vote_question', '=', $question); + $query->where(self::$table . '_d' . $depth . '.qa_question_vote_created_by', '=', $account) + ->andWhere(self::$table . '_d' . $depth . '.qa_question_vote_question', '=', $question); $results = self::getAllByQuery($query); diff --git a/composer.json b/composer.json index 8f2fb6d..7ad134b 100755 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ ], "require-dev": { "phpunit/phpunit": ">=9.4", - "friendsofphp/php-cs-fixer": ">=2.18", + "friendsofphp/php-cs-fixer": ">=3.0", "squizlabs/php_codesniffer": ">=3.5", "phpmd/phpmd": ">=2.9", "phpstan/phpstan": ">=0.12.58",