Module: EnjuCirculation::EnjuManifestation::InstanceMethods
- Defined in:
- lib/enju_circulation/manifestation.rb
Instance Method Summary collapse
- #available_checkout_types(user) ⇒ Object
- #checkout_period(user) ⇒ Object
- #checkouts(start_date, end_date) ⇒ Object
- #is_checked_out_by?(user) ⇒ Boolean
- #is_reservable_by?(user) ⇒ Boolean
- #is_reserved? ⇒ Boolean
- #is_reserved_by?(user) ⇒ Boolean
- #next_reservation ⇒ Object
- #reservation_expired_period(user) ⇒ Object
Instance Method Details
#available_checkout_types(user) ⇒ Object
25 26 27 28 29 |
# File 'lib/enju_circulation/manifestation.rb', line 25 def available_checkout_types(user) if user user.profile.user_group.user_group_has_checkout_types.available_for_carrier_type(self.carrier_type) end end |
#checkout_period(user) ⇒ Object
63 64 65 66 67 |
# File 'lib/enju_circulation/manifestation.rb', line 63 def checkout_period(user) if available_checkout_types(user) available_checkout_types(user).collect(&:checkout_period).max || 0 end end |
#checkouts(start_date, end_date) ⇒ Object
59 60 61 |
# File 'lib/enju_circulation/manifestation.rb', line 59 def checkouts(start_date, end_date) Checkout.completed(start_date, end_date).where(:item_id => self.items.collect(&:id)) end |
#is_checked_out_by?(user) ⇒ Boolean
75 76 77 78 79 80 81 |
# File 'lib/enju_circulation/manifestation.rb', line 75 def is_checked_out_by?(user) if items.size > items.size - user.checkouts.not_returned.collect(&:item).size true else false end end |
#is_reservable_by?(user) ⇒ Boolean
31 32 33 34 35 36 37 38 39 |
# File 'lib/enju_circulation/manifestation.rb', line 31 def is_reservable_by?(user) return false if items.for_checkout.empty? unless user.has_role?('Librarian') unless items.size == (items.size - user.checkouts.overdue(Time.zone.now).collect(&:item).size) return false end end true end |
#is_reserved? ⇒ Boolean
51 52 53 54 55 56 57 |
# File 'lib/enju_circulation/manifestation.rb', line 51 def is_reserved? if self.reserves.present? true else false end end |
#is_reserved_by?(user) ⇒ Boolean
41 42 43 44 45 46 47 48 49 |
# File 'lib/enju_circulation/manifestation.rb', line 41 def is_reserved_by?(user) return nil unless user reserve = Reserve.waiting.where(:user_id => user.id, :manifestation_id => id).first if reserve reserve else false end end |
#next_reservation ⇒ Object
21 22 23 |
# File 'lib/enju_circulation/manifestation.rb', line 21 def next_reservation self.reserves.waiting.order('reserves.created_at ASC').readonly(false).first end |
#reservation_expired_period(user) ⇒ Object
69 70 71 72 73 |
# File 'lib/enju_circulation/manifestation.rb', line 69 def reservation_expired_period(user) if available_checkout_types(user) available_checkout_types(user).collect(&:reservation_expired_period).max || 0 end end |