epaper/app/models/paper_criteria.rb

47 lines
1.5 KiB
Ruby
Raw Normal View History

2019-05-28 15:54:32 +00:00
class PaperCriteria
include Mongoid::Document
include Mongoid::Timestamps
2024-11-15 10:20:00 +00:00
include Slug
2019-05-28 15:54:32 +00:00
field :title,as: :slug_title, localize: true
field :description, localize: true
field :content, localize: true
2019-05-28 15:54:32 +00:00
field :start_date, type: DateTime
field :end_date, type: DateTime
field :sending_time, type: DateTime
field :sending_title, localize: true
field :sending_notes
field :language_to_send, type: Array, :default => ["en","zh_tw"]
field :receivers, type: Array, :default => ["subscriber"]
2019-05-28 15:54:32 +00:00
field :other_emails
2020-08-28 12:49:47 +00:00
field :invalid_emails, type: Array, :default => []
field :send_failed_emails, type: Array, :default => []
2024-09-15 02:22:04 +00:00
field :email_sentdate, :type => DateTime
2024-11-15 10:20:00 +00:00
field :banner_image, type: BSON::ObjectId
mount_uploader :image, ImageUploader
2019-05-28 15:54:32 +00:00
def epaper_topics
2020-08-04 06:48:46 +00:00
tmp = EPaperTopic.where(:period.gte => self.start_date.in_time_zone(Time.zone.utc_offset / 3600), :period.lte => self.end_date.in_time_zone(Time.zone.utc_offset / 3600)).can_display
tmp = EPaperTopic.where(:period.gte => self.start_date.in_time_zone(Time.zone.utc_offset / 3600), :period.lte => self.end_date.in_time_zone(Time.zone.utc_offset / 3600)).limit(1) if tmp.first.nil?
2020-03-04 04:40:31 +00:00
tmp
2019-05-28 15:54:32 +00:00
end
def other_emails_ids
if !self.other_emails.nil?
return self.other_emails.split(",")
else
return []
end
end
2024-09-15 02:22:04 +00:00
def get_email_sentdate
_email_sentdate = self.email_sentdate
if _email_sentdate && _email_sentdate < DateTime.now
_email_sentdate = nil
end
_email_sentdate
end
2024-11-15 10:20:00 +00:00
end