Sha256: ca55bfa52061fd5662c2b5acef95dd6a6fd83c8e80c2aff1df1b705374600b81

Contents?: true

Size: 1.63 KB

Versions: 42

Compression:

Stored size: 1.63 KB

Contents

module EnjuCirculation
  module Manifestation
    def next_reservation
      self.reserves.waiting.order('reserves.created_at ASC').first
    end

    def available_checkout_types(user)
      if user
        user.user_group.user_group_has_checkout_types.available_for_carrier_type(self.carrier_type)
      end
    end

    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

    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

    def is_reserved?
      if self.reserves.present?
        true
      else
        false
      end
    end

    def checkouts(start_date, end_date)
      Checkout.completed(start_date, end_date).where(:item_id => self.items.collect(&:id))
    end

    def checkout_period(user)
      if available_checkout_types(user)
        available_checkout_types(user).collect(&:checkout_period).max || 0
      end
    end

    def reservation_expired_period(user)
      if available_checkout_types(user)
        available_checkout_types(user).collect(&:reservation_expired_period).max || 0
      end
    end

    def is_checked_out_by?(user)
      if items.size > items.size - user.checkouts.not_returned.collect(&:item).size
        true
      else
        false
      end
    end
  end
end

#class Manifestation < ActiveRecord::Base
#end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
enju_circulation-0.0.47 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.46 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.45 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.43 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.42 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.41 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.40 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.39 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.38 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.37 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.36 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.35 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.34 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.33 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.32 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.31 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.30 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.29 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.28 lib/enju_circulation/manifestation.rb
enju_circulation-0.0.27 lib/enju_circulation/manifestation.rb