2014-06-27 08:58:18 +00:00
|
|
|
class BreadcrumbWidgetsController < ApplicationController
|
|
|
|
def widget
|
2021-12-18 05:02:43 +00:00
|
|
|
params = OrbitHelper.params
|
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
|
|
|
|
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
|
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
|
|
|
|
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}
|
2014-06-27 08:58:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"crumbs" => data
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|