diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-06-20 19:06:19 +0200 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-06-20 19:06:19 +0200 |
commit | eb0e1cc5c26275ff3e5c341404e8bc558f8312b8 (patch) | |
tree | 71f449ccd6f15422717de3ac24f87d5e888ddd79 /app/models/voicemail_account.rb | |
parent | df6e17e48995f25e72509986f30700d778b179b6 (diff) | |
parent | 3b27a5d45b12f6bac65da2a8e17387bfda42a2f1 (diff) |
Merge branch 'develop'
Diffstat (limited to 'app/models/voicemail_account.rb')
-rw-r--r-- | app/models/voicemail_account.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/app/models/voicemail_account.rb b/app/models/voicemail_account.rb new file mode 100644 index 0000000..8ec181f --- /dev/null +++ b/app/models/voicemail_account.rb @@ -0,0 +1,64 @@ +class VoicemailAccount < ActiveRecord::Base + attr_accessible :uuid, :name, :active, :gs_node_id, :voicemail_accountable_type, :voicemail_accountable_id + + belongs_to :voicemail_accountable, :polymorphic => true + has_many :voicemail_settings + has_many :voicemail_messages, :foreign_key => 'username', :primary_key => 'name' + + validates :name, + :presence => true, + :uniqueness => true + + validates :voicemail_accountable_id, + :presence => true + + validates :voicemail_accountable_type, + :presence => true + + def to_s + "#{voicemail_accountable.to_s}: #{name}" + end + + def notify_to + send_notification = nil + if self.voicemail_settings.where(:name => 'notify', :value => true).first + send_notification = true + elsif self.voicemail_settings.where(:name => 'notify', :value => false).first + send_notification = false + end + + if send_notification == nil + send_notification = GsParameter.get('notify', 'voicemail', 'settings') + end + + if !send_notification + return send_notification + end + + email = self.voicemail_settings.where(:name => 'email').first.try(:value) + + if email.blank? + if self.voicemail_accountable.class == User + email = self.voicemail_accountable.email + end + end + + return email + end + + + def notification_setting(name) + setting = nil + if self.voicemail_settings.where(:name => name, :value => true).first + setting = true + elsif self.voicemail_settings.where(:name => name, :value => false).first + setting = false + end + + if setting == nil + setting = GsParameter.get(name, 'voicemail', 'settings') + end + + return setting + end +end |