-
-
Save jjaffeux/1b80577f41281e1c979eeeefa83cc63c to your computer and use it in GitHub Desktop.
whispers_report.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.report_whispers(report) | |
report.data = [] | |
report.modes = [:table] | |
report.labels = [ | |
{ | |
type: :user, | |
properties: { | |
username: :username, | |
id: :user_id, | |
avatar: :user_avatar_template, | |
}, | |
title: I18n.t("reports.whispers.labels.editor") | |
}, | |
{ | |
type: :post, | |
properties: { | |
topic_id: :topic_id, | |
number: :post_number, | |
truncated_raw: :post_raw | |
}, | |
title: I18n.t("reports.whispers.labels.post") | |
} | |
] | |
query = Post | |
.joins(:user, :topic) | |
.where(post_type: Post.types[:whisper]) | |
.where('posts.created_at > ? AND posts.created_at <= ?', report.start_date, report.end_date) | |
.order("posts.created_at" => :desc) | |
.limit(report.limit) | |
query.find_each do |post| | |
report.data << { | |
topic_id: post.topic.id, | |
post_number: post.post_number, | |
post_raw: post.raw, | |
username: post.user.username_lower, | |
user_id: post.user.id, | |
user_avatar_template: User.avatar_template(post.user.username_lower, post.user.uploaded_avatar_id) | |
} | |
end | |
report | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment