33 lines
1.0 KiB
Ruby
Executable File
33 lines
1.0 KiB
Ruby
Executable File
module Admin::EpaperHelper
|
|
extend self
|
|
def get_all_categories
|
|
app = ModuleApp.where(key: 'e_paper').first
|
|
asc_flag = app.asc rescue true
|
|
app.categories.enabled.sort_by do |category|
|
|
tmp = category.sort_number.to_i rescue 0
|
|
asc_flag ? tmp : -tmp
|
|
end
|
|
end
|
|
def get_paper_data(paper_criteria)
|
|
papers = paper_criteria.epaper_topics.group_by(&:category)
|
|
papers_data = []
|
|
papers_sorted = get_all_categories.map do |v|
|
|
tmp = papers.select{|cat,topics| (cat.id==v.id rescue false)}
|
|
if tmp.count==0
|
|
tmp = nil
|
|
end
|
|
tmp
|
|
end.compact
|
|
papers_sorted.each do |paper|
|
|
paper.each do |category, topics|
|
|
topics_data = Array(topics).compact
|
|
papers_data << {
|
|
"category_title" => (category.title rescue nil),
|
|
"category_id" => category.id,
|
|
"topic_ids" => topics_data.map{|t| t.id}
|
|
}
|
|
end
|
|
end
|
|
papers_data
|
|
end
|
|
end |