@@ -214,11 +214,15 @@ public function get_ideas($number = 10, $sort = 'date', $sort_direction = 'DESC'
214214 return $ row ['topic_id ' ];
215215 }, $ rows );
216216
217+ $ idea_ids = array_column ($ rows , 'idea_id ' );
218+
217219 $ topic_tracking_info = get_complete_topic_tracking ((int ) $ this ->config ['ideas_forum_id ' ], $ topic_ids );
220+ $ user_voting_info = $ this ->get_users_votes ($ this ->user ->id , $ idea_ids );
218221
219222 foreach ($ rows as &$ row )
220223 {
221224 $ row ['read ' ] = !(isset ($ topic_tracking_info [$ row ['topic_id ' ]]) && $ row ['topic_last_post_time ' ] > $ topic_tracking_info [$ row ['topic_id ' ]]);
225+ $ row ['u_voted ' ] = isset ($ user_voting_info [$ row ['idea_id ' ]]) ? (string ) $ user_voting_info [$ row ['idea_id ' ]] : '' ;
222226 }
223227 }
224228
@@ -827,4 +831,30 @@ protected function profile_url()
827831
828832 return $ this ->profile_url ;
829833 }
834+
835+ /**
836+ * Get the ideas a user voted on from a group of ideas
837+ *
838+ * @param int $user_id The user's id
839+ * @param array $ids An array of idea identifiers
840+ * @return array An array of ideas the user voted on with their vote result, or empty otherwise.
841+ * example: [idea_id => vote_result]
842+ * [1 => 1, 2 => 0] Voted up idea 1, voted down idea 2
843+ */
844+ protected function get_users_votes ($ user_id , $ ids = [])
845+ {
846+ $ results = [];
847+ $ sql = 'SELECT idea_id, vote_value
848+ FROM ' . $ this ->table_votes . '
849+ WHERE user_id = ' . (int ) $ user_id . '
850+ AND ' . $ this ->db ->sql_in_set ('idea_id ' , $ ids , false , true );
851+ $ result = $ this ->db ->sql_query ($ sql );
852+ while ($ row = $ this ->db ->sql_fetchrow ($ result ))
853+ {
854+ $ results [$ row ['idea_id ' ]] = $ row ['vote_value ' ];
855+ }
856+ $ this ->db ->sql_freeresult ($ result );
857+
858+ return $ results ;
859+ }
830860}
0 commit comments