diff --git a/app/controllers/event_news_controller.rb b/app/controllers/event_news_controller.rb index 8a9f0bc..cca58e9 100644 --- a/app/controllers/event_news_controller.rb +++ b/app/controllers/event_news_controller.rb @@ -12,8 +12,7 @@ class EventNewsController < ApplicationController } end locale = OrbitHelper.get_site_locale.to_s - files = a.event_news_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } if file.enabled_for?(locale) } rescue [] - files.delete(nil) + files = a.event_news_files.to_fronted(locale) links = a.event_news_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] author = User.find(a.create_user_id).member_profile.name rescue "" desc = a.image_description @@ -126,61 +125,10 @@ class EventNewsController < ApplicationController "extras" => {} } end - def get_tabs_option - subpart = OrbitHelper.get_current_widget - tab_options = ["not_enable_tabs","enable_tabs_with_categories_include_all","enable_tabs_with_categories"] - read_more_options = ['default','upper_left','lower_left','upper_right','lower_right'] - all_setting_options = ['the_same_as_data_count','display_all_in_other_tabs'] - @tab_option = 0 - @read_more_option = 0 - @all_setting_option = 0 - if subpart.methods.include? 'select_options'.to_sym - ModuleApp.all.select{|tmp| tmp.key.to_s=='event_news'}.each do |modile_app| - @show_options = modile_app.show_options rescue nil - end - subpart.select_options.each do |select_option| - if !(@show_options.nil?) && select_option.field_name == @show_options.keys[1].to_s - value = YAML.load(select_option.value) - tmp = value[:en] - I18n.with_locale(:en) do - tab_options.each_with_index do |option,i| - if tmp == t("event_news.#{option}") - @tab_option = i - break - end - end - end - end - if !(@show_options.nil?) && select_option.field_name == @show_options.keys[2].to_s - value = YAML.load(select_option.value) - tmp = value[:en] - I18n.with_locale(:en) do - read_more_options.each_with_index do |option,i| - if tmp == t("announcement.#{option}") - @read_more_option = i - break - end - end - end - end - if !(@show_options.nil?) && select_option.field_name == @show_options.keys[3].to_s - value = YAML.load(select_option.value) - tmp = value[:en] - I18n.with_locale(:en) do - all_setting_options.each_with_index do |option,i| - if tmp == t("announcement.#{option}") - @all_setting_option = i - break - end - end - end - end - end - end - end def pack_data(is_random=false) cats = OrbitHelper.widget_categories || [] tags = OrbitHelper.widget_tags || [] + tags = ['all'] if tags.blank? subpart = OrbitHelper.get_current_widget get_tabs_option event_news = [] @@ -190,11 +138,11 @@ class EventNewsController < ApplicationController else if cats.count != 1 || tags == ["all"] cats.each do |cat| - event_news = event_news + get_event_news_for_pack_data([cat],tags,'') + event_news = event_news + get_event_news_for_pack_data([cat],tags,'',is_random) end else tags.each do |tag| - event_news = event_news + get_event_news_for_pack_data(cats,[tag],tag) + event_news = event_news + get_event_news_for_pack_data(cats,[tag],tag,is_random) end use_tag = true end @@ -207,7 +155,7 @@ class EventNewsController < ApplicationController else cats = ["all"] + cats end - event_news = event_news.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]} + event_news = event_news.sort_by { |a| tmp=a["event_date"].blank?;[tmp ? 0 : 1, tmp ? nil : a["event_date"].to_time] }.reverse end cats = cats.uniq tags = tags.uniq @@ -233,8 +181,16 @@ class EventNewsController < ApplicationController end [cat_id,t] }.to_h - page = Page.where(:page_id=> subpart.read_more_page_id).first rescue nil - page = Page.where(:module => "event_news").first rescue nil if page.nil? + home_page = Page.first + page = nil + locale = I18n.locale.to_s + if home_page.respond_to?(:find_page) + page = home_page.find_page(:page_id=> subpart.read_more_page_id,:enabled_for=>locale).first rescue nil + page = home_page.find_page(:module=>"event_news",:enabled_for=>locale).first rescue nil if page.nil? + else + page = Page.where(:page_id=> subpart.read_more_page_id,:enabled_for=>locale).first rescue nil + page = Page.where(:module=>"event_news",:enabled_for=>locale).first rescue nil if page.nil? + end all_cats = cats.dup all_cats.delete "all" if all_cats.count == 0 @@ -251,7 +207,7 @@ class EventNewsController < ApplicationController "
" + "