diff --git a/app/helpers/event_news_helper.rb b/app/helpers/event_news_helper.rb index 5f4ef83..c60195b 100644 --- a/app/helpers/event_news_helper.rb +++ b/app/helpers/event_news_helper.rb @@ -204,37 +204,67 @@ module EventNewsHelper page_number = 1 if page_number == 0 page_data_count = data_count || OrbitHelper.page_data_count.to_i feeds_anns = [] - page = OrbitHelper.page rescue nil - page = Page.where(url:params['url']).first if page.nil? if @type == "show_widget" tags = @tags categories = @categories else + page = OrbitHelper.page rescue nil + page = Page.where(url:params['url']).first if page.nil? + tags = page.tags tags = params[:tags] if params[:tags].present? categories = params['category']=='all' ? (page.categories || []) : (Array(params['category']) rescue (page.categories || [])) if params['category'].present? && tags.blank? tags = ["all"] end - end - if !params["source"].present? - if @type == "show_widget" - if params[:uids].blank? - event_news = EventNews.where(:title.nin => ["",nil],:is_preview.in=>[false,nil]) - .can_display_and_sorted.is_approved - .filter_by_categories(categories,false).filter_by_tags(tags).to_a - else - member_prfile = MemberProfile.any_in(:uid=>params[:uids]) - user_ids = member_prfile.map{|m| m.user.id rescue nil}.select{|id| !id.nil?} - event_news = EventNews.where(:title.nin => ["",nil],:is_preview.in=>[false,nil],:create_user_id.in=>user_ids) - .can_display_and_sorted.is_approved - .filter_by_categories(categories,false).filter_by_tags(tags).to_a + + @enable_search_flag = false + module_app = ModuleApp.where(key: 'event_news_mod').first + @show_option_items = nil + @show_today_data_first = false + if module_app && page.respond_to?(:select_option_items) + @show_option_items = module_app.show_option_items + if !(@show_option_items.nil?) + page.select_option_items.each do |select_option_item| + value = YAML.load(select_option_item.value)[I18n.locale] + case select_option_item.field_name + when @show_option_items.keys[1].to_s + if value == t('event_news.yes') + @enable_search_flag = true + end + when @show_option_items.keys[2].to_s + if value == t('event_news.yes') + @show_today_data_first = true + end + end + end end - else - event_news = EventNews.where(:title.nin => ["",nil],:is_preview.in=>[false,nil]) - .can_display_and_sorted.is_approved - .filter_by_categories(categories,false).filter_by_tags(tags).to_a end + + if categories.include? 'all' + @categories = module_app.categories + else + cat_maps = Category.where(:id.in => categories).collect{|cat| [cat.id.to_s, cat]}.to_h + @categories = categories.map{|v| cat_maps[v.to_s]}.compact + end + end + event_news = [] + if !params["source"].present? + event_news = @show_today_data_first ? + EventNews.can_display_and_sorted_according_today : + EventNews.can_display_and_sorted + + event_news = event_news + .where(:title.nin => ["",nil]) + .filter_by_categories(categories,false).filter_by_tags(tags) + if @type == "show_widget" + if !params[:uids].blank? + member_profile = MemberProfile.any_in(:uid=>params[:uids]) + user_ids = member_profile.map{|m| m.user.id rescue nil}.select{|id| !id.nil?} + event_news = event_news.where(:create_user_id.in=>user_ids) + end + end + event_news = event_news.to_a if !(defined? SiteFeed).nil? if @type != "show_widget" feeds_anns = get_feed_event_news("index",nil,nil,page_number*page_data_count) @@ -243,7 +273,6 @@ module EventNewsHelper end end else - event_news = [] if @type != "show_widget" feeds_anns = get_feed_event_news("index",params["source"],nil,page_number*page_data_count) else diff --git a/app/models/event_news.rb b/app/models/event_news.rb index 9d3081f..66b30bc 100644 --- a/app/models/event_news.rb +++ b/app/models/event_news.rb @@ -107,7 +107,7 @@ class EventNews scope :open_in_future, ->{where(:is_hidden.ne=>true,:is_preview.ne => true,:postdate.gt=>Time.now).order(postdate: :asc)} scope :can_display_and_sorted, ->{ - where(:is_hidden.ne=>true,:is_preview.ne => true) + is_approved_and_show .valid_time_range .order( EventNewsHelper.is_postdate_sort_first ? @@ -116,7 +116,7 @@ class EventNews ) } scope :can_display_and_sorted_according_today, ->{ - where(:is_hidden.ne=>true,:is_preview.ne => true) + is_approved_and_show .order(event_date: :asc).valid_time_range.order({postdate: :asc, id: :asc}).where(:event_date.gte => Date.today.to_time) } scope :valid_time_range, ->{ diff --git a/app/views/event_news_mods/index.html.erb b/app/views/event_news_mods/index.html.erb index 504f432..4926b1d 100644 --- a/app/views/event_news_mods/index.html.erb +++ b/app/views/event_news_mods/index.html.erb @@ -1,21 +1,7 @@ -<% params = OrbitHelper.params - page = Page.where(url:params['url']).first - enable_search_flag = false - if page.respond_to?(:select_option_items) - ModuleApp.all.select{|tmp| tmp.key.to_s=='event_news_mod'}.each do |modile_app| - @show_option_items = modile_app.show_option_items rescue nil - end - page.select_option_items.each do |select_option_item| - if !(@show_option_items.nil?) && select_option_item.field_name == @show_option_items.keys[1].to_s - value = YAML.load(select_option_item.value) - if value[I18n.locale] == t('event_news.yes') - enable_search_flag = true - end - end - end - end +<% + params = OrbitHelper.params %> -<% if enable_search_flag %> +<% if @enable_search_flag %>