访问他人的主页只显示他本人的动态
This commit is contained in:
parent
f78595bbbb
commit
ded6753ce1
|
@ -1660,55 +1660,117 @@ class UsersController < ApplicationController
|
|||
course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')"
|
||||
project_types = "('Message','Issue','Project')"
|
||||
principal_types = "JournalsForMessage"
|
||||
container_type = ''
|
||||
act_type = ''
|
||||
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)
|
||||
container_type = 'Course'
|
||||
act_type = 'HomeworkCommon'
|
||||
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)
|
||||
container_type = 'Course'
|
||||
act_type = 'News'
|
||||
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)
|
||||
container_type = 'Course'
|
||||
act_type = 'Message'
|
||||
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)
|
||||
container_type = 'Course'
|
||||
act_type = 'Poll'
|
||||
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)
|
||||
container_type = 'Course'
|
||||
act_type = 'JournalsForMessage'
|
||||
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)
|
||||
container_type = 'Project'
|
||||
act_type = 'Issue'
|
||||
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)
|
||||
container_type = 'Course'
|
||||
act_type = 'Message'
|
||||
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)
|
||||
container_type = 'Principal'
|
||||
act_type = 'JournalsForMessage'
|
||||
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)
|
||||
container_type = 'Principal'
|
||||
act_type = 'Principal'
|
||||
end
|
||||
end
|
||||
if container_type != '' && act_type != ''
|
||||
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'
|
||||
sql = "container_type = '#{container_type}' and container_id in #{user_project_ids} and act_type = '#{act_type}'"
|
||||
elsif container_type == 'Principal' && act_type == 'JournalsForMessage'
|
||||
sql = "container_type = '#{container_type}' and act_type= '#{act_type}' and container_id = #{@user.id}"
|
||||
elsif container_type == 'Principal' && act_type == 'Principal'
|
||||
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}))"
|
||||
end
|
||||
if User.current != @user
|
||||
sql += "and user_id = #{@user.id}"
|
||||
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 + ")"
|
||||
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
|
||||
user_ids = "(" + @user.id.to_s + ")"
|
||||
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
|
||||
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 = 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|
|
||||
|
|
|
@ -36,7 +36,9 @@
|
|||
<ul class="homepagePostTypeProject fl">
|
||||
<li class="f14">更多</li>
|
||||
<li class="mt-4"><%= link_to "个人留言", {:controller => "users", :action => "show", :type => "user_journals"}, :class =>"homepagePostTypeMessage postTypeGrey"%>
|
||||
<li class="mt-4"><%= link_to @user == User.current ? "我的动态" : "他的动态", {:controller => "users", :action => "show", :type => "current_user"}, :class =>"homepagePostTypeMine postTypeGrey"%>
|
||||
<% if @user == User.current %>
|
||||
<li class="mt-4"><%= link_to "我的动态", {:controller => "users", :action => "show", :type => "current_user"}, :class =>"homepagePostTypeMine postTypeGrey"%>
|
||||
<% end %>
|
||||
<li class="mt-4"><%= link_to "全部动态", {:controller => "users", :action => "show", :type => nil}, :class =>"homepagePostTypeAll postTypeGrey"%>
|
||||
</ul>
|
||||
</li>
|
||||
|
|
Loading…
Reference in New Issue