diff --git a/app/models/bulletin_feed.rb b/app/models/bulletin_feed.rb index afc3806..3e4fe8c 100644 --- a/app/models/bulletin_feed.rb +++ b/app/models/bulletin_feed.rb @@ -85,7 +85,7 @@ class BulletinFeed end anns_before_filter.selector = {"$and"=>[anns_before_filter.selector,{"$or"=>(I18n.available_locales.map{|v| {"title.#{v}"=>{"$nin"=>["", nil]}}})}]} if can_display_and_sorted_flag - announcements = anns_before_filter.valid_time_range + announcements = anns_before_filter.valid_time_range.to_a end else announcements = [] @@ -99,7 +99,20 @@ class BulletinFeed first_postdate = anns_before_filter.open_in_future.limit(1).pluck(:postdate)[0] first_deadline = nil - + cat_ids = announcements.collect{|a| a.category_id.blank? ? nil : a.category_id.to_s}.compact.uniq + tag_ids = announcements.collect{|a| a.tag_ids.collect{|v| v.blank? ? nil : v.to_s}}.flatten.compact.uniq + basic_query = {:module => 'announcement',:enabled_for=>I18n.locale} + if !cat_ids.blank? + query = basic_query.merge({:categories.all => cat_ids}) + else + query = basic_query.clone + end + if !tag_ids.blank? + query = query.merge({:tags.all => tag_ids}) + end + page = Page.where(query).first || Page.where(basic_query).first + more_url = page ? "/#{I18n.locale}#{(page.get_url)}" : nil + announcements.each_with_index do |anns,i| deadline = anns.deadline if !deadline.blank? @@ -114,6 +127,11 @@ class BulletinFeed author = "" end a = {} + if more_url + a['show_url'] = "#{more_url}/#{anns.to_param}" + else + a['show_url'] = '#' + end a["id"] = anns.uid a["title_translations"] = anns.title_translations a["subtitle_translations"] = anns.subtitle_translations