curation/app/models/curation_post_section.rb

46 lines
1.1 KiB
Ruby

# encoding: utf-8
class CurationPostSection
include Mongoid::Document
include Mongoid::Timestamps
field :title, localize: true
field :section_type
field :text, localize: true
field :universal_table
field :table_entries
belongs_to :curation_post
def get_table_entries_for_frontend
module_app = ModuleApp.find_by_key("universal_table")
tids = self.table_entries.split(',')
table_entries = TableEntry.find(tids)
table_entries.map do |entry|
rows = []
entry.column_entries.each do |ce|
ct = ce.table_column
next if ct.nil?
next if ct.display_in_index === false
text = ce.get_frontend_text(ct)
if ct.is_link_to_show
text = "<a class='tabletitle' href='#{OrbitHelper.cal_url_to_show(module_app, entry)}'>#{text}</a>"
end
rows << {
"title" => ct.title,
"text" => text
} if text != ""
end
{
"uid" => entry.uid,
"type" => self.section_type,
"rows" => rows
}
end
end
def get_table_entries
tids = self.table_entries.split(',')
TableEntry.find(tids)
end
end