2016-01-19 23:11:52 -05:00
|
|
|
# ViewModel used on Summary tab on User page
|
|
|
|
|
|
|
|
class UserSummary
|
|
|
|
|
2016-03-30 12:05:16 -04:00
|
|
|
MAX_BADGES = 6
|
2016-01-19 23:11:52 -05:00
|
|
|
MAX_TOPICS = 6
|
|
|
|
|
|
|
|
alias :read_attribute_for_serialization :send
|
|
|
|
|
|
|
|
def initialize(user, guardian)
|
|
|
|
@user = user
|
|
|
|
@guardian = guardian
|
|
|
|
end
|
|
|
|
|
|
|
|
def topics
|
|
|
|
Topic
|
|
|
|
.secured(@guardian)
|
|
|
|
.listable_topics
|
2016-01-27 19:12:12 -05:00
|
|
|
.visible
|
2016-01-19 23:11:52 -05:00
|
|
|
.where(user: @user)
|
2016-03-30 12:05:16 -04:00
|
|
|
.order('like_count DESC, created_at ASC')
|
2016-01-19 23:11:52 -05:00
|
|
|
.includes(:user, :category)
|
|
|
|
.limit(MAX_TOPICS)
|
|
|
|
end
|
|
|
|
|
|
|
|
def replies
|
|
|
|
Post
|
|
|
|
.secured(@guardian)
|
2016-03-30 12:05:16 -04:00
|
|
|
.includes(:user, topic: :category)
|
2016-01-27 19:12:12 -05:00
|
|
|
.references(:topic)
|
|
|
|
.merge(Topic.listable_topics.visible.secured(@guardian))
|
2016-01-19 23:11:52 -05:00
|
|
|
.where(user: @user)
|
|
|
|
.where('post_number > 1')
|
|
|
|
.where('topics.archetype <> ?', Archetype.private_message)
|
2016-03-30 12:05:16 -04:00
|
|
|
.order('posts.like_count DESC, posts.created_at ASC')
|
2016-01-19 23:11:52 -05:00
|
|
|
.limit(MAX_TOPICS)
|
|
|
|
end
|
|
|
|
|
|
|
|
def badges
|
2016-03-30 12:05:16 -04:00
|
|
|
@user.featured_user_badges(MAX_BADGES)
|
2016-01-19 23:11:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def user_stat
|
|
|
|
@user.user_stat
|
|
|
|
end
|
|
|
|
|
2016-03-30 12:05:16 -04:00
|
|
|
delegate :likes_given,
|
|
|
|
:likes_received,
|
|
|
|
:days_visited,
|
|
|
|
:posts_read_count,
|
|
|
|
:topic_count,
|
|
|
|
:post_count,
|
|
|
|
:time_read,
|
2016-01-19 23:11:52 -05:00
|
|
|
to: :user_stat
|
|
|
|
|
|
|
|
end
|