55 lines
1.8 KiB
Ruby
55 lines
1.8 KiB
Ruby
class BreadcrumbWidgetsController < ApplicationController
|
|
def widget
|
|
params = OrbitHelper.request.params
|
|
url = params["url"]
|
|
crumbs = url.split("/")
|
|
data = []
|
|
uid = nil
|
|
if params[:page].class == String && params[:page].include?("-")
|
|
uid = params[:page].split("-").last
|
|
end
|
|
crumbs.each_with_index do |crumb,i|
|
|
if crumb == ""
|
|
p = Page.root
|
|
data << {"page_name" => p.name.gsub(/<br>|<BR>/,''), "url" => "/?locale=#{locale.to_s}"}
|
|
else
|
|
p = Page.where(:page_id => crumb).first
|
|
page_name = p.name.gsub(/<br>|<BR>/,'') rescue ""
|
|
if i == crumbs.count - 1
|
|
override_page_name = nil
|
|
if uid.present? && p.module.present?
|
|
module_app = ModuleApp.find_by_key(p.module) rescue nil
|
|
registration_module = OrbitApp::Module::Registration.find_by_key(p.module) rescue nil
|
|
taggable_model = registration_module.taggable_model.constantize rescue nil
|
|
if module_app && registration_module
|
|
model = taggable_model.where(:uid=>uid).first rescue nil
|
|
if model
|
|
if (model.category.present? rescue false)
|
|
override_page_name = model.category.title rescue nil
|
|
end
|
|
if (model.tags.present? && model.tags.count == 1 rescue false)
|
|
override_page_name = model.tags.first.name rescue nil
|
|
end
|
|
end
|
|
end
|
|
else
|
|
if params[:category].present?
|
|
override_page_name = Category.find(Array(params[:category]).first).title rescue nil
|
|
end
|
|
if params[:tags].present?
|
|
override_page_name = Tag.find(Array(params['tags']).first).name rescue nil
|
|
end
|
|
end
|
|
if override_page_name.present?
|
|
page_name = override_page_name
|
|
end
|
|
end
|
|
data << {"page_name" => page_name, "url" => "/#{locale.to_s}" + p.url}
|
|
end
|
|
end
|
|
{
|
|
"crumbs" => data
|
|
}
|
|
|
|
end
|
|
end |