活跃度排序不一致

This commit is contained in:
yanxd 2014-07-28 12:17:58 +08:00
parent a39672dd14
commit bf9a992399
1 changed files with 19 additions and 22 deletions

View File

@ -263,9 +263,6 @@ class UsersController < ApplicationController
sort_init 'login', 'asc'
sort_update %w(login firstname lastname mail admin created_on last_login_on)
# Deprecation
@project_type = params[:project_type]
case params[:format]
when 'xml', 'json'
@offset, @limit = api_offset_and_limit({:limit => 15})
@ -274,16 +271,9 @@ class UsersController < ApplicationController
end
# retrieve all users
scope = UserStatus.visible
# if role has something, change scope.
case params[:role]
when 'teacher'
scope = UserStatus.teacher
when 'student'
scope = UserStatus.student
else
end
# 先内连一下statuses 保证排序之后数量一致
scope = User.visible.
joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id")
# unknow
scope = scope.in_group(params[:group_id]) if params[:group_id].present?
@ -295,25 +285,32 @@ class UsersController < ApplicationController
# users classify
case params[:user_sort_type]
when '0'
# 创建时间排序
@s_type = 0
@us_ordered = scope.
joins("LEFT JOIN users ON user_statuses.user_id = users.id").
reorder('users.created_on DESC')
@users = scope.reorder('users.created_on DESC')
when '1'
# 活跃度排序, 就是所谓的得分情况
@s_type = 1
@us_ordered = scope.reorder('user_statuses.grade DESC')
@users = scope.
joins("LEFT JOIN user_scores ON users.id = user_scores.user_id").
reorder('user_scores.active DESC')
when '2'
# 粉丝数排序
@s_type = 2
@us_ordered = scope.reorder('user_statuses.watchers_count DESC')
@users = scope.
#joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id").
reorder('user_statuses.watchers_count DESC')
else
# 默认活跃度排序
@s_type = 1
@us_ordered = scope.reorder('user_statuses.grade DESC')
@users = scope.
joins("LEFT JOIN user_scores ON users.id = user_scores.user_id").
reorder('user_scores.active DESC')
end
# limit and offset
@users_statuses = @us_ordered.offset(@user_pages.offset).limit(@user_pages.per_page)
# get users ActiveRecord
@users = @users_statuses.includes(:user).map(&:user)
@users = @users.limit(@user_pages.per_page).offset(@user_pages.offset)
@user_base_tag = params[:id] ? 'base_users':'users_base'
respond_to do |format|