From 224c0b686c5ee0ca32260c2aa4b32dc770738f9f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 8 Dec 2016 09:59:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E9=A6=96=E9=A1=B5=E7=9A=84?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E7=A4=BE=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 70 ++++++++++++++++++- app/helpers/application_helper.rb | 31 ++++++++ app/helpers/users_helper.rb | 33 --------- .../layouts/base_course_community.html.erb | 52 ++++++++++++-- .../layouts/base_project_community.html.erb | 29 +++++++- app/views/layouts/new_base_user.html.erb | 6 +- app/views/users/course_community.html.erb | 38 ++++++++++ 7 files changed, 217 insertions(+), 42 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0cc676c14..ee3aba32d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1919,6 +1919,74 @@ class UsersController < ApplicationController # 课程社区 def course_community + if params[:course_id] != nil + join_course_messages = CourseMessage.where("course_id =? and course_message_type =? and user_id =? and course_message_id =? and viewed =?", + params[:course_id], 'JoinCourseRequest', User.current.id, @user.id, false) + join_course_messages.update_all(:viewed => true) + end + shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id) + @page = params[:page] ? params[:page].to_i + 1 : 0 + user_course_ids = (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")" + course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')" + principal_types = "JournalsForMessage" + container_type = '' + act_type = '' + + if params[:type].present? + case params[:type] + when "course_homework" + container_type = 'Course' + act_type = 'HomeworkCommon' + when "course_news" + container_type = 'Course' + act_type = 'News' + when "course_message" + container_type = 'Course' + act_type = 'Message' + when "course_poll" + container_type = 'Course' + act_type = 'Poll' + when "course_journals" + container_type = 'Course' + act_type = 'JournalsForMessage' + when "user_journals" + container_type = 'Principal' + act_type = 'JournalsForMessage' + when "current_user" + container_type = 'Principal' + act_type = 'Principal' + when "all" + container_type = 'all' + act_type = 'all' + end + end + 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 == '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 = '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 + if User.current != @user + blog_ids = "("+@user.blog.id.to_s+")" + 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(','))+")" + end + sql = "(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_count = UserActivity.where("#{sql}").order('updated_at desc').count + @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) + @type = params[:type] respond_to do |format| format.js format.html {render :layout => 'base_course_community'} @@ -3580,7 +3648,7 @@ class UsersController < ApplicationController # @syllabus = paginateHelper @syllabus,@limit respond_to do |format| - format.html {render :layout => 'new_base_user'} + format.html {render :layout => 'base_course_community'} end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 75a0eb3f1..b8ce07d69 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2791,6 +2791,37 @@ module ApplicationHelper end technical_title end + # 用户项目总数 + def user_project_count + @my_projects = @user.projects.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS updatetime").order("updatetime DESC") + @my_project_total = @my_projects.count + end + + # 用户的课程总数 + def user_course_count + @my_course_count = @user.syllabuses.count + + sy_courses = @user.courses.visible.not_deleted + syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" + syllabus_members = SyllabusMember.where("user_id = #{@user.id}") + syllabus_member_ids = syllabus_members.empty? ? "(-1)" : "(" + syllabus_members.map{|syl_mem| syl_mem.syllabus_id}.join(',') + ")" + @join_syllabuses = Syllabus.where("(id in #{syllabus_ids} or id in #{syllabus_member_ids}) and user_id != #{@user.id}") + @my_joined_course_count = @join_syllabuses.count + + @user_course_total = @my_joined_course_count + @my_course_count + end + + # 用户发布的issue数 + def issues_author_is_self_count + @issues = Issue.where( :author_id => @user.id ) + @issues_author_is_self_count = @issues.count + end + + # 用户收到的issue数 + def issues_assigned_is_self_count + @issues = Issue.where( :assigned_to_id => @user.id ) + @issues_assigned_is_self_count = @issues.count + end def get_user_roll user technical_title = "" diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 42825c6ab..879a7bb3c 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -53,39 +53,6 @@ module UsersHelper end - - # 用户项目总数 - def user_project_count - @my_projects = @user.projects.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS updatetime").order("updatetime DESC") - @my_project_total = @my_projects.count - end - - # 用户的课程总数 - def user_course_count - @my_course_count = @user.syllabuses.count - - sy_courses = @user.courses.visible.not_deleted - syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" - syllabus_members = SyllabusMember.where("user_id = #{@user.id}") - syllabus_member_ids = syllabus_members.empty? ? "(-1)" : "(" + syllabus_members.map{|syl_mem| syl_mem.syllabus_id}.join(',') + ")" - @join_syllabuses = Syllabus.where("(id in #{syllabus_ids} or id in #{syllabus_member_ids}) and user_id != #{@user.id}") - @my_joined_course_count = @join_syllabuses.count - - @user_course_total = @my_joined_course_count + @my_course_count - end - - # 用户发布的issue数 - def issues_author_is_self_count - @issues = Issue.where( :author_id => @user.id ) - @issues_author_is_self_count = @issues.count - end - - # 用户收到的issue数 - def issues_assigned_is_self_count - @issues = Issue.where( :assigned_to_id => @user.id ) - @issues_assigned_is_self_count = @issues.count - end - def get_resource_type type case type when 'Course' diff --git a/app/views/layouts/base_course_community.html.erb b/app/views/layouts/base_course_community.html.erb index d571ffc82..c6bcc8925 100644 --- a/app/views/layouts/base_course_community.html.erb +++ b/app/views/layouts/base_course_community.html.erb @@ -44,10 +44,54 @@