summaryrefslogtreecommitdiff
path: root/app/models/voicemail_account.rb
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-03-27 12:14:02 +0100
committerPeter Kozak <spag@golwen.net>2013-03-27 12:14:02 +0100
commit045eea165f469bb053c28e629848af35a93787de (patch)
treea409f1eb6f7e3c2f3ea0ab9b48b751adae6bda51 /app/models/voicemail_account.rb
parentc2e5547c22d2021bfa0dbafadd55723485e1c7d1 (diff)
notification methods added
Diffstat (limited to 'app/models/voicemail_account.rb')
-rw-r--r--app/models/voicemail_account.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/app/models/voicemail_account.rb b/app/models/voicemail_account.rb
index 02dc283..8ec181f 100644
--- a/app/models/voicemail_account.rb
+++ b/app/models/voicemail_account.rb
@@ -3,6 +3,7 @@ class VoicemailAccount < ActiveRecord::Base
belongs_to :voicemail_accountable, :polymorphic => true
has_many :voicemail_settings
+ has_many :voicemail_messages, :foreign_key => 'username', :primary_key => 'name'
validates :name,
:presence => true,
@@ -17,4 +18,47 @@ class VoicemailAccount < ActiveRecord::Base
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