diff --git a/app/helpers/admin/新文字文件.txt b/app/helpers/admin/新文字文件.txt new file mode 100644 index 0000000..ccde8f0 --- /dev/null +++ b/app/helpers/admin/新文字文件.txt @@ -0,0 +1,33 @@ +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" => category, + "topics" => topics_data + } + end + end + papers_data + end +end \ No newline at end of file diff --git a/lib/tasks/e_paper_tasks.rake b/lib/tasks/e_paper_tasks.rake index 46527b6..d408351 100644 --- a/lib/tasks/e_paper_tasks.rake +++ b/lib/tasks/e_paper_tasks.rake @@ -10,7 +10,7 @@ namespace :epaper do emails = [] mail_limit = 25 subscribers.each do |subscriber| - emails << subscriber.email if paper.language_to_send.include? subscriber.language + emails << subscriber.email if paper.language_to_send.include?(subscriber.language) && !subscriber.email.blank? subscriber.last_paper_sent = paper.id.to_s subscriber.save if emails.count == mail_limit