2014-04-01 07:12:43 +00:00
|
|
|
class Bulletin
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
2014-05-01 08:41:00 +00:00
|
|
|
|
|
|
|
include OrbitModel::Status
|
2014-05-15 11:27:05 +00:00
|
|
|
include OrbitModel::Impression
|
2014-06-23 08:36:04 +00:00
|
|
|
# encoding: utf-8
|
2014-04-20 12:23:52 +00:00
|
|
|
include OrbitTag::Taggable
|
|
|
|
include OrbitCategory::Categorizable
|
2014-04-03 03:18:02 +00:00
|
|
|
include Slug
|
2014-04-01 07:12:43 +00:00
|
|
|
|
2014-04-11 09:20:07 +00:00
|
|
|
field :title, as: :slug_title, type: String, localize: true
|
2014-05-01 08:41:00 +00:00
|
|
|
field :subtitle, localize: true
|
|
|
|
field :text, localize: true
|
|
|
|
field :create_user_id
|
|
|
|
field :update_user_id
|
|
|
|
field :public, :type => Boolean, :default => true
|
|
|
|
field :postdate , :type => DateTime, :default => Time.now
|
|
|
|
field :deadline , :type => DateTime
|
2014-06-06 04:05:33 +00:00
|
|
|
field :rss2_sn
|
2014-09-22 08:32:30 +00:00
|
|
|
field :approved, :type => Boolean, :default => false
|
2014-06-17 10:46:52 +00:00
|
|
|
field :is_preview, :type => Boolean, :default => false
|
2015-03-05 11:48:38 +00:00
|
|
|
field :expirable_created_at, type: DateTime
|
2016-07-20 12:35:23 +00:00
|
|
|
field :rejected, :type => Boolean, :default => false
|
|
|
|
field :reapproval, :type => Boolean, :default => false
|
|
|
|
field :rejection_reason
|
2017-06-20 07:04:05 +00:00
|
|
|
field :is_external_link, :type => Boolean, :default => false
|
|
|
|
field :external_link
|
2014-05-01 08:41:00 +00:00
|
|
|
|
2014-05-28 07:37:56 +00:00
|
|
|
field :email_id
|
2014-05-01 08:41:00 +00:00
|
|
|
field :email_sent, :type => Boolean, :default => false
|
2014-06-24 09:23:51 +00:00
|
|
|
field :email_sentdate , :type => DateTime
|
2014-05-28 07:37:56 +00:00
|
|
|
field :email_member_ids
|
2014-05-01 08:41:00 +00:00
|
|
|
field :other_mailaddress
|
2014-10-14 06:28:51 +00:00
|
|
|
field :image_description, localize: true
|
2015-12-22 11:04:13 +00:00
|
|
|
field :top_end_date, :type => DateTime
|
2014-05-01 08:41:00 +00:00
|
|
|
|
|
|
|
mount_uploader :image, ImageUploader
|
|
|
|
|
|
|
|
has_many :bulletin_links, :autosave => true, :dependent => :destroy
|
|
|
|
has_many :bulletin_files, :autosave => true, :dependent => :destroy
|
|
|
|
|
|
|
|
accepts_nested_attributes_for :bulletin_files, :allow_destroy => true
|
|
|
|
accepts_nested_attributes_for :bulletin_links, :allow_destroy => true
|
|
|
|
|
2014-05-28 07:37:56 +00:00
|
|
|
before_destroy :destroy_email
|
|
|
|
|
2015-10-08 09:10:58 +00:00
|
|
|
scope :can_display, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc],[:postdate, :desc])}
|
2014-09-22 08:32:30 +00:00
|
|
|
scope :is_approved, ->{where(:approved => true)}
|
2014-06-06 11:17:58 +00:00
|
|
|
|
2015-03-05 11:48:38 +00:00
|
|
|
before_create :set_expire
|
2015-12-22 11:04:13 +00:00
|
|
|
|
2015-03-05 11:48:38 +00:00
|
|
|
def set_expire
|
|
|
|
self.expirable_created_at = Time.now if self.is_preview
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2014-05-01 08:41:00 +00:00
|
|
|
def update_user
|
|
|
|
User.find(update_user_id) rescue nil
|
|
|
|
end
|
2014-04-01 07:12:43 +00:00
|
|
|
|
2014-05-01 08:41:00 +00:00
|
|
|
def update_user=(user)
|
|
|
|
self.update_user_id = user.id
|
2014-04-01 07:12:43 +00:00
|
|
|
end
|
2014-04-21 07:39:13 +00:00
|
|
|
|
2014-05-28 07:37:56 +00:00
|
|
|
def email_members
|
|
|
|
MemberProfile.find(self.email_member_ids) rescue []
|
|
|
|
end
|
|
|
|
|
|
|
|
def email_addresses
|
|
|
|
addresses = self.email_members.collect{|member| member.email} rescue []
|
|
|
|
addresses = addresses +[self.other_mailaddress] if !self.other_mailaddress.blank?
|
|
|
|
addresses.flatten
|
|
|
|
end
|
|
|
|
|
|
|
|
def email
|
|
|
|
mail = Email.find(self.email_id) rescue nil
|
|
|
|
end
|
|
|
|
|
2014-08-08 03:45:33 +00:00
|
|
|
def expired?
|
|
|
|
(self.deadline < Time.now) rescue false
|
|
|
|
end
|
|
|
|
|
2014-05-28 07:37:56 +00:00
|
|
|
def destroy_email
|
|
|
|
mail = Email.find(self.email_id) rescue nil
|
|
|
|
mail.destroy if !mail.nil?
|
|
|
|
end
|
|
|
|
|
2015-12-22 11:04:13 +00:00
|
|
|
def self.remove_expired_status
|
|
|
|
self.where(:is_top => true, :top_end_date.ne => nil, :top_end_date.lt => Time.now).each do |b|
|
|
|
|
b.is_top = false
|
|
|
|
b.top_end_date = nil
|
|
|
|
b.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-01 07:12:43 +00:00
|
|
|
end
|