personal-conference/app/models/writing_conference.rb

95 lines
2.6 KiB
Ruby
Raw Normal View History

2014-07-01 10:19:07 +00:00
class WritingConference
include Mongoid::Document
include Mongoid::Timestamps
include OrbitModel::Status
include OrbitTag::Taggable
include Slug
field :paper_title, as: :slug_title, localize: true
field :conference_title, localize: true
field :authors, localize: true
field :location, localize: true
field :sponsor, localize: true
field :year
field :language
field :period_start_date, :type => Date
field :period_end_date, :type => Date
field :keywords
field :abstract
field :publication_date, :type => Date
field :url
field :note
field :create_user_id, :type => BSON::ObjectId
field :update_user_id, :type => BSON::ObjectId
field :isbn
field :isi_number
belongs_to :member_profile
has_and_belongs_to_many :conference_author_types
has_and_belongs_to_many :conference_paper_types
has_and_belongs_to_many :conference_paper_levels
has_many :writing_conference_files, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :writing_conference_files, :allow_destroy => true
before_validation :add_http
def create_link
title = []
title << self.authors if self.authors.present?
if !self.publication_date.nil?
pd = self.publication_date.strftime("%Y-%m-%d").split('-')
title << pd[0]
end
title << self.paper_title if self.paper_title.present?
title << self.conference_title if self.conference_title.present?
title << self.location if self.location.present?
title << "#{period_start_date}-#{period_end_date}" if (self.period_start_date.present? && self.period_end_date.present?)
title.join(', ')
end
def values_for_view
attribute_values = self.attributes.select{|k,v| v if (k.in?(
[ "year",
"language",
"period_start_date",
"period_end_date",
"publication_date",
"keywords",
"abstract",
"url",
"note",
"isbn",
"isi_number"]) && v.present?)}
localized_fields = {
"paper_title" => self.paper_title,
"conference_title" => self.conference_title,
"location"=>self.location,
"sponsor"=>self.sponsor}
authors = {"authors" => self.authors}
files = Hash.new
# self.writing_conference_files.each do |f, index|
# title = f.title.blank? ? File.basename(f.file.path) : f.title
# end
values = [localized_fields, attribute_values, authors,files]
values.inject(&:merge)
end
protected
def add_http
unless self.url.blank? || self.url[/^http:\/\//] || self.url[/^https:\/\//]
self.url = 'http://' + self.url
end
end
end