shield_project_ids=ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id)
shield_project_ids=ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id)
shield_course_ids=ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id)
shield_course_ids=ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id)
watched_user_blog_ids=Blog.select("id").where("author_id in #{user_ids}").count==0?"":Blog.select("id").where("author_id in #{user_ids}").map{|blog|blog.id}.join(",")
watched_user_blog_ids=Blog.select("id").where("author_id in #{user_ids}").count==0?"":Blog.select("id").where("author_id in #{user_ids}").map{|blog|blog.id}.join(",")
blog_ids="("+watched_user_blog_ids+")"
ifcontainer_type=="Course"
activities=UserActivity.where("(container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})").order('updated_at desc')
elsifcontainer_type=="Project"
activities=UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})").order('updated_at desc')
else
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')
ifcontainer_type=="Course"
activities=UserActivity.where("(container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})").order('updated_at desc')
elsifcontainer_type=="Project"
activities=UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})").order('updated_at desc')
else
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')
ifCourseMessage.where("course_message_type = 'JoinCourseRequest' and user_id = #{course.tea_id} and content = '#{role_str}' and course_message_id = #{current_user.id} and course_id = #{course.id} and status = 0").count!=0
syllabuses=Syllabus.where("id in #{syllabus_ids} or user_id = #{user.id}").order("updated_at desc")
syllabuses.eachdo|syllabus|
syllabus.courses=courses.where("syllabus_id = #{syllabus.id}").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("time desc")
tmp_courses=courses.where("syllabus_id = #{syllabus.id}").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc")