X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=app%2Fmodels%2Fcustomer.rb;h=5509439cb8f1c87d5f17dfbcfc3eea5e7b31dcdc;hb=9145563a8d27360910c3de21b088f68283f33ba3;hp=58db47dedcd28dcee754fe2d767e28c00d131299;hpb=97d39268c0b348898dca1ec24552eb26a94ae546;p=cs356-p2-videostore.git diff --git a/app/models/customer.rb b/app/models/customer.rb index 58db47d..5509439 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,12 +1,63 @@ class Customer < ActiveRecord::Base has_many :coitems - has_many :bitems - - has_many_polymorphs :purchaseables, :from => [:coitems, :bitems], :through => :purchases + has_many :merchandise_purchases + has_many :rentable_purchases validates_presence_of :name, :email, :phone, :address validates_numericality_of :debt + def checked_out_videos + coitems = Coitem.find_all_by_customer_id(id) + video_count = 0 + + for item in coitems + if item.rentable.class == Video + video_count += 1 + end + end + + return video_count + end + + def checked_out_games + coitems = Coitem.find_all_by_customer_id(id) + game_count = 0 + + for item in coitems + if item.rentable.class == Game + game_count += 1 + end + end + + return game_count + end + + def overdue_videos + coitems = Coitem.find_all_by_customer_id(id) + overdue_video_count = 0 + + for item in coitems + if item.rentable.class == Video and item.overdue? + overdue_video_count += 1 + end + end + + return overdue_video_count + end + + def overdue_games + coitems = Coitem.find_all_by_customer_id(id) + overdue_game_count = 0 + + for item in coitems + if item.rentable.class == Game and item.overdue? + overdue_game_count += 1 + end + end + + return overdue_game_count + end + protected def validate