diff options
author | Peter Kozak <spag@golwen.net> | 2013-04-30 12:23:35 +0200 |
---|---|---|
committer | Peter Kozak <spag@golwen.net> | 2013-04-30 12:23:35 +0200 |
commit | bf29bf2261e955d702e02ea852adb8c9cf46a110 (patch) | |
tree | 89a5b0653eff960bb164138694782f7c316453f8 | |
parent | 4b904201187892676a0fd12e518513334924c534 (diff) |
phone book lookup method added
-rw-r--r-- | app/models/voicemail_message.rb | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/app/models/voicemail_message.rb b/app/models/voicemail_message.rb index 91ba457..698aa50 100644 --- a/app/models/voicemail_message.rb +++ b/app/models/voicemail_message.rb @@ -2,7 +2,8 @@ class VoicemailMessage < ActiveRecord::Base self.table_name = 'voicemail_msgs' self.primary_key = 'uuid' -# belongs_to :sip_account, :foreign_key => 'username', :primary_key => 'auth_name', :readonly => true + belongs_to :voicemail_account, :foreign_key => 'username', :primary_key => 'name', :readonly => true + # Prevent objects from being destroyed def before_destroy raise ActiveRecord::ReadOnlyRecord @@ -49,4 +50,43 @@ class VoicemailMessage < ActiveRecord::Base end end + def phone_book_entry_by_number(number) + begin + voicemail_accountable = self.voicemail_account.voicemail_accountable + rescue + return nil + end + + if ! voicemail_accountable + return nil + end + + if voicemail_accountable.class == SipAccount + owner = voicemail_accountable.sip_accountable + else + owner = voicemail_accountable + end + + if owner.class == User + phone_books = owner.phone_books.all + phone_books.concat(owner.current_tenant.phone_books.all) + elsif owner.class == Tenant + phone_books = owner.phone_books.all + end + + if ! phone_books + return nil + end + + phone_books.each do |phone_book| + phone_book_entry = phone_book.find_entry_by_number(number) + if phone_book_entry + return phone_book_entry + end + end + + return nil + + end + end |