enju_circulation 0.0.47 → 0.0.48

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/app/models/reserve.rb +9 -9
  2. data/lib/enju_circulation/controller.rb +25 -0
  3. data/lib/enju_circulation/manifestation.rb +61 -45
  4. data/lib/enju_circulation/version.rb +1 -1
  5. data/lib/enju_circulation.rb +4 -1
  6. data/spec/dummy/README.rdoc +261 -0
  7. data/spec/dummy/app/controllers/application_controller.rb +4 -13
  8. data/spec/dummy/app/models/user_group.rb +11 -0
  9. data/spec/dummy/config/initializers/mime_types.rb +0 -1
  10. data/spec/dummy/db/migrate/001_create_patrons.rb +1 -5
  11. data/spec/dummy/db/migrate/005_create_manifestations.rb +1 -8
  12. data/spec/dummy/db/migrate/006_create_items.rb +1 -6
  13. data/spec/dummy/db/migrate/012_create_owns.rb +12 -0
  14. data/spec/dummy/db/migrate/015_create_creates.rb +12 -0
  15. data/spec/dummy/db/migrate/047_create_produces.rb +12 -0
  16. data/spec/dummy/db/migrate/073_create_carrier_types.rb +1 -5
  17. data/spec/dummy/db/migrate/125_create_donates.rb +12 -0
  18. data/spec/dummy/db/migrate/20080830154109_create_realizes.rb +13 -0
  19. data/spec/dummy/db/migrate/20080830172106_create_exemplifies.rb +1 -7
  20. data/spec/dummy/db/migrate/20080905191442_create_patron_types.rb +1 -5
  21. data/spec/dummy/db/migrate/20081025083323_create_countries.rb +28 -0
  22. data/spec/dummy/db/migrate/20081025083905_create_languages.rb +1 -5
  23. data/spec/dummy/db/migrate/20090812151902_create_patron_relationship_types.rb +12 -0
  24. data/spec/dummy/db/migrate/20091012101112_add_dcndl_schema.rb +27 -0
  25. data/spec/dummy/db/migrate/20091202124834_create_versions.rb +18 -0
  26. data/spec/dummy/db/migrate/20091214131723_create_series_statements.rb +13 -0
  27. data/spec/dummy/db/migrate/20100223121519_rename_series_statement_title_to_original_title.rb +13 -0
  28. data/spec/dummy/db/migrate/20100321235924_add_series_statement_identifier_to_series_statement.rb +10 -0
  29. data/spec/dummy/db/migrate/20100525124311_create_manifestation_relationships.rb +13 -0
  30. data/spec/dummy/db/migrate/20100606073747_create_patron_relationships.rb +13 -0
  31. data/spec/dummy/db/migrate/20100607044753_create_manifestation_relationship_types.rb +12 -0
  32. data/spec/dummy/db/migrate/20100814091104_add_position_to_patron_relationship.rb +11 -0
  33. data/spec/dummy/db/migrate/20110301035123_add_pub_date_to_manifestation.rb +9 -0
  34. data/spec/dummy/db/migrate/20110301121550_add_birth_date_and_death_date_to_patron.rb +11 -0
  35. data/spec/dummy/db/migrate/20110425133109_add_issn_to_series_statement.rb +9 -0
  36. data/spec/dummy/db/migrate/20110618091240_add_periodical_to_series_statement.rb +9 -0
  37. data/spec/dummy/db/migrate/20110619064807_add_edition_string_to_manifestation.rb +9 -0
  38. data/spec/dummy/db/migrate/20110627034940_create_series_statement_merge_lists.rb +9 -0
  39. data/spec/dummy/db/migrate/20110627035057_create_series_statement_merges.rb +12 -0
  40. data/spec/dummy/db/migrate/20110820131417_create_series_has_manifestations.rb +13 -0
  41. data/spec/dummy/db/migrate/20110916053430_rename_manifestation_number_list_to_number_string.rb +13 -0
  42. data/spec/dummy/db/migrate/20110916103953_add_manifestaiton_id_to_series_statement.rb +10 -0
  43. data/spec/dummy/db/migrate/20110918161853_rename_series_statement_manifestation_id_to_root_manifestation_id.rb +13 -0
  44. data/spec/dummy/db/migrate/20110918162329_add_note_to_series_statement.rb +9 -0
  45. data/spec/dummy/db/migrate/20111124110059_create_create_types.rb +12 -0
  46. data/spec/dummy/db/migrate/20111124110319_create_realize_types.rb +12 -0
  47. data/spec/dummy/db/migrate/20111124110355_create_produce_types.rb +12 -0
  48. data/spec/dummy/db/migrate/20111124112131_add_create_type_to_create.rb +7 -0
  49. data/spec/dummy/db/migrate/20120125152919_add_title_subseries_transcription_to_series_statement.rb +6 -0
  50. data/spec/dummy/db/schema.rb +246 -36
  51. data/spec/dummy/db/test.sqlite3 +0 -0
  52. data/spec/dummy/lib/enju_leaf.rb +2 -0
  53. metadata +71 -33
  54. data/lib/enju_circulation/user_group.rb +0 -10
  55. data/spec/dummy/app/models/basket.rb +0 -64
  56. data/spec/dummy/app/models/carrier_type.rb +0 -33
  57. data/spec/dummy/app/models/event.rb +0 -85
  58. data/spec/dummy/app/models/event_category.rb +0 -23
  59. data/spec/dummy/app/models/exemplify.rb +0 -45
  60. data/spec/dummy/app/models/item.rb +0 -278
  61. data/spec/dummy/app/models/language.rb +0 -4
  62. data/spec/dummy/app/models/library.rb +0 -128
  63. data/spec/dummy/app/models/library_group.rb +0 -86
  64. data/spec/dummy/app/models/manifestation.rb +0 -13
  65. data/spec/dummy/app/models/patron.rb +0 -168
  66. data/spec/dummy/app/models/patron_type.rb +0 -19
  67. data/spec/dummy/app/models/request_status_type.rb +0 -19
  68. data/spec/dummy/app/models/request_type.rb +0 -18
  69. data/spec/dummy/app/models/shelf.rb +0 -54
@@ -1,45 +0,0 @@
1
- class Exemplify < ActiveRecord::Base
2
- belongs_to :manifestation
3
- belongs_to :item
4
-
5
- validates_associated :manifestation, :item
6
- validates_presence_of :manifestation_id, :item_id
7
- validates_uniqueness_of :item_id
8
- after_save :reindex
9
- after_destroy :reindex
10
-
11
- acts_as_list :scope => :manifestation_id
12
-
13
- def self.per_page
14
- 10
15
- end
16
-
17
- def reindex
18
- manifestation.try(:index)
19
- item.try(:index)
20
- end
21
-
22
- if defined?(EnjuCirculation)
23
- after_create :create_lending_policy
24
-
25
- def create_lending_policy
26
- UserGroupHasCheckoutType.available_for_item(item).each do |rule|
27
- LendingPolicy.create!(:item_id => item.id, :user_group_id => rule.user_group_id, :fixed_due_date => rule.fixed_due_date, :loan_period => rule.checkout_period, :renewal => rule.checkout_renewal_limit)
28
- end
29
- end
30
- end
31
- end
32
-
33
- # == Schema Information
34
- #
35
- # Table name: exemplifies
36
- #
37
- # id :integer not null, primary key
38
- # manifestation_id :integer not null
39
- # item_id :integer not null
40
- # type :string(255)
41
- # position :integer
42
- # created_at :datetime
43
- # updated_at :datetime
44
- #
45
-
@@ -1,278 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- class Item < ActiveRecord::Base
3
- scope :on_shelf, where('shelf_id != 1')
4
- scope :on_web, where(:shelf_id => 1)
5
- has_one :exemplify
6
- has_one :manifestation, :through => :exemplify
7
- #has_many :owns
8
- #has_many :patrons, :through => :owns
9
- belongs_to :shelf, :counter_cache => true, :validate => true
10
- delegate :display_name, :to => :shelf, :prefix => true
11
- belongs_to :bookstore, :validate => true
12
- #has_many :donates
13
- #has_many :donors, :through => :donates, :source => :patron
14
- belongs_to :required_role, :class_name => 'Role', :foreign_key => 'required_role_id', :validate => true
15
- #has_one :resource_import_result
16
- belongs_to :budget_type
17
-
18
- validates_associated :shelf, :bookstore
19
- validates :manifestation_id, :presence => true, :on => :create
20
- validates :item_identifier, :allow_blank => true, :uniqueness => true,
21
- :format => {:with => /\A[0-9A-Za-z_]+\Z/}
22
- validates :url, :url => true, :allow_blank => true, :length => {:maximum => 255}
23
- validates_date :acquired_at, :allow_blank => true
24
-
25
- #has_paper_trail
26
- normalize_attributes :item_identifier
27
-
28
- searchable do
29
- text :item_identifier, :note, :title #, :creator, :contributor, :publisher
30
- string :item_identifier
31
- string :library do
32
- shelf.library.name if shelf
33
- end
34
- integer :required_role_id
35
- integer :manifestation_id do
36
- manifestation.id if manifestation
37
- end
38
- integer :shelf_id
39
- #integer :patron_ids, :multiple => true
40
- time :created_at
41
- time :updated_at
42
- end
43
-
44
- attr_accessor :library_id, :manifestation_id
45
-
46
- if defined?(EnjuCirculation)
47
- FOR_CHECKOUT_CIRCULATION_STATUS = [
48
- 'Available On Shelf',
49
- 'On Loan',
50
- 'Waiting To Be Reshelved'
51
- ]
52
- FOR_CHECKOUT_USE_RESTRICTION = [
53
- 'Available For Supply Without Return',
54
- 'Limited Circulation, Long Loan Period',
55
- 'Limited Circulation, Short Loan Period',
56
- 'No Reproduction',
57
- 'Overnight Only',
58
- 'Renewals Not Permitted',
59
- 'Supervision Required',
60
- 'Term Loan',
61
- 'User Signature Required',
62
- 'Limited Circulation, Normal Loan Period'
63
- ]
64
- scope :for_checkout, includes(:circulation_status, :use_restriction).where(
65
- 'circulation_statuses.name' => FOR_CHECKOUT_CIRCULATION_STATUS,
66
- 'use_restrictions.name' => FOR_CHECKOUT_USE_RESTRICTION
67
- ).where('item_identifier IS NOT NULL')
68
- scope :removed, includes(:circulation_status).where('circulation_statuses.name' => 'Removed')
69
- has_many :checkouts
70
- has_many :reserves
71
- has_many :checked_items, :dependent => :destroy
72
- has_many :baskets, :through => :checked_items
73
- belongs_to :circulation_status, :validate => true
74
- belongs_to :checkout_type
75
- has_many :lending_policies, :dependent => :destroy
76
- has_one :item_has_use_restriction, :dependent => :destroy
77
- has_one :use_restriction, :through => :item_has_use_restriction
78
- validates_associated :circulation_status, :checkout_type
79
- validates_presence_of :circulation_status, :checkout_type
80
- before_save :set_use_restriction
81
- searchable do
82
- integer :circulation_status_id
83
- end
84
- attr_accessor :use_restriction_id
85
-
86
- def set_circulation_status
87
- self.circulation_status = CirculationStatus.where(:name => 'In Process').first if self.circulation_status.nil?
88
- end
89
-
90
- def set_use_restriction
91
- if self.use_restriction_id
92
- self.use_restriction = UseRestriction.where(:id => self.use_restriction_id).first
93
- else
94
- return if use_restriction
95
- self.use_restriction = UseRestriction.where(:name => 'Limited Circulation, Normal Loan Period').first
96
- end
97
- end
98
-
99
- def checkout_status(user)
100
- user.user_group.user_group_has_checkout_types.where(:checkout_type_id => self.checkout_type.id).first
101
- end
102
-
103
- def reserved?
104
- return true if manifestation.next_reservation
105
- false
106
- end
107
-
108
- def rent?
109
- return true if self.checkouts.not_returned.select(:item_id).detect{|checkout| checkout.item_id == self.id}
110
- false
111
- end
112
-
113
- def reserved_by_user?(user)
114
- if manifestation.next_reservation
115
- return true if manifestation.next_reservation.user == user
116
- end
117
- false
118
- end
119
-
120
- def available_for_checkout?
121
- if circulation_status.name == 'On Loan'
122
- false
123
- else
124
- manifestation.items.for_checkout.include?(self)
125
- end
126
- end
127
-
128
- def checkout!(user)
129
- self.circulation_status = CirculationStatus.where(:name => 'On Loan').first
130
- if self.reserved_by_user?(user)
131
- manifestation.next_reservation.update_attributes(:checked_out_at => Time.zone.now)
132
- manifestation.next_reservation.sm_complete!
133
- end
134
- save!
135
- end
136
-
137
- def checkin!
138
- self.circulation_status = CirculationStatus.where(:name => 'Available On Shelf').first
139
- save(:validate => false)
140
- end
141
-
142
- def retain(librarian)
143
- Item.transaction do
144
- reservation = manifestation.next_reservation
145
- unless reservation.nil?
146
- reservation.item = self
147
- reservation.sm_retain!
148
- reservation.send_message(librarian)
149
- end
150
- end
151
- end
152
-
153
- def lending_rule(user)
154
- lending_policies.where(:user_group_id => user.user_group.id).first
155
- end
156
-
157
- def not_for_loan?
158
- !manifestation.items.for_checkout.include?(self)
159
- end
160
- end
161
-
162
- if defined?(EnjuInventory)
163
- has_many :inventories, :dependent => :destroy
164
- has_many :inventory_files, :through => :inventories
165
- searchable do
166
- integer :inventory_file_ids, :multiple => true
167
- end
168
-
169
- def self.inventory_items(inventory_file, mode = 'not_on_shelf')
170
- item_ids = Item.select(:id).collect(&:id)
171
- inventory_item_ids = inventory_file.items.select('items.id').collect(&:id)
172
- case mode
173
- when 'not_on_shelf'
174
- Item.where(:id => (item_ids - inventory_item_ids))
175
- when 'not_in_catalog'
176
- Item.where(:id => (inventory_item_ids - item_ids))
177
- end
178
- rescue
179
- nil
180
- end
181
- end
182
-
183
- if defined?(EnjuQuestion)
184
- has_many :answer_has_items, :dependent => :destroy
185
- has_many :answers, :through => :answer_has_items
186
- end
187
-
188
- if defined?(EnjuInterLibraryLoan)
189
- has_many :inter_library_loans, :dependent => :destroy
190
- def inter_library_loaned?
191
- true if self.inter_library_loans.size > 0
192
- end
193
- end
194
-
195
- def self.per_page
196
- 10
197
- end
198
-
199
- def title
200
- manifestation.try(:original_title)
201
- end
202
-
203
- def creator
204
- manifestation.try(:creator)
205
- end
206
-
207
- def contributor
208
- manifestation.try(:contributor)
209
- end
210
-
211
- def publisher
212
- manifestation.try(:publisher)
213
- end
214
-
215
- def shelf_name
216
- shelf.name
217
- end
218
-
219
- def hold?(library)
220
- return true if self.shelf.library == library
221
- false
222
- end
223
-
224
- def owned(patron)
225
- owns.where(:patron_id => patron.id).first
226
- end
227
-
228
- def library_url
229
- "#{LibraryGroup.site_config.url}libraries/#{self.shelf.library.name}"
230
- end
231
-
232
- def manifestation_url
233
- Addressable::URI.parse("#{LibraryGroup.site_config.url}manifestations/#{self.manifestation.id}").normalize.to_s if self.manifestation
234
- end
235
-
236
- def deletable?
237
- if circulation_status.name == 'Removed'
238
- return false
239
- else
240
- if defined?(EnjuCirculation)
241
- checkouts.not_returned.empty?
242
- else
243
- true
244
- end
245
- end
246
- end
247
- end
248
-
249
-
250
- # == Schema Information
251
- #
252
- # Table name: items
253
- #
254
- # id :integer not null, primary key
255
- # call_number :string(255)
256
- # item_identifier :string(255)
257
- # circulation_status_id :integer default(5), not null
258
- # checkout_type_id :integer default(1), not null
259
- # created_at :datetime not null
260
- # updated_at :datetime not null
261
- # deleted_at :datetime
262
- # shelf_id :integer default(1), not null
263
- # include_supplements :boolean default(FALSE), not null
264
- # checkouts_count :integer default(0), not null
265
- # owns_count :integer default(0), not null
266
- # note :text
267
- # url :string(255)
268
- # price :integer
269
- # lock_version :integer default(0), not null
270
- # required_role_id :integer default(1), not null
271
- # state :string(255)
272
- # required_score :integer default(0), not null
273
- # acquired_at :datetime
274
- # bookstore_id :integer
275
- # missing_since :datetime
276
- # budget_type_id :integer
277
- #
278
-
@@ -1,4 +0,0 @@
1
- class Language < ActiveRecord::Base
2
- has_many :manifestations
3
- has_many :patrons
4
- end
@@ -1,128 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- class Library < ActiveRecord::Base
3
- include MasterModel
4
- default_scope :order => 'libraries.position'
5
- scope :real, where('id != 1')
6
- has_many :shelves, :order => 'shelves.position'
7
- belongs_to :library_group, :validate => true
8
- has_many :events, :include => :event_category
9
- #belongs_to :holding_patron, :polymorphic => true, :validate => true
10
- belongs_to :patron #, :validate => true
11
- has_many :inter_library_loans, :foreign_key => 'borrowing_library_id'
12
- has_many :users
13
- belongs_to :country
14
-
15
- extend FriendlyId
16
- friendly_id :name
17
- #geocoded_by :address
18
-
19
- searchable do
20
- text :name, :display_name, :note, :address
21
- time :created_at
22
- time :updated_at
23
- integer :position
24
- end
25
-
26
- #validates_associated :library_group, :holding_patron
27
- validates_associated :library_group, :patron
28
- validates_presence_of :short_display_name, :library_group, :patron
29
- validates_uniqueness_of :short_display_name, :case_sensitive => false
30
- validates :display_name, :uniqueness => true
31
- validates :name, :format => {:with => /^[a-z][0-9a-z]{2,254}$/}
32
- before_validation :set_patron, :on => :create
33
- #before_save :set_calil_neighborhood_library
34
- after_validation :geocode, :if => :address_changed?
35
- after_create :create_shelf
36
- after_save :clear_all_cache
37
- after_destroy :clear_all_cache
38
-
39
- def self.per_page
40
- 10
41
- end
42
-
43
- def self.all_cache
44
- if Rails.env == 'production'
45
- Rails.cache.fetch('library_all'){Library.all}
46
- else
47
- Library.all
48
- end
49
- end
50
-
51
- def clear_all_cache
52
- Rails.cache.delete('library_all')
53
- end
54
-
55
- def set_patron
56
- self.patron = Patron.new(
57
- :full_name => self.name
58
- )
59
- end
60
-
61
- def create_shelf
62
- Shelf.create!(:name => "#{self.name}_default", :library => self)
63
- end
64
-
65
- def closed?(date)
66
- events.closing_days.collect{|c| c.start_at.beginning_of_day}.include?(date.beginning_of_day)
67
- end
68
-
69
- def web?
70
- return true if self.id == 1
71
- false
72
- end
73
-
74
- def self.web
75
- Library.find(1)
76
- end
77
-
78
- def address(locale = I18n.locale)
79
- case locale.to_sym
80
- when :ja
81
- "#{self.region.to_s.localize(locale)}#{self.locality.to_s.localize(locale)}#{self.street.to_s.localize(locale)}"
82
- else
83
- "#{self.street.to_s.localize(locale)} #{self.locality.to_s.localize(locale)} #{self.region.to_s.localize(locale)}"
84
- end
85
- rescue
86
- nil
87
- end
88
-
89
- def address_changed?
90
- return true if region_changed? or locality_changed? or street_changed?
91
- false
92
- end
93
- end
94
-
95
- # == Schema Information
96
- #
97
- # Table name: libraries
98
- #
99
- # id :integer not null, primary key
100
- # patron_id :integer
101
- # patron_type :string(255)
102
- # name :string(255) not null
103
- # display_name :text
104
- # short_display_name :string(255) not null
105
- # zip_code :string(255)
106
- # street :text
107
- # locality :text
108
- # region :text
109
- # telephone_number_1 :string(255)
110
- # telephone_number_2 :string(255)
111
- # fax_number :string(255)
112
- # note :text
113
- # call_number_rows :integer default(1), not null
114
- # call_number_delimiter :string(255) default("|"), not null
115
- # library_group_id :integer default(1), not null
116
- # users_count :integer default(0), not null
117
- # position :integer
118
- # country_id :integer
119
- # created_at :datetime
120
- # updated_at :datetime
121
- # deleted_at :datetime
122
- # opening_hour :text
123
- # latitude :float
124
- # longitude :float
125
- # calil_systemid :string(255)
126
- # calil_neighborhood_systemid :text
127
- #
128
-