create_course_messages=@course.course_messages.where("user_id =? and course_message_type =? and course_id =? and viewed =?",User.current.id,'Course',@course.id,0)
create_course_messages=@course.course_messages.where("user_id =? and course_message_type =? and course_id =? and viewed =?",User.current.id,'Course',@course.id,0)
project__messages=ForgeMessage.where("forge_message_type in ('ProjectInvite', 'JoinProject', 'RemoveFromProject') and user_id =? and project_id =? ",user,project)
messages=MessageAll.where("(user_id =? and message_type !=?) or message_type =?",@user,"SystemMessage","SystemMessage").order("created_at desc")
messages=MessageAll.where("(user_id =? and message_type !=?) or message_type =?",@user.id,"SystemMessage","SystemMessage").includes(:message).order("created_at desc")
@message_alls=CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork','Exercise') and user_id =?",@user).order("created_at desc")
@message_alls=CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork','Exercise') and user_id =?",@user.id).order("created_at desc")
when'course_message'
when'course_message'
@message_alls=CourseMessage.where("course_message_type =? and user_id =?","Message",@user).order("created_at desc")
@message_alls=CourseMessage.where("course_message_type =? and user_id =?","Message",@user.id).order("created_at desc")
when'course_news'
when'course_news'
# 课程通知包含发布的通知和回复的通知
# 课程通知包含发布的通知和回复的通知
@message_alls=CourseMessage.where("course_message_type in (?, ? ,?)","News","Comment","Course").where("user_id =?",@user).order("created_at desc")
@message_alls=CourseMessage.where("course_message_type in ('News', 'Comment') and user_id =?",@user.id).order("created_at desc")
when'poll'
when'poll'
@message_alls=CourseMessage.where("course_message_type =? and user_id =?","Poll",@user).order("created_at desc")
@message_alls=CourseMessage.where("course_message_type =? and user_id =?","Poll",@user.id).order("created_at desc")
#项目相关消息
#项目相关消息
when'issue'
when'issue'
@message_alls=ForgeMessage.where("forge_message_type =? or forge_message_type =?","Issue","Journal").where("user_id=?",@user).order("created_at desc")
@message_alls=ForgeMessage.where("forge_message_type in ('Issue', 'Journal') and user_id =?",@user.id).order("created_at desc")
when'forge_message'
when'forge_message'
@message_alls=ForgeMessage.where("forge_message_type =? and user_id =?","Message",@user).order("created_at desc")
@message_alls=ForgeMessage.where("forge_message_type =? and user_id =?","Message",@user.id).order("created_at desc")
when'forge_news'
when'forge_news'
@message_alls=ForgeMessage.where("forge_message_type in (?,?) and user_id =?","News","Comment",@user).order("created_at desc")
@message_alls=ForgeMessage.where("forge_message_type in (?,?) and user_id =?","News","Comment",@user.id).order("created_at desc")
when'apply'
when'apply'
@message_alls=ForgeMessage.where("forge_message_type in ('ProjectInvite', 'AppliedProject', 'JoinProject', 'RemoveFromProject') and user_id =?",@user).order("created_at desc")
@message_alls=ForgeMessage.where("forge_message_type in ('ProjectInvite', 'AppliedProject', 'JoinProject', 'RemoveFromProject') and user_id =?",@user.id).order("created_at desc")
#贴吧消息
#贴吧消息
when'forum'
when'forum'
@message_alls=MemoMessage.where("memo_type =? and user_id =?","Memo",@user).order("created_at desc")
@message_alls=MemoMessage.where("memo_type =? and user_id =?","Memo",@user.id).order("created_at desc")
#用户留言
#用户留言
when'user_feedback'
when'user_feedback'
@message_alls=UserFeedbackMessage.where("journals_for_message_type =? and user_id =?","JournalsForMessage",@user).order("created_at desc")
@message_alls=UserFeedbackMessage.where("journals_for_message_type =? and user_id =?","JournalsForMessage",@user.id).order("created_at desc")
else
else
render_404
render_404
return
return
@ -1209,9 +1206,7 @@ class UsersController < ApplicationController
join_course_messages=CourseMessage.where("course_id =? and course_message_type =? and user_id =? and course_message_id =? and viewed =?",
join_course_messages=CourseMessage.where("course_id =? and course_message_type =? and user_id =? and course_message_id =? and viewed =?",
@ -1253,7 +1248,12 @@ class UsersController < ApplicationController
end
end
else
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)
# @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)
# sql = "SELECT distinct c.* FROM `courses` c, tags t, taggings ts where t.id = ts.tag_id and ts.taggable_id = c.id and c.is_excellent = 1 and is_delete = 0 and
# ts.taggable_type = 'Course' and t.name like '%#{keywords}%'"
course_count=CourseMessage.where("user_id =? and viewed =? and created_at >?",User.current.id,0,User.current.onclick_time.onclick_time).count
user=User.current
forge_count=ForgeMessage.where("user_id =? and viewed =? and created_at >?",User.current.id,0,User.current.onclick_time.onclick_time).count
onclick_time=user.onclick_time.onclick_time
user_feedback_count=UserFeedbackMessage.where("user_id =? and viewed =? and created_at >?",User.current.id,0,User.current.onclick_time.onclick_time).count
course_count=CourseMessage.where("user_id =? and viewed =? and created_at >?",user.id,0,onclick_time).count
user_memo_count=MemoMessage.where("user_id =? and viewed =? and created_at >?",User.current.id,0,User.current.onclick_time.onclick_time).count
forge_count=ForgeMessage.where("user_id =? and viewed =? and created_at >?",user.id,0,onclick_time).count
<% courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5) %>
<% course_order_ids = "(" +
CourseActivity.find_by_sql("SELECT c.course_id, updated_at FROM
(SELECT ca.course_id, MAX(ca.updated_at) AS updated_at FROM course_activities ca WHERE ca.course_id IN (" + @user.courses.visible.select('courses.id').map{|c| c.id}.join(',') + ")
GROUP BY ca.course_id) AS c
ORDER BY c.updated_at DESC limit 5").map {|c| c.course_id}.join(",") + ")"%>
<% courses = Course.where("id in #{course_order_ids}")%>
<%# courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5) %>
<% projects = @user.projects.visible.select("projects.*,(SELECT MAX(created_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5)%>
<% project_order_ids = "(" +
ForgeActivity.find_by_sql("SELECT p.project_id, p.created_at FROM
(SELECT fa.project_id, MAX(fa.created_at) AS created_at FROM forge_activities fa WHERE fa.project_id IN (" + @user.projects.visible.select('projects.id').map{|p| p.id}.join(',') + ")
GROUP BY fa.project_id) AS p
ORDER BY p.created_at DESC limit 5").map {|p| p.project_id}.join(",") + ")"%>
<% projects = Project.where("projects.id in #{project_order_ids}")%>
<%# projects = @user.projects.visible.select("projects.*, (SELECT MAX(created_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5)%>