breadcrumb-widget/app/controllers/breadcrumb_widgets_controll...

56 lines
1.9 KiB
Ruby
Raw Normal View History

2014-06-27 08:58:18 +00:00
class BreadcrumbWidgetsController < ApplicationController
def widget
2021-12-18 05:02:43 +00:00
params = OrbitHelper.params
2021-12-18 05:22:00 +00:00
org_params = OrbitHelper.request.query_parameters
2014-06-27 08:58:18 +00:00
url = params["url"]
crumbs = url.split("/")
data = []
2021-05-11 04:31:58 +00:00
uid = nil
if params[:page].class == String && params[:page].include?("-")
uid = params[:page].split("-").last
end
crumbs.each_with_index do |crumb,i|
2014-06-27 08:58:18 +00:00
if crumb == ""
p = Page.root
2020-11-19 07:12:34 +00:00
data << {"page_name" => p.name.gsub(/<br>|<BR>/,''), "url" => "/?locale=#{locale.to_s}"}
2014-06-27 08:58:18 +00:00
else
p = Page.where(:page_id => crumb).first
2021-05-11 04:31:58 +00:00
page_name = p.name.gsub(/<br>|<BR>/,'') rescue ""
if i == crumbs.count - 1
override_page_name = nil
2021-12-18 05:26:01 +00:00
if uid.present? && p.module.present? && p.module=='announcement'
2021-05-11 04:31:58 +00:00
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
2021-05-26 07:54:51 +00:00
model = taggable_model.where(:uid=>uid).first rescue nil
2021-05-11 04:31:58 +00:00
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
2021-12-18 05:22:00 +00:00
if org_params[:category].present?
override_page_name = Category.find(Array(org_params[:category]).first).title rescue nil
2021-05-11 04:31:58 +00:00
end
2021-12-18 05:22:00 +00:00
if org_params[:tags].present?
override_page_name = Tag.find(Array(org_params['tags']).first).name rescue nil
2021-05-11 04:31:58 +00:00
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}
2014-06-27 08:58:18 +00:00
end
end
{
"crumbs" => data
}
end
end