From e2622d82a9157dfedca1866a41d0e9c9aa0873e9 Mon Sep 17 00:00:00 2001 From: Toks Date: Mon, 20 May 2013 09:38:05 -0400 Subject: [PATCH] add feedback count for #1323 --- app/models/user.rb | 16 ++++++++++++++-- app/presenters/user_presenter.rb | 6 +++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 71e3ba6f2..887547188 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -519,7 +519,7 @@ class User < ActiveRecord::Base options[:except] ||= [] options[:except] += hidden_attributes options[:methods] ||= [] - options[:methods] += [:wiki_page_version_count, :artist_version_count, :pool_version_count, :forum_post_count, :comment_count] + options[:methods] += [:wiki_page_version_count, :artist_version_count, :pool_version_count, :forum_post_count, :comment_count, :positive_feedback_count, :neutral_feedback_count, :negative_feedback_count] super(options) end @@ -529,7 +529,7 @@ class User < ActiveRecord::Base options[:except] ||= [] options[:except] += hidden_attributes options[:methods] ||= [] - options[:methods] += [:wiki_page_version_count, :artist_version_count, :pool_version_count, :forum_post_count, :comment_count] + options[:methods] += [:wiki_page_version_count, :artist_version_count, :pool_version_count, :forum_post_count, :comment_count, :positive_feedback_count, :neutral_feedback_count, :negative_feedback_count] super(options, &block) end @@ -563,6 +563,18 @@ class User < ActiveRecord::Base def comment_count Comment.for_creator(id).count end + + def positive_feedback_count + feedback.positive.count + end + + def neutral_feedback_count + feedback.neutral.count + end + + def negative_feedback_count + feedback.negative.count + end end module SearchMethods diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index 79faeb971..83fce11f9 100644 --- a/app/presenters/user_presenter.rb +++ b/app/presenters/user_presenter.rb @@ -128,9 +128,9 @@ class UserPresenter end def feedbacks(template) - positive = UserFeedback.for_user(user.id).positive.count - neutral = UserFeedback.for_user(user.id).neutral.count - negative = UserFeedback.for_user(user.id).negative.count + positive = user.positive_feedback_count + neutral = user.neutral_feedback_count + negative = user.negative_feedback_count template.link_to("positive:#{positive} neutral:#{neutral} negative:#{negative}", template.user_feedbacks_path(:search => {:user_id => user.id})) end