forked from saurabh/orbit4-5
added some stuff for feeds and utility
This commit is contained in:
parent
f7c377d092
commit
59a198005d
|
@ -20,6 +20,7 @@
|
|||
app/views/frontend
|
||||
/public/uploads/*
|
||||
public/assets/*
|
||||
public/site_feeds/*
|
||||
public/import_status.yml
|
||||
public/announcement_link_widget_en.json
|
||||
public/announcement_link_widget_zh_tw.json
|
||||
|
|
|
@ -381,6 +381,72 @@ module OrbitHelper
|
|||
ActionView::Base.full_sanitizer.sanitize(string)
|
||||
end
|
||||
|
||||
# get feeds for the module
|
||||
|
||||
def self.get_feed_for_module(type)
|
||||
categories = []
|
||||
ma = nil
|
||||
if type == "index"
|
||||
categories = @categories if !@categories.nil?
|
||||
ma = @module_app
|
||||
elsif type == "widget"
|
||||
categories = @widget_categories if !@widget_categories.nil?
|
||||
ma = @widget_module_app
|
||||
end
|
||||
if categories.first == "all"
|
||||
feeds = SiteFeed.where(:channel_key => ma.key).enabled
|
||||
else
|
||||
feeds = SiteFeed.where(:channel_key => ma.key, :merge_with_category.in => categories).enabled
|
||||
end
|
||||
data = []
|
||||
if feeds.count > 0
|
||||
temp_ids = []
|
||||
feeds.each do |feed|
|
||||
file = File.join(Rails.root,"public","site_feeds",feed.id.to_s,feed.feed_uid.to_s + ".json")
|
||||
if File.exists?(file)
|
||||
d = File.read(file)
|
||||
d = JSON.parse(d)
|
||||
cat = Category.find(feed.merge_with_category).title
|
||||
final_d = []
|
||||
d[ma.key.pluralize].each{|a|
|
||||
a["category"] = cat
|
||||
if !temp_ids.include?(a["id"])
|
||||
temp_ids << a["id"]
|
||||
a["params"] = a["params"] + "_" + feed.id.to_s + "h"
|
||||
final_d << a
|
||||
end
|
||||
}
|
||||
data.concat(final_d)
|
||||
end
|
||||
end
|
||||
end
|
||||
data
|
||||
end
|
||||
|
||||
def self.is_object_from_feed?(uid)
|
||||
return uid.ends_with?("h")
|
||||
end
|
||||
|
||||
def self.get_from_feed(uidwithid)
|
||||
temp = uidwithid.split("_")
|
||||
feed_id = temp[1][0...-1]
|
||||
uid = temp[0]
|
||||
object = nil
|
||||
feed = SiteFeed.find(feed_id) rescue nil
|
||||
if !feed.nil?
|
||||
file = File.join(Rails.root,"public","site_feeds",feed.id.to_s,feed.feed_uid.to_s + ".json")
|
||||
if File.exists?(file)
|
||||
d = File.read(file)
|
||||
d = JSON.parse(d)
|
||||
objects = d[@module_app.key.pluralize]
|
||||
object = objects.select{|obj| obj["id"] == uid}.first
|
||||
cat = Category.find(feed.merge_with_category)
|
||||
object = {} if cat.disable
|
||||
end
|
||||
end
|
||||
object
|
||||
end
|
||||
|
||||
# ===============================================================
|
||||
# Breadcrumbs
|
||||
# ===============================================================
|
||||
|
|
Loading…
Reference in New Issue