diff --git a/app/api/mobile/apis/activities.rb b/app/api/mobile/apis/activities.rb index 661925012..b4fb90ea7 100644 --- a/app/api/mobile/apis/activities.rb +++ b/app/api/mobile/apis/activities.rb @@ -10,30 +10,44 @@ module Mobile params do requires :page, type: Integer requires :token, type: String + requires :container_type, type: String end post do authenticate! user = current_user - 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) + container_type = params[:container_type] ? params[:container_type] : "All" + + if container_type == "All" || container_type == "Project" + shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id) + user_project_ids = (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).join(",") + ")" + project_types = "('Message','Issue','Project')" + end + + if container_type == "All" || container_type == "Course" + shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id) + user_course_ids = (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")" + course_types = "('Message','News','HomeworkCommon','Poll','Course')" + end + page = params[:page] ? params[:page] : 0 - user_project_ids = (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).join(",") + ")" - user_course_ids = (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")" - course_types = "('Message','News','HomeworkCommon','Poll','Course')" - project_types = "('Message','Issue','Project')" principal_types = "JournalsForMessage" 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 + ")" 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 + ")" - 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') - + if container_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') + elsif container_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') + end all_count = activities.count activities = activities.limit(10).offset(page * 10) count = activities.count @@ -42,6 +56,7 @@ module Mobile present :count, count present :page, page present :status, 0 + present :container_type, container_type end end end diff --git a/app/services/syllabuses_service.rb b/app/services/syllabuses_service.rb index 9b060697c..530c550ed 100644 --- a/app/services/syllabuses_service.rb +++ b/app/services/syllabuses_service.rb @@ -14,6 +14,10 @@ class SyllabusesService courses.each do |c| other.courses << c[:course] unless c[:course].syllabus end + + user.syllabuses.each do |syllabus| + syllabus.courses = syllabus.courses.not_deleted + end user.syllabuses.to_a << other end @@ -45,6 +49,7 @@ class SyllabusesService c.tea_id = user.id c.syllabus_id = sy.id c.update_default_value + c.is_public = 0 c.save! after_create_course(c, user) end diff --git a/public/assets/wechat/activities.html b/public/assets/wechat/activities.html index a51a0f5f0..037ef8277 100644 --- a/public/assets/wechat/activities.html +++ b/public/assets/wechat/activities.html @@ -6,14 +6,19 @@
发布者: | -{{discussion.user.realname}} | -
来 源: | -{{discussion.course_project_name}} | 班级问答区 | -