From e6ddb3cec040c4feee785c42d5292ce0de73c9ea Mon Sep 17 00:00:00 2001 From: cxt Date: Wed, 7 Sep 2016 11:30:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=BB=E9=A1=B5=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E8=BF=87=E6=BB=A4=E4=B8=AD=E7=82=B9=E5=87=BB=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E5=8A=A8=E6=80=81=E8=A6=81=E6=98=BE=E7=A4=BA=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E7=94=A8=E6=88=B7=E5=85=B3=E8=81=94=E7=9A=84=E6=89=80?= =?UTF-8?q?=E6=9C=89=E5=8A=A8=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 71 +++++------------------------ app/views/users/show.html.erb | 6 +-- 2 files changed, 14 insertions(+), 63 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5aab1df49..18090c400 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1691,9 +1691,12 @@ class UsersController < ApplicationController when "current_user" container_type = 'Principal' act_type = 'Principal' + when "all" + container_type = 'all' + act_type = 'all' end end - if container_type != '' && act_type != '' + if container_type != '' && container_type != 'all' if container_type == 'Course' sql = "container_type = '#{container_type}' and container_id in #{user_course_ids} and act_type = '#{act_type}'" elsif container_type == 'Project' @@ -1709,69 +1712,19 @@ class UsersController < ApplicationController else if User.current != @user blog_ids = "("+@user.blog.id.to_s+")" - sql = "user_id = #{@user.id} and((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ - "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + - "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids}))" else blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" - sql = "(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ - "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + - "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})" + end + sql = "(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})" + if container_type != 'all' && User.current != @user + sql = "user_id = #{@user.id} and(" + sql + ")" end end + @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) - # if params[:type].present? - # case params[:type] - # when "course_homework" - # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'HomeworkCommon'").order('updated_at desc').limit(10).offset(@page * 10) - # when "course_news" - # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'News'").order('updated_at desc').limit(10).offset(@page * 10) - # when "course_message" - # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) - # when "course_poll" - # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Poll'").order('updated_at desc').limit(10).offset(@page * 10) - # when "course_journals" - # @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'JournalsForMessage'").order('updated_at desc').limit(10).offset(@page * 10) - # when "project_issue" - # @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('updated_at desc').limit(10).offset(@page * 10) - # when "project_message" - # @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) - # when "user_journals" - # @user_activities = UserActivity.where("container_type = 'Principal' and act_type= 'JournalsForMessage' and container_id = #{@user.id}").order('updated_at desc').limit(10).offset(@page * 10) - # when "current_user" - # @user_activities = UserActivity.where("user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))").order('updated_at desc').limit(10).offset(@page * 10) - # else - # if @user == User.current - # blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" - # else - # blog_ids = "("+@user.blog.id.to_s+")" - # end - # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - # "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ - # "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + - # "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) - # end - # else - # # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) - # # blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" - # # 减少数据库交互 - # if @user == User.current - # watched_user_ids = User.watched_by(@user.id).count == 0 ? " " : ("," + User.watched_by(@user.id).map{|u| u.id.to_s }.join(',')) - # user_ids = "(" + @user.id.to_s + watched_user_ids + ")" - # else - # user_ids = "(" + @user.id.to_s + ")" - # end - # watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}") - # blog_ids = watched_user_blog_ids.empty? ? "(-1)" : "(" + watched_user_blog_ids.map { |blog| blog.id}.join(",") + ")" - # - # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - # "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ - # "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + - # "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) - # end - # @user_activities = paginateHelper @user_activities,500 @type = params[:type] respond_to do |format| format.js diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 5ae593ddf..e920af7bf 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -34,10 +34,8 @@