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 field :rss2_id 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 get_plugin_data(fields_to_show) plugin_datas = [] fields_to_show.each do |field| plugin_data = self.get_plugin_field_data(field) next if plugin_data.blank? or plugin_data['value'].blank? plugin_datas << plugin_data end plugin_datas end def get_plugin_field_data(field) case field when "paper_level" value = self.conference_paper_levels.collect{|level| level.title}.join(',') rescue "" when "author_type" value = self.conference_author_types.collect{|type| type.title}.join(',') rescue "" when "paper_type" value = self.conference_paper_types.collect{|type| type.title}.join(',') rescue "" when "publication_date" value = self.publication_date.to_date.strftime("%Y-%m-%d") rescue "" when "language" value = I18n.t(self.language) rescue "" when "file" files = [] self.writing_conference_files.each do |conference_files| url = conference_files.file.url title = (conference_files.title.blank? ? File.basename(conference_files.file.path) : conference_files.title) files << "
  • #{title}
  • " end value = files.join("") else value = self.send(field) rescue "" end value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "#{value}" : value { "key"=>field, "title_class"=>"conference-#{field.gsub('_','-')}-field", "value_class"=>"conference-#{field.gsub('_','-')}-value", "title"=>I18n.t('personal_conference.'+field), "value"=>value } end protected def add_http unless self.url.blank? || self.url[/^http:\/\//] || self.url[/^https:\/\//] self.url = 'http://' + self.url end end end