From d7cfa0d48c105b835d9bf187e10627837e422d77 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 6 May 2020 14:59:33 -0700 Subject: [PATCH] Make get users votes public --- factory/ideas.php | 54 +++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/factory/ideas.php b/factory/ideas.php index d811d7c0..1801260d 100644 --- a/factory/ideas.php +++ b/factory/ideas.php @@ -578,6 +578,33 @@ public function get_voters($id) return $rows; } + /** + * Get a user's votes from a group of ideas + * + * @param int $user_id The user's id + * @param array $ids An array of idea ids + * @return array An array of ideas the user voted on and their vote result, or empty otherwise. + * example: [idea_id => vote_result] + * 1 => 1, idea 1, voted up by the user + * 2 => 0, idea 2, voted down by the user + */ + public function get_users_votes($user_id, array $ids) + { + $results = []; + $sql = 'SELECT idea_id, vote_value + FROM ' . $this->table_votes . ' + WHERE user_id = ' . (int) $user_id . ' + AND ' . $this->db->sql_in_set('idea_id', $ids, false, true); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $results[$row['idea_id']] = $row['vote_value']; + } + $this->db->sql_freeresult($result); + + return $results; + } + /** * Submits a new idea. * @@ -829,31 +856,4 @@ protected function profile_url() return $this->profile_url; } - - /** - * Get a user's votes from a group of ideas - * - * @param int $user_id The user's id - * @param array $ids An array of idea ids - * @return array An array of ideas the user voted on and their vote result, or empty otherwise. - * example: [idea_id => vote_result] - * 1 => 1, idea 1, voted up by the user - * 2 => 0, idea 2, voted down by the user - */ - protected function get_users_votes($user_id, $ids = []) - { - $results = []; - $sql = 'SELECT idea_id, vote_value - FROM ' . $this->table_votes . ' - WHERE user_id = ' . (int) $user_id . ' - AND ' . $this->db->sql_in_set('idea_id', $ids, false, true); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $results[$row['idea_id']] = $row['vote_value']; - } - $this->db->sql_freeresult($result); - - return $results; - } }