Skip to content

Commit c34d5fe

Browse files
authored
Merge pull request #113 from VSEphpbb/voters
Tweak access to new get users votes function
2 parents 4b0b116 + d7cfa0d commit c34d5fe

1 file changed

Lines changed: 27 additions & 27 deletions

File tree

factory/ideas.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,33 @@ public function get_voters($id)
578578
return $rows;
579579
}
580580

581+
/**
582+
* Get a user's votes from a group of ideas
583+
*
584+
* @param int $user_id The user's id
585+
* @param array $ids An array of idea ids
586+
* @return array An array of ideas the user voted on and their vote result, or empty otherwise.
587+
* example: [idea_id => vote_result]
588+
* 1 => 1, idea 1, voted up by the user
589+
* 2 => 0, idea 2, voted down by the user
590+
*/
591+
public function get_users_votes($user_id, array $ids)
592+
{
593+
$results = [];
594+
$sql = 'SELECT idea_id, vote_value
595+
FROM ' . $this->table_votes . '
596+
WHERE user_id = ' . (int) $user_id . '
597+
AND ' . $this->db->sql_in_set('idea_id', $ids, false, true);
598+
$result = $this->db->sql_query($sql);
599+
while ($row = $this->db->sql_fetchrow($result))
600+
{
601+
$results[$row['idea_id']] = $row['vote_value'];
602+
}
603+
$this->db->sql_freeresult($result);
604+
605+
return $results;
606+
}
607+
581608
/**
582609
* Submits a new idea.
583610
*
@@ -829,31 +856,4 @@ protected function profile_url()
829856

830857
return $this->profile_url;
831858
}
832-
833-
/**
834-
* Get a user's votes from a group of ideas
835-
*
836-
* @param int $user_id The user's id
837-
* @param array $ids An array of idea ids
838-
* @return array An array of ideas the user voted on and their vote result, or empty otherwise.
839-
* example: [idea_id => vote_result]
840-
* 1 => 1, idea 1, voted up by the user
841-
* 2 => 0, idea 2, voted down by the user
842-
*/
843-
protected function get_users_votes($user_id, $ids = [])
844-
{
845-
$results = [];
846-
$sql = 'SELECT idea_id, vote_value
847-
FROM ' . $this->table_votes . '
848-
WHERE user_id = ' . (int) $user_id . '
849-
AND ' . $this->db->sql_in_set('idea_id', $ids, false, true);
850-
$result = $this->db->sql_query($sql);
851-
while ($row = $this->db->sql_fetchrow($result))
852-
{
853-
$results[$row['idea_id']] = $row['vote_value'];
854-
}
855-
$this->db->sql_freeresult($result);
856-
857-
return $results;
858-
}
859859
}

0 commit comments

Comments
 (0)