summaryrefslogtreecommitdiff
path: root/app/models/switchboard.rb
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-06-27 08:56:03 +0200
committerPeter Kozak <spag@golwen.net>2013-06-27 08:56:03 +0200
commit39c06e5b4fd5a984c4f93fa48567c63848632ced (patch)
tree393ec0dbe1020d6800c94476f6c331d211ab9c30 /app/models/switchboard.rb
parent677e234c6b3bbec189f2caf2f237f609ab44b274 (diff)
parent1c6646bc732def369e54ef4ac576d748c6ba9c92 (diff)
Merge branch 'develop' of github.com:amooma/GS5 into develop
Diffstat (limited to 'app/models/switchboard.rb')
-rw-r--r--app/models/switchboard.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb
index 095f878..d62657f 100644
--- a/app/models/switchboard.rb
+++ b/app/models/switchboard.rb
@@ -25,8 +25,13 @@ class Switchboard < ActiveRecord::Base
}
belongs_to :user, :touch => true
+
has_many :switchboard_entries, :dependent => :destroy
+ has_many :switchable_switchboard_entries, :class_name => "SwitchboardEntry", :conditions => {:switchable => true}
+
has_many :sip_accounts, :through => :switchboard_entries
+ has_many :switchable_sip_accounts, :source => :sip_account, :through => :switchable_switchboard_entries, :uniq => true
+
has_many :phone_numbers, :through => :sip_accounts
before_validation :convert_0_to_nil
@@ -36,7 +41,11 @@ class Switchboard < ActiveRecord::Base
end
def active_calls
- self.switchboard_entries.where(:switchable => true).map{|se| se.sip_account}.uniq.map{|sip_account| sip_account.calls}.flatten
+ Call.where("sip_account_id = ? or b_sip_account_id = ?", self.switchable_sip_account_ids, self.switchable_sip_account_ids).order(:start_stamp)
+ end
+
+ def dispatchable_incoming_calls
+ Call.where("b_sip_account_id = ?", self.switchable_sip_account_ids).order(:start_stamp)
end
private