Created
August 18, 2009 21:45
-
-
Save sprite2005/169997 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Listing < ActiveRecord::Base | |
belongs_to :user | |
def get_availability | |
if user.active_phone_number && user.outgoing_call_session.nil? && user.incoming_call_session.nil? && (self.active == true) | |
return :online | |
elsif user.outgoing_call_session || user.incoming_call_session | |
return :busy | |
else | |
return :offline | |
end | |
end | |
def update_availability | |
status = get_availability | |
if self.availability_status != status | |
self.availability_status = status | |
save | |
end | |
end | |
end | |
class User < ActiveRecord::Base | |
has_many :listings, :order => "position", :dependent => :destroy | |
has_one :outgoing_call_session, :class_name => "CallSession", :foreign_key => "client_id" | |
has_one :incoming_call_session, :class_name => "CallSession", :foreign_key => "vendor_id" | |
belongs_to :active_phone_number, :class_name => "PhoneNumber", :foreign_key => "active_phone_number_id" | |
def get_availability | |
if active_phone_number && outgoing_call_session.nil? && incoming_call_session.nil? && !listings.first(:conditions => "active = true").nil? | |
return :online | |
elsif outgoing_call_session || incoming_call_session | |
return :busy | |
else | |
return :offline | |
end | |
end | |
def update_availability | |
status = get_availability | |
if self.availability_status != status | |
self.availability_status = status | |
save | |
end | |
end | |
end | |
class CallSession < ActiveRecord::Base | |
belongs_to :listing | |
belongs_to :transaction | |
belongs_to :client, :class_name => 'User', :foreign_key => 'client_id' | |
belongs_to :vendor, :class_name => 'User', :foreign_key => 'vendor_id' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment