From 683cd9f9189f5651f7d723986010cd2984502039 Mon Sep 17 00:00:00 2001 From: z9hang Date: Fri, 8 Aug 2014 13:47:02 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 1 + app/helpers/user_score_helper.rb | 70 ++++++++++++++++++---------- app/views/users/_user_score.html.erb | 3 +- 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index cba7784bc..eaa96e82a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -56,6 +56,7 @@ class UsersController < ApplicationController include WordsHelper include GitlabHelper include UserScoreHelper + helper :user_score # added by liuping 关注 diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index 8c00a6b23..dc43de32a 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -372,8 +372,8 @@ module UserScoreHelper result.post_issue = 0 result.total_score = 0 result.score_type =type - unless project_id.nil? - result.project_id = project_id + unless project.nil? + result.project_id = project.id end else result = option_number.first @@ -416,12 +416,26 @@ module UserScoreHelper def memo_num(user,project=nil) if project.nil? Message.includes(:author).joins(:board).where("#{Message.table_name}.parent_id IS NULL and #{Message.table_name}.author_id = '#{user.id}' and #{Board.table_name}.project_id != -1").all.count #+ Memo.includes(:author).where("parent_id IS NULL and author_id = '#{user.id}'").all.count + + #user.messages.where("parent_id IS NULL").count else Message.includes(:author).joins(:board).where("#{Message.table_name}.parent_id IS NULL and #{Message.table_name}.author_id = '#{user.id}' and #{Board.table_name}.project_id = #{project.id}").all.count end end + def memo_score(user,project=nil) + if project.nil? + User.find_by_sql("SELECT `users`.id,(SELECT COUNT(*) * 2 FROM `messages` JOIN `boards` ON boards.project_id != -1 AND messages.board_id = boards.id +WHERE messages.parent_id IS NULL AND messages.author_id = `users`.id) AS m_count +FROM `users` where id = #{user.id}") + else + User.find_by_sql("SELECT `users`.id,(SELECT COUNT(*) * 2 FROM `messages` JOIN `boards` ON boards.project_id = '#{project.id}' AND messages.board_id = boards.id +WHERE messages.parent_id IS NULL AND messages.author_id = `users`.id) AS m_count +FROM `users` where id = #{user.id}") + end + end + #更新对缺陷留言数 def update_messges_for_issue(user,type,project=nil) option_number = get_option_number(user,type) @@ -437,6 +451,14 @@ module UserScoreHelper end end + def messges_for_issue_score(user,project=nil) + if project.nil? + User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM journals WHERE journals.user_id = users.id AND journals.notes IS NOT NULL AND journals.notes != '') AS m_score FROM users where id = #{user.id}") + else + User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM journals join issues on #{Journal.table_name}.journalized_type = 'Issue' and #{Journal.table_name}.journalized_id = #{Issue.table_name}.id WHERE journals.user_id = users.id AND journals.notes IS NOT NULL AND journals.notes != ''and #{Issue.table_name}.project_id = '#{project.id}') AS m_score FROM users where id = #{user.id}") + end + end + #更新更改缺陷状态状态次数 def update_issues_status(user,type,project=nil) option_number = get_option_number(user,type) @@ -508,8 +530,8 @@ module UserScoreHelper def tread_num(user,project=nil) if project.nil? - result0 = PraiseTread.where("praise_tread_object_type = 'Issue' || praise_tread_object_type = 'Message' and praise_or_tread = 0 and user_id = '#{user.id}'").all.count - pts = PraiseTread.where("praise_tread_object_type = 'Issue' || praise_tread_object_type = 'Message' and praise_or_tread = 0").all + result0 = PraiseTread.where("praise_tread_object_type IN ( 'Issue','Message') and praise_or_tread = 0 and user_id = '#{user.id}'").all.count + pts = PraiseTread.where("praise_tread_object_type IN ( 'Issue','Message') and praise_or_tread = 0").all result = [] result1 = [] result2 = [] @@ -521,18 +543,18 @@ module UserScoreHelper target_user = obj.author level = UserLevels.get_level(pt.user)#pt.user.get_level project = pt.project - if level == 1 && target_user.id = user.id + if level == 1 && target_user.id == user.id result << pt - elsif level == 2 && target_user.id = user.id + elsif level == 2 && target_user.id == user.id result1 << pt - elsif level == 3 && target_user.id = user.id + elsif level == 3 && target_user.id == user.id result2 << pt end end - [:tread=>result0,:tead_by_one => result.count,:tread_by_two => result1.count,:tread_by_three =>result2.count] + {:tread=>result0,:tead_by_one => result.count,:tread_by_two => result1.count,:tread_by_three =>result2.count} else - result0 = PraiseTread.where("praise_tread_object_type = 'Issue' || praise_tread_object_type = 'Message' and praise_or_tread = 0 and user_id = '#{user.id}'").all.count - pts = PraiseTread.where("praise_tread_object_type = 'Issue' || praise_tread_object_type = 'Message' and praise_or_tread = 0").all + result0 = PraiseTread.where("praise_tread_object_type IN ( 'Issue','Message') and praise_or_tread = 0 and user_id = '#{user.id}'").all.count + pts = PraiseTread.where("praise_tread_object_type IN ( 'Issue','Message') and praise_or_tread = 0").all result = [] result1 = [] result2 = [] @@ -547,15 +569,15 @@ module UserScoreHelper target_user = obj.author level = UserLevels.get_level(pt.user)#pt.user.get_level project = pt.project - if level == 1 && target_user.id = user.id + if level == 1 && target_user.id == user.id result << pt - elsif level == 2 && target_user.id = user.id + elsif level == 2 && target_user.id == user.id result1 << pt - elsif level == 3 && target_user.id = user.id + elsif level == 3 && target_user.id == user.id result2 << pt end end - [:tread=>result0,:tead_by_one => result.count,:tread_by_two => result1.count,:tread_by_three =>result2.count] + {:tread=>result0,:tead_by_one => result.count,:tread_by_two => result1.count,:tread_by_three =>result2.count} end end @@ -572,7 +594,7 @@ module UserScoreHelper def praise_num(user,project=nil) if !project.nil? - pts = PraiseTread.where("praise_tread_object_type = 'Issue' || praise_tread_object_type = 'Message' and praise_or_tread = 1").all + pts = PraiseTread.where("praise_tread_object_type IN ( 'Issue','Message') and praise_or_tread = 1").all result = [] result1 = [] result2 = [] @@ -587,17 +609,17 @@ module UserScoreHelper target_user = obj.author level = UserLevels.get_level(pt.user)#pt.user.get_level project = pt.project - if level == 1 && target_user.id = user.id + if level == 1 && target_user.id == user.id result << pt - elsif level == 2 && target_user.id = user.id + elsif level == 2 && target_user.id == user.id result1 << pt - elsif level == 3 && target_user.id = user.id + elsif level == 3 && target_user.id == user.id result2 << pt end end - [:praise_by_one => result.count,:praise_by_two => result1.count,:praise_by_three => result2.count] + {:praise_by_one => result.count,:praise_by_two => result1.count,:praise_by_three => result2.count} else - pts = PraiseTread.where("praise_tread_object_type = 'Issue' || praise_tread_object_type = 'Message' and praise_or_tread = 1").all + pts = PraiseTread.where("praise_tread_object_type IN ( 'Issue','Message') and praise_or_tread = 1").all result = [] result1 = [] result2 = [] @@ -612,15 +634,15 @@ module UserScoreHelper target_user = obj.author level = UserLevels.get_level(pt.user)#pt.user.get_level project = pt.project - if level == 1 && target_user.id = user.id + if level == 1 && target_user.id == user.id result << pt - elsif level == 2 && target_user.id = user.id + elsif level == 2 && target_user.id == user.id result1 << pt - elsif level == 3 && target_user.id = user.id + elsif level == 3 && target_user.id == user.id result2 << pt end end - [:praise_by_one => result.count,:praise_by_two => result1.count,:praise_by_three => result2.count] + {:praise_by_one => result.count,:praise_by_two => result1.count,:praise_by_three => result2.count} end end diff --git a/app/views/users/_user_score.html.erb b/app/views/users/_user_score.html.erb index 53f05a2dd..338d72ada 100644 --- a/app/views/users/_user_score.html.erb +++ b/app/views/users/_user_score.html.erb @@ -1,5 +1,6 @@ <%= l(:label_user_grade)%>: -<%= link_to(format("%.2f" , user.user_score_attr.total_score).to_i, {:controller => 'users', + +<%= link_to(format("%.2f" ,user_scores(user,1).total_score ).to_i, {:controller => 'users', :action => 'show_new_score', :remote => true, :id => user.id From f8c6b661198cef6604ed016d834a519223f697e0 Mon Sep 17 00:00:00 2001 From: z9hang Date: Fri, 8 Aug 2014 15:09:32 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E5=A4=84=E5=AF=BC=E8=88=AA=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/my_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index a87df4fef..d55afbb31 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -16,6 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class MyController < ApplicationController + layout "users_base" before_filter :require_login helper :issues From dd64f13e497002bdd4a7032640cb5b5c75e546a6 Mon Sep 17 00:00:00 2001 From: chenmin <19763783@qq.com> Date: Fri, 8 Aug 2014 15:37:26 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=A9=BA=E8=A1=8Cbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/welcome/course.html.erb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/welcome/course.html.erb b/app/views/welcome/course.html.erb index 9d5037107..d48f11774 100644 --- a/app/views/welcome/course.html.erb +++ b/app/views/welcome/course.html.erb @@ -101,7 +101,7 @@

<% end %> - <% find_all_new_hot_course(9, @school_id).map do |course| %> + <% find_all_new_hot_course(10, @school_id).map do |course| %>
  • /,"") %>>
    <%= image_tag(get_course_avatar(course), :class => "avatar-4") %> @@ -132,7 +132,7 @@
    <% else %> - <% if school_course.count < 9 %> + <% if school_course.count < 10 %> <%= link_to "更多>>", {:controller => 'courses', :action => 'index', :school_id => nil} %> @@ -181,7 +181,7 @@
  • <%end%> <% end; reset_cycle %> - <% if school_course.count < 9 %> + <% if school_course.count < 10 %>
  • @@ -189,7 +189,7 @@ 该学校开设课程较少,您可以查看其他学校课程

  • - <% find_all_new_hot_course(9 - school_course.count, @school_id).map do |course| %> + <% find_all_new_hot_course(10 - school_course.count, @school_id).map do |course| %>
  • /,"") %>>
    <%= image_tag(get_course_avatar(course), :class => "avatar-4") %> From 6037421c7ded5579ab56fc00ca6063c1c62ad050 Mon Sep 17 00:00:00 2001 From: chenmin <19763783@qq.com> Date: Fri, 8 Aug 2014 15:45:06 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E7=9A=84=E5=AD=A6=E6=A0=A1=E6=98=BE=E7=A4=BA?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/welcome/course.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/welcome/course.html.erb b/app/views/welcome/course.html.erb index d48f11774..7cab331b6 100644 --- a/app/views/welcome/course.html.erb +++ b/app/views/welcome/course.html.erb @@ -101,7 +101,7 @@

    <% end %> - <% find_all_new_hot_course(10, @school_id).map do |course| %> + <% find_all_new_hot_course(9, @school_id).map do |course| %>
  • /,"") %>>
    <%= image_tag(get_course_avatar(course), :class => "avatar-4") %>