checkAnswer($id); $question = $this->checkQuestion($answer->question_id); $user = $this->getLoginUser(); $validator = new AnswerValidator(); $validator->checkOwner($user->id, $answer->owner_id); $validator->checkIfAllowDelete($answer); $answer->deleted = 1; $answer->update(); $this->recountQuestionAnswers($question); $this->recountUserAnswers($user); $this->eventsManager->fire('Answer:afterDelete', $this, $answer); return $answer; } protected function recountQuestionAnswers(QuestionModel $question) { $questionRepo = new QuestionRepo(); $answerCount = $questionRepo->countAnswers($question->id); $question->answer_count = $answerCount; $question->update(); } protected function recountUserAnswers(UserModel $user) { $userRepo = new UserRepo(); $answerCount = $userRepo->countAnswers($user->id); $user->answer_count = $answerCount; $user->update(); } }