ask/app/models/ask_question.rb

54 lines
1.6 KiB
Ruby

class AskQuestion
include Mongoid::Document
include Mongoid::Timestamps
# include ActiveModel::Validations
include OrbitCategory::Categorizable
include OrbitTag::Taggable
# 欄位
field :name, type: String
field :identity, type: String
field :mail, type: String
field :phone, type: String
field :fax, type: String
field :title, type: String
field :content, type: String
field :appointment, type:DateTime
field :sex
field :reply, type: String
field :comment, type: String
field :situation, type: String, default: "is_waiting" #預設待處理
field :send_email, type: Boolean, default: false
field :email_id
field :custom_values, type: Hash,default: {}
field :agree_show,type: Boolean,default: false
field :agree_usage,type: Boolean,default: false
# validates_presence_of :name, :identity, :mail, :title, :content
def email
mail = Email.find(self.email_id) rescue nil
end
def email_address
email_address = AskAdmin.pluck(:email).select{|s| s.present?}.uniq rescue []
authorizes = Authorization.where(:module_app_id=>ModuleApp.where(:key=>'ask').first.id).to_a rescue []
authorizes.each do |a|
if a.category_id
next if a.category_id != self.category_id
end
if a.user_id
u = a.user
email_address << u.email if u && u.email
elsif a.role_id
email_address = email_address + MemberProfile.where(:role_ids=>a.role_id).pluck(:email).select{|s| s.present?}.uniq
else
a.destroy
end
end
email_address.uniq!
# email_address = email_address +[self.mail] if !self.mail.blank?
email_address.flatten
end
end