diff --git a/app/helpers/event_news_helper.rb b/app/helpers/event_news_helper.rb index c60195b..31496c0 100644 --- a/app/helpers/event_news_helper.rb +++ b/app/helpers/event_news_helper.rb @@ -218,22 +218,22 @@ module EventNewsHelper tags = ["all"] end - @enable_search_flag = false module_app = ModuleApp.where(key: 'event_news_mod').first + @enable_search_flag = false @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?) + 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') + if value == I18n.t('yes_') @enable_search_flag = true end - when @show_option_items.keys[2].to_s - if value == t('event_news.yes') + when @show_option_items.keys[3].to_s + if value == I18n.t('yes_') @show_today_data_first = true end end @@ -248,7 +248,7 @@ module EventNewsHelper @categories = categories.map{|v| cat_maps[v.to_s]}.compact end end - event_news = [] + event_news_list = [] if !params["source"].present? event_news = @show_today_data_first ? EventNews.can_display_and_sorted_according_today : @@ -264,7 +264,7 @@ module EventNewsHelper event_news = event_news.where(:create_user_id.in=>user_ids) end end - event_news = event_news.to_a + event_news_list = 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) @@ -280,17 +280,16 @@ module EventNewsHelper end end if !feeds_anns.blank? - if event_news.count != 0 - top_anns = event_news.select{|v| v.is_top} + feeds_anns.select{|v| v['is_top']} - rest_all_anns = feeds_anns.select{|v| v['is_top'] != true} + event_news.select{|v| !v.is_top} - rest_anns = rest_all_anns.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 0 : 1, tmp ? nil : a["postdate"].to_time] }.reverse - all_sorted = top_anns.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 0 : 1, tmp ? nil : a["postdate"].to_time] }.reverse + rest_anns + if event_news_list.count != 0 + top_anns = event_news_list.select{|v| v.is_top} + feeds_anns.select{|v| v['is_top']} + rest_all_anns = feeds_anns.select{|v| v['is_top'] != true} + event_news_list.select{|v| !v.is_top} + all_sorted = sort_event_news(top_anns) + sort_event_news(rest_all_anns) else - all_sorted = feeds_anns.select{|v| v['is_top']}.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 0 : 1, tmp ? nil : a["postdate"].to_time] }.reverse + feeds_anns.select{|v| v['is_top'] != true}.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 0 : 1, tmp ? nil : a["postdate"].to_time] }.reverse + all_sorted = sort_event_news(feeds_anns.select{|v| v['is_top']}) + sort_event_news(feeds_anns.select{|v| v['is_top'] != true}) end all_filter = filter_by_keywords(all_sorted,params[:keywords],params[:stime],params[:etime]) else - all_filter = filter_by_keywords(event_news,params[:keywords],params[:stime],params[:etime]) + all_filter = filter_by_keywords(event_news_list,params[:keywords],params[:stime],params[:etime]) end if page_data_count != 0 sorted = all_filter[(page_number-1)*page_data_count...page_number*page_data_count] @@ -301,6 +300,33 @@ module EventNewsHelper total_pages = page_data_count == 0 ? 1 : (annc_count.to_f / page_data_count).ceil [sorted,total_pages] end + + def sort_event_news(event_news_list) + if @show_today_data_first || !EventNewsHelper.is_postdate_sort_first + event_news_list = event_news_list.sort_by { |event_news| + tmp1 = event_news["event_date"].blank? + tmp2 = event_news["postdate"].blank? + [ + tmp1 ? 0 : 1, tmp1 ? nil : event_news["event_date"].to_time, + tmp2 ? 0 : 1, tmp2 ? nil : event_news["postdate"].to_time + ] + } + if !@show_today_data_first + event_news_list = event_news_list.reverse + end + else + event_news_list = event_news_list.sort_by { |event_news| + tmp1 = event_news["event_date"].blank? + tmp2 = event_news["postdate"].blank? + [ + tmp2 ? 0 : 1, tmp2 ? nil : event_news["postdate"].to_time, + tmp1 ? 0 : 1, tmp1 ? nil : event_news["event_date"].to_time + ] + }.reverse + end + return event_news_list + end + def render_view_for_event_news(overridehtml=nil) @key = Site.first.template def render_link_to_edit(html, url_to_edit)