select('qa_question_vote_created_for') ->selectAs('SUM(qa_question_vote_score)', 'score') ->from(QAQuestionVoteMapper::TABLE) ->where(QAQuestionVoteMapper::TABLE . '.qa_question_vote_created_for', 'in', $accounts) ->groupBy('qa_question_vote_created_for') ->execute() ->fetchAll(); foreach ($questionScore as $votes) { $scores[(int) $votes['qa_question_vote_created_for']] = (int) $votes['score']; } $query = new Builder(self::$db); $answerScore = $query->select('qa_answer_vote_created_for') ->selectAs('SUM(qa_answer_vote_score)', 'score') ->from(QAAnswerVoteMapper::TABLE) ->where(QAAnswerVoteMapper::TABLE . '.qa_answer_vote_created_for', 'in', $accounts) ->groupBy('qa_answer_vote_created_for') ->execute() ->fetchAll(); foreach ($answerScore as $votes) { $scores[(int) $votes['qa_answer_vote_created_for']] ??= 0; $scores[(int) $votes['qa_answer_vote_created_for']] += (int) $votes['score']; } return $scores; } }