app/models/item.rb in enju_biblio-0.3.18 vs app/models/item.rb in enju_biblio-0.4.0.beta.1
- old
+ new
@@ -8,25 +8,23 @@
end
}
delegate :display_name, to: :shelf, prefix: true
has_many :owns
has_many :agents, through: :owns
- has_many :donates, dependent: :destroy
+ has_many :donates
has_many :donors, through: :donates, source: :agent
has_one :resource_import_result
belongs_to :manifestation, touch: true
belongs_to :bookstore, optional: true
belongs_to :required_role, class_name: 'Role', foreign_key: 'required_role_id'
belongs_to :budget_type, optional: true
has_one :accept, dependent: :destroy
has_one :withdraw, dependent: :destroy
- has_many :item_custom_values, -> { joins(:item_custom_property).order(:position) }, dependent: :destroy
+ scope :accepted_between, lambda{|from, to| includes(:accept).where('items.created_at BETWEEN ? AND ?', Time.zone.parse(from).beginning_of_day, Time.zone.parse(to).end_of_day)}
belongs_to :shelf, counter_cache: true
- accepts_nested_attributes_for :item_custom_values, reject_if: :all_blank
- scope :accepted_between, lambda{|from, to| includes(:accept).where('items.created_at BETWEEN ? AND ?', Time.zone.parse(from).beginning_of_day, Time.zone.parse(to).end_of_day)}
validates_associated :bookstore
validates :manifestation_id, presence: true
validates :item_identifier, allow_blank: true, uniqueness: true,
format: {with: /\A[0-9A-Za-z_]+\Z/}
validates :binding_item_identifier, allow_blank: true,
@@ -64,27 +62,27 @@
attr_accessor :library_id
paginates_per 10
def title
- manifestation&.original_title
+ manifestation.try(:original_title)
end
def creator
- manifestation&.creator
+ manifestation.try(:creator)
end
def contributor
- manifestation&.contributor
+ manifestation.try(:contributor)
end
def publisher
- manifestation&.publisher
+ manifestation.try(:publisher)
end
def owned(agent)
- owns.find_by(agent_id: agent.id)
+ owns.where(agent_id: agent.id).first
end
def manifestation_url
Addressable::URI.parse("#{LibraryGroup.site_config.url}manifestations/#{self.manifestation.id}").normalize.to_s if self.manifestation
end
@@ -96,56 +94,10 @@
true
else
true
end
end
-
- def self.csv_header(role: 'Guest')
- Item.new.to_hash(role: role).keys
- end
-
- def to_hash(role: 'Guest')
- record = {
- item_id: id,
- item_identifier: item_identifier,
- binding_item_identifier: binding_item_identifier,
- call_number: call_number,
- library: shelf&.library&.name,
- shelf: shelf&.name,
- item_note: note,
- accepted_at: accept&.created_at,
- acquired_at: acquired_at,
- item_created_at: created_at,
- item_updated_at: updated_at
- }
-
- if ['Administrator', 'Librarian'].include?(role)
- record.merge!({
- bookstore: bookstore&.name,
- budget_type: budget_type&.name,
- item_required_role: required_role.name,
- item_price: price,
- item_memo: memo
- })
-
- ItemCustomProperty.order(:position).each do |custom_property|
- custom_value = item_custom_values.find_by(item_custom_property: custom_property)
- record[:"item:#{custom_property.name}"] = custom_value.try(:value)
- end
-
- if defined?(EnjuCirculation)
- record.merge!({
- use_restriction: use_restriction&.name,
- circulation_status: circulation_status&.name,
- checkout_type: checkout_type&.name,
- total_checkouts: checkouts.count
- })
- end
- end
-
- record
- end
end
# == Schema Information
#
# Table name: items
@@ -171,7 +123,6 @@
# checkout_type_id :integer default(1), not null
# binding_item_identifier :string
# binding_call_number :string
# binded_at :datetime
# manifestation_id :integer not null
-# memo :text
#