Module: EnjuCirculation::EnjuUser::InstanceMethods
- Defined in:
- lib/enju_circulation/user.rb
Instance Method Summary collapse
- #check_item_before_destroy ⇒ Object
- #checked_item_count ⇒ Object
- #has_overdue?(day = 1) ⇒ Boolean
- #reached_reservation_limit?(manifestation) ⇒ Boolean
Instance Method Details
#check_item_before_destroy ⇒ Object
28 29 30 31 32 33 |
# File 'lib/enju_circulation/user.rb', line 28 def check_item_before_destroy # TODO: 貸出記録を残す場合 if checkouts.size > 0 raise 'This user has items still checked out.' end end |
#checked_item_count ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/enju_circulation/user.rb', line 35 def checked_item_count checkout_count = {} CheckoutType.all.each do |checkout_type| # 資料種別ごとの貸出中の冊数を計算 checkout_count[:"#{checkout_type.name}"] = self.checkouts.count_by_sql([" SELECT count(item_id) FROM checkouts WHERE item_id IN ( SELECT id FROM items WHERE checkout_type_id = ? ) AND user_id = ? AND checkin_id IS NULL", checkout_type.id, self.id] ) end return checkout_count end |
#has_overdue?(day = 1) ⇒ Boolean
56 57 58 |
# File 'lib/enju_circulation/user.rb', line 56 def has_overdue?(day = 1) true if checkouts.where(checkin_id: nil).where(Checkout.arel_table[:due_date].lt day.days.ago).count >= 1 end |
#reached_reservation_limit?(manifestation) ⇒ Boolean
51 52 53 54 |
# File 'lib/enju_circulation/user.rb', line 51 def reached_reservation_limit?(manifestation) return true if profile.user_group.user_group_has_checkout_types.available_for_carrier_type(manifestation.carrier_type).where(:user_group_id => profile.user_group.id).collect(&:reservation_limit).max.to_i <= reserves.waiting.size false end |