Module: EnjuCirculation::Manifestation
- 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
7 8 9 10 11 |
# File 'lib/enju_circulation/manifestation.rb', line 7 def available_checkout_types(user) if user user.user_group.user_group_has_checkout_types.available_for_carrier_type(self.carrier_type) end end |
#checkout_period(user) ⇒ Object
45 46 47 48 49 |
# File 'lib/enju_circulation/manifestation.rb', line 45 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
41 42 43 |
# File 'lib/enju_circulation/manifestation.rb', line 41 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
57 58 59 60 61 62 63 |
# File 'lib/enju_circulation/manifestation.rb', line 57 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
13 14 15 16 17 18 19 20 21 |
# File 'lib/enju_circulation/manifestation.rb', line 13 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
33 34 35 36 37 38 39 |
# File 'lib/enju_circulation/manifestation.rb', line 33 def is_reserved? if self.reserves.present? true else false end end |
#is_reserved_by?(user) ⇒ Boolean
23 24 25 26 27 28 29 30 31 |
# File 'lib/enju_circulation/manifestation.rb', line 23 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
3 4 5 |
# File 'lib/enju_circulation/manifestation.rb', line 3 def next_reservation self.reserves.waiting.order('reserves.created_at ASC').first end |
#reservation_expired_period(user) ⇒ Object
51 52 53 54 55 |
# File 'lib/enju_circulation/manifestation.rb', line 51 def reservation_expired_period(user) if available_checkout_types(user) available_checkout_types(user).collect(&:reservation_expired_period).max || 0 end end |