select('qa_question_created_by') ->selectAs('SUM(qa_question_vote_score)', 'score') ->from(QAQuestionVoteMapper::getTable()) ->leftJoin(QAQuestionMapper::getTable()) ->on(QAQuestionVoteMapper::getTable() . '.qa_question_vote_question', '=', QAQuestionMapper::getTable() . '.qa_question_id') ->where(QAQuestionMapper::getTable() . '.qa_question_created_by', 'in', $accounts) ->groupBy('qa_question_created_by') ->execute() ->fetchAll(); foreach ($questionScore as $votes) { $scores[(int) $votes['qa_question_created_by']] = (int) $votes['score']; } $query = new Builder(self::$db); $answerScore = $query->select('qa_answer_created_by') ->selectAs('SUM(qa_answer_vote_score)', 'score') ->from(QAAnswerVoteMapper::getTable()) ->leftJoin(QAAnswerMapper::getTable()) ->on(QAAnswerVoteMapper::getTable() . '.qa_answer_vote_answer', '=', QAAnswerMapper::getTable() . '.qa_answer_id') ->where(QAAnswerMapper::getTable() . '.qa_answer_created_by', 'in', $accounts) ->groupBy('qa_answer_created_by') ->execute() ->fetchAll(); foreach ($answerScore as $votes) { $scores[(int) $votes['qa_answer_created_by']] ??= 0; $scores[(int) $votes['qa_answer_created_by']] += (int) $votes['score']; } return $scores; } }