2020-02-01 03:47:52 +00:00
|
|
|
module AnnouncementsHelper
|
2020-03-01 07:49:01 +00:00
|
|
|
def set_image_version_for_widget
|
|
|
|
subpart = OrbitHelper.get_current_widget
|
|
|
|
@image_version = 'thumb'
|
|
|
|
if subpart.methods.include? 'select_options'.to_sym
|
|
|
|
ModuleApp.all.select{|tmp| tmp.key.to_s=='announcement'}.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.first.to_s
|
|
|
|
value = YAML.load(select_option.value)
|
|
|
|
if value[I18n.locale] == t('announcement.small_size')
|
|
|
|
@image_version = 'thumb'
|
|
|
|
elsif value[I18n.locale] == t('announcement.medium_size')
|
|
|
|
@image_version = 'mobile'
|
|
|
|
elsif value[I18n.locale] == t('announcement.orignal_size')
|
|
|
|
@image_version = 'orignal'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def data_to_human_type(a)
|
|
|
|
statuses = a.statuses_with_classname.collect do |status|
|
|
|
|
{
|
|
|
|
"status" => status["name"],
|
|
|
|
"status-class" => "status-#{status['classname']}"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
files = a.bulletin_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)
|
|
|
|
links = a.bulletin_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
|
|
|
|
desc = (desc.nil? || desc == "" ? "announcement image" : desc)
|
2020-03-27 02:18:00 +00:00
|
|
|
link_to_show = a.is_external_link? ? a.external_link : OrbitHelper.widget_item_url(a.to_param)
|
2020-03-01 07:49:01 +00:00
|
|
|
target = a.is_external_link ? "_blank" : "_self"
|
|
|
|
if @image_version == 'thumb'
|
|
|
|
image_url = a.image.thumb.url
|
|
|
|
elsif @image_version == 'mobile'
|
|
|
|
image_url = a.image.mobile.url
|
|
|
|
else
|
|
|
|
image_url = a.image.url
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"bulletin_links" => links,
|
|
|
|
"bulletin_files" => files,
|
|
|
|
"title" => a.title,
|
|
|
|
"source-site" => "",
|
|
|
|
"source-site-title" => "",
|
|
|
|
"source-site-link" => "",
|
|
|
|
"subtitle" => a.subtitle,
|
|
|
|
"statuses" => statuses,
|
|
|
|
"category" => a.category.title,
|
|
|
|
"postdate" => a.postdate,
|
|
|
|
"author" => author,
|
|
|
|
"link_to_show" => link_to_show,
|
|
|
|
"target" => target,
|
|
|
|
"img_src" => image_url || "/assets/announcement-default.jpg",
|
|
|
|
"img_description" => desc
|
|
|
|
}
|
|
|
|
end
|
2020-04-05 14:38:26 +00:00
|
|
|
def get_feed_annc(type,site_source,locale)
|
|
|
|
ma_key = 'announcement'
|
|
|
|
if type == "index"
|
|
|
|
categories = Array(OrbitHelper.widget_categories)
|
|
|
|
elsif type == "widget"
|
|
|
|
categories = Array(OrbitHelper.widget_categories)
|
|
|
|
else
|
|
|
|
categories = []
|
|
|
|
end
|
|
|
|
if categories.include?("all")
|
|
|
|
feeds = SiteFeedAnnc.where(:channel_key => ma_key)
|
|
|
|
else
|
|
|
|
feeds = SiteFeedAnnc.where(:channel_key => ma_key, :merge_with_category.in => categories)
|
|
|
|
end
|
|
|
|
if feeds.count > 0
|
|
|
|
temp_ids = []
|
|
|
|
data = feeds.collect do |feed|
|
|
|
|
feed.all_contents_for_feed(site_source,locale)
|
|
|
|
end.flatten.compact
|
|
|
|
else
|
|
|
|
data = []
|
|
|
|
end
|
|
|
|
data
|
|
|
|
end
|
2020-02-01 03:47:52 +00:00
|
|
|
def get_feed_announcements(type,site_source=nil)
|
|
|
|
locale = OrbitHelper.get_site_locale.to_s
|
2020-04-05 14:38:26 +00:00
|
|
|
if !(defined? SiteFeedAnnc).nil?
|
|
|
|
fans = get_feed_annc(type,site_source,locale)
|
|
|
|
else
|
|
|
|
feed_anns = OrbitHelper.get_feed_for_module(type)
|
|
|
|
fans = []
|
|
|
|
feed_anns.each do |fa|
|
|
|
|
next if !site_source.nil? && site_source != fa["source-site-title"]
|
|
|
|
status = {
|
|
|
|
"status" => "<a href='#{fa["source-site"]}' target='_blank' class='feed-source'>#{fa["source-site-title"]}</a>",
|
|
|
|
"status-class" => "status-source"
|
|
|
|
}
|
2020-02-01 03:47:52 +00:00
|
|
|
|
2020-04-05 14:38:26 +00:00
|
|
|
files = fa["bulletin_files"].collect{|bf| { "file_url" => bf["url"], "file_title" => (fa["title_translations"][locale].blank? ? File.basename(fa["url"]) : fa["title_translations"][locale] rescue '') }} rescue []
|
|
|
|
links = fa["bulletin_links"].map{|link| { "link_url" => link["url"], "link_title" => (link["title_translations"][locale].blank? ? link["url"] : link["title_translations"][locale]) } } rescue []
|
2020-02-01 03:47:52 +00:00
|
|
|
|
2020-04-05 14:38:26 +00:00
|
|
|
x = {
|
|
|
|
"bulletin_links" => links,
|
|
|
|
"bulletin_files" => files,
|
|
|
|
"title" => fa["title_translations"][locale],
|
|
|
|
"subtitle" => fa["subtitle_translations"][locale],
|
|
|
|
"statuses" => [status],
|
|
|
|
"category" => fa["category"],
|
|
|
|
"postdate" => fa["postdate"],
|
|
|
|
"author" => fa["author"],
|
|
|
|
"source-site" => "<a href='#{fa["source-site"]}' target='_blank' class='feed-source'>#{fa["source-site-title"]}</a>",
|
|
|
|
"source-site-title" => fa["source-site-title"],
|
|
|
|
"source-site-link" => fa["source-site"],
|
|
|
|
"link_to_show" => OrbitHelper.url_to_show(fa["params"]),
|
|
|
|
"target" => "_self",
|
|
|
|
"img_src" => fa["image"]["thumb"] || "/assets/announcement-default.jpg",
|
|
|
|
"img_description" => fa["image_description_translations"][locale],
|
|
|
|
"more" => t(:more_plus),
|
|
|
|
"view_count" => ""
|
|
|
|
}
|
|
|
|
if (!x["title"].empty? rescue false)
|
|
|
|
fans << x
|
|
|
|
end
|
2020-02-01 03:47:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
fans
|
|
|
|
end
|
2020-03-02 10:09:55 +00:00
|
|
|
def filter_by_keywords(sorted,keywords)
|
2020-03-17 01:26:34 +00:00
|
|
|
if !keywords.to_s.empty?
|
2020-03-02 10:09:55 +00:00
|
|
|
sorted.select{|anns|
|
|
|
|
if anns["source-site"].present?
|
|
|
|
title = Nokogiri::HTML(anns["title"].to_s).text
|
|
|
|
else
|
|
|
|
title = Nokogiri::HTML(anns.title.to_s).text
|
|
|
|
end
|
|
|
|
title.include?(keywords.to_s)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sorted
|
|
|
|
end
|
2020-02-01 03:47:52 +00:00
|
|
|
end
|
|
|
|
def get_sorted_annc
|
|
|
|
params = OrbitHelper.params
|
|
|
|
locale = OrbitHelper.get_site_locale.to_s
|
|
|
|
page = Page.where(url:params['url']).first
|
2020-03-01 07:49:01 +00:00
|
|
|
page_number = OrbitHelper.page_number.to_i
|
|
|
|
page_number = 1 if page_number == 0
|
|
|
|
page_data_count = OrbitHelper.page_data_count.to_i
|
2020-02-01 03:47:52 +00:00
|
|
|
feeds_anns = []
|
|
|
|
tags = page.tags
|
2020-03-01 07:49:01 +00:00
|
|
|
categories = params['category']=='all' ? (page.categories || []) : ([Category.find(params['category'])] rescue (page.categories || []))
|
|
|
|
if !params["source"].present?
|
|
|
|
announcements = Bulletin.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
|
2020-03-17 02:32:51 +00:00
|
|
|
if !(defined? SiteFeed).nil?
|
2020-02-01 03:47:52 +00:00
|
|
|
feeds_anns = get_feed_announcements("index")
|
|
|
|
end
|
2020-03-01 07:49:01 +00:00
|
|
|
else
|
|
|
|
announcements = []
|
|
|
|
feeds_anns = get_feed_announcements("index",params["source"])
|
2020-02-01 03:47:52 +00:00
|
|
|
end
|
|
|
|
if !feeds_anns.blank?
|
2020-03-01 07:49:01 +00:00
|
|
|
if announcements.count != 0
|
2020-04-05 14:38:26 +00:00
|
|
|
top_anns = announcements.select{|v| v.is_top} + feeds_anns.select{|v| v['is_top']}
|
|
|
|
rest_all_anns = feeds_anns.select{|v| v['is_top'] != true} + announcements.select{|v| !v.is_top}
|
2020-03-17 01:26:34 +00:00
|
|
|
rest_anns = rest_all_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]}
|
2020-04-05 14:38:26 +00:00
|
|
|
all_sorted = top_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]} + rest_anns
|
2020-03-01 07:49:01 +00:00
|
|
|
else
|
2020-04-05 14:38:26 +00:00
|
|
|
all_sorted = feeds_anns.sort{|v1,v2| [v2['is_top'],v2["postdate"]]<=>[v1['is_top'],v1["postdate"]]}
|
2020-02-01 03:47:52 +00:00
|
|
|
end
|
2020-03-02 10:09:55 +00:00
|
|
|
all_filter = filter_by_keywords(all_sorted,params[:keywords])
|
2020-02-01 03:47:52 +00:00
|
|
|
else
|
2020-03-02 10:09:55 +00:00
|
|
|
all_filter = filter_by_keywords(announcements,params[:keywords])
|
2020-02-01 03:47:52 +00:00
|
|
|
end
|
2020-03-01 07:49:01 +00:00
|
|
|
if page_data_count != 0
|
|
|
|
sorted = all_filter[(page_number-1)*page_data_count...page_number*page_data_count]
|
|
|
|
else
|
|
|
|
sorted = all_filter
|
2020-02-28 04:18:43 +00:00
|
|
|
end
|
2020-03-01 07:49:01 +00:00
|
|
|
annc_count = all_filter.count
|
|
|
|
total_pages = page_data_count == 0 ? 1 : (annc_count.to_f / page_data_count).ceil
|
|
|
|
[sorted,total_pages]
|
2020-02-01 03:47:52 +00:00
|
|
|
end
|
|
|
|
end
|