/**
* @return array
* @param return_limit int [optional]
* @desc Returns the top rated topics viewable by the current user, limit of $return_limit
*/
function top_rated_topics($return_limit = '10', $forum_id = '-1')
{
    global $db, $board_config;
    $auth_topic_list = auth_rated_topics();
    if ($forum_id == -1) {
        $sql = "SELECT\tAVG(rating) AS average, COUNT(rating) AS rating_number, MIN(rating) AS min, MAX(rating) AS max, topic_id\n\t\t   FROM " . RATINGS_TABLE . "\n\t\t   WHERE topic_id IN ({$auth_topic_list})\n\t\t   GROUP BY topic_id DESC\n\t\t   HAVING rating_number >= " . $board_config['min_rates_number'] . "\n\t\t   ORDER BY average DESC\n\t\t   LIMIT {$return_limit}";
    } else {
        $sql = "SELECT\tAVG(r.rating) AS average, COUNT(r.rating) AS rating_number, MIN(r.rating) AS min, MAX(r.rating) AS max, r.topic_id\n\t\t   FROM " . RATINGS_TABLE . " r, " . TOPICS_TABLE . " t\n\t\t   WHERE r.topic_id IN ({$auth_topic_list})\n\t\t   AND r.topic_id = t.topic_id\n\t       AND t.forum_id = {$forum_id}\n\t\t   GROUP BY r.topic_id DESC\n\t\t   HAVING rating_number >= " . $board_config['min_rates_number'] . "\n\t\t   ORDER BY average DESC\n\t\t   LIMIT {$return_limit}";
    }
    if (!($result = $db->sql_query($sql))) {
        message_die(GENERAL_ERROR, $lang['Error_Dbase_Ratings'], $lang['Database_Error'], __LINE__, __FILE__, $sql);
    }
    $row = $db->sql_fetchrowset($result);
    return $row;
}
Example #2
0
/**
* @return array
* @param return_limit int [optional]
* @desc Returns the top rated topics viewable by the current user, limit of $return_limit
*/
function top_rated_topics($return_limit = 10, $forum_id = -1)
{
    global $db, $config;
    $auth_topic_list = auth_rated_topics();
    if ($forum_id == -1) {
        $sql = "SELECT AVG(rating) AS average, COUNT(rating) AS rating_number, MIN(rating) AS min, MAX(rating) AS max, topic_id\n\t\t\tFROM " . RATINGS_TABLE . "\n\t\t\tWHERE topic_id IN (" . $auth_topic_list . ")\n\t\t\tGROUP BY topic_id DESC\n\t\t\tHAVING rating_number >= " . $config['min_rates_number'] . "\n\t\t\tORDER BY average DESC\n\t\t\tLIMIT {$return_limit}";
    } else {
        $sql = "SELECT AVG(r.rating) AS average, COUNT(r.rating) AS rating_number, MIN(r.rating) AS min, MAX(r.rating) AS max, r.topic_id\n\t\t\tFROM " . RATINGS_TABLE . " r, " . TOPICS_TABLE . " t\n\t\t\tWHERE r.topic_id IN (" . $auth_topic_list . ")\n\t\t\tAND r.topic_id = t.topic_id\n\t\t\tAND t.forum_id = " . $forum_id . "\n\t\t\tGROUP BY r.topic_id DESC\n\t\t\tHAVING rating_number >= " . $config['min_rates_number'] . "\n\t\t\tORDER BY average DESC\n\t\t\tLIMIT {$return_limit}";
    }
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrowset($result);
    return $row;
}