enju_bookmark 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/app/models/bookmark_sweeper.rb +1 -0
  2. data/app/views/bookmark_stat_has_manifestations/index.html.erb +1 -1
  3. data/app/views/bookmark_stats/index.html.erb +1 -1
  4. data/app/views/bookmarks/_index.html.erb +1 -1
  5. data/app/views/bookmarks/_index_user.html.erb +1 -1
  6. data/app/views/bookmarks/show.html.erb +1 -1
  7. data/lib/enju_bookmark.rb +2 -2
  8. data/lib/enju_bookmark/calculate_stat.rb +30 -0
  9. data/lib/enju_bookmark/expire_tag_cloud.rb +10 -0
  10. data/lib/enju_bookmark/version.rb +1 -1
  11. data/spec/dummy/app/models/user_has_role.rb +18 -0
  12. data/spec/dummy/config/application.rb +3 -0
  13. data/spec/dummy/config/initializers/mime_types.rb +0 -1
  14. data/spec/dummy/db/migrate/001_create_patrons.rb +1 -10
  15. data/spec/dummy/db/migrate/005_create_manifestations.rb +4 -16
  16. data/spec/dummy/db/migrate/006_create_items.rb +1 -9
  17. data/spec/dummy/db/migrate/012_create_owns.rb +12 -0
  18. data/spec/dummy/db/migrate/015_create_creates.rb +12 -0
  19. data/spec/dummy/db/migrate/047_create_produces.rb +12 -0
  20. data/spec/dummy/db/migrate/059_create_libraries.rb +1 -7
  21. data/spec/dummy/db/migrate/069_create_shelves.rb +1 -5
  22. data/spec/dummy/db/migrate/073_create_carrier_types.rb +1 -5
  23. data/spec/dummy/db/migrate/{20111201163342_create_user_groups.rb → 077_create_user_groups.rb} +2 -2
  24. data/spec/dummy/db/migrate/080_create_library_groups.rb +1 -6
  25. data/spec/dummy/db/migrate/112_create_frequencies.rb +12 -0
  26. data/spec/dummy/db/migrate/117_create_form_of_works.rb +12 -0
  27. data/spec/dummy/db/migrate/124_create_bookstores.rb +17 -0
  28. data/spec/dummy/db/migrate/125_create_donates.rb +12 -0
  29. data/spec/dummy/db/migrate/130_create_request_status_types.rb +12 -0
  30. data/spec/dummy/db/migrate/131_create_request_types.rb +12 -0
  31. data/spec/dummy/db/migrate/20080830154109_create_realizes.rb +13 -0
  32. data/spec/dummy/db/migrate/20080830172106_create_exemplifies.rb +1 -7
  33. data/spec/dummy/db/migrate/20080905191442_create_patron_types.rb +1 -5
  34. data/spec/dummy/db/migrate/20081006090811_create_subscriptions.rb +17 -0
  35. data/spec/dummy/db/migrate/20081006093246_create_subscribes.rb +14 -0
  36. data/spec/dummy/db/migrate/20081023092436_create_search_engines.rb +17 -0
  37. data/spec/dummy/db/migrate/20081025083323_create_countries.rb +28 -0
  38. data/spec/dummy/db/migrate/20081025083905_create_languages.rb +1 -5
  39. data/spec/dummy/db/migrate/20081027150907_create_picture_files.rb +15 -0
  40. data/spec/dummy/db/migrate/20081028083142_create_patron_import_files.rb +22 -0
  41. data/spec/dummy/db/migrate/20081028083208_create_resource_import_files.rb +22 -0
  42. data/spec/dummy/db/migrate/20090705133942_add_attachments_picture_to_picture_file.rb +15 -0
  43. data/spec/dummy/db/migrate/20090705212043_add_attachments_attachment_to_manifestation.rb +15 -0
  44. data/spec/dummy/db/migrate/20090719201843_create_extents.rb +12 -0
  45. data/spec/dummy/db/migrate/20090720091106_create_medium_of_performances.rb +12 -0
  46. data/spec/dummy/db/migrate/20090720091429_create_content_types.rb +1 -5
  47. data/spec/dummy/db/migrate/20090812151902_create_patron_relationship_types.rb +12 -0
  48. data/spec/dummy/db/migrate/20091012101112_add_dcndl_schema.rb +27 -0
  49. data/spec/dummy/db/migrate/20091025080447_create_licenses.rb +12 -0
  50. data/spec/dummy/db/migrate/20091202124834_create_versions.rb +18 -0
  51. data/spec/dummy/db/migrate/20091214131723_create_series_statements.rb +2 -8
  52. data/spec/dummy/db/migrate/20100129142347_create_import_requests.rb +15 -0
  53. data/spec/dummy/db/migrate/20100223121519_rename_series_statement_title_to_original_title.rb +13 -0
  54. data/spec/dummy/db/migrate/20100525124311_create_manifestation_relationships.rb +13 -0
  55. data/spec/dummy/db/migrate/20100606073747_create_patron_relationships.rb +13 -0
  56. data/spec/dummy/db/migrate/20100607044753_create_manifestation_relationship_types.rb +12 -0
  57. data/spec/dummy/db/migrate/20100814091104_add_position_to_patron_relationship.rb +11 -0
  58. data/spec/dummy/db/migrate/20100925043847_create_resource_import_results.rb +15 -0
  59. data/spec/dummy/db/migrate/20100925074559_create_patron_import_results.rb +12 -0
  60. data/spec/dummy/db/migrate/20101212070145_add_acquired_at_to_item.rb +9 -0
  61. data/spec/dummy/db/migrate/20110301121550_add_birth_date_and_death_date_to_patron.rb +11 -0
  62. data/spec/dummy/db/migrate/20110603184217_add_edit_mode_to_resource_import_file.rb +9 -0
  63. data/spec/dummy/db/migrate/20110620173525_add_bookstore_id_to_item.rb +11 -0
  64. data/spec/dummy/db/migrate/20110627034940_create_series_statement_merge_lists.rb +9 -0
  65. data/spec/dummy/db/migrate/20110627035057_create_series_statement_merges.rb +12 -0
  66. data/spec/dummy/db/migrate/20110820131417_create_series_has_manifestations.rb +1 -5
  67. data/spec/dummy/db/migrate/20111009183423_add_ndc_to_manifestation.rb +9 -0
  68. data/spec/dummy/db/migrate/20111124110059_create_create_types.rb +12 -0
  69. data/spec/dummy/db/migrate/20111124110319_create_realize_types.rb +12 -0
  70. data/spec/dummy/db/migrate/20111124110355_create_produce_types.rb +12 -0
  71. data/spec/dummy/db/migrate/20111124112131_add_create_type_to_create.rb +7 -0
  72. data/spec/dummy/db/migrate/20120105074911_add_isil_to_library.rb +5 -0
  73. data/spec/dummy/db/migrate/20120125152919_add_title_subseries_transcription_to_series_statement.rb +6 -0
  74. data/spec/dummy/db/migrate/20120129014038_create_budget_types.rb +12 -0
  75. data/spec/dummy/db/migrate/20120129020544_add_budget_type_id_to_item.rb +6 -0
  76. data/spec/dummy/db/migrate/20120319120638_add_content_type_id_to_manifestation.rb +6 -0
  77. data/spec/dummy/db/migrate/20120410104851_add_year_of_publication_to_manifestation.rb +5 -0
  78. data/spec/dummy/db/migrate/20120413072700_add_picture_meta_to_picture_file.rb +5 -0
  79. data/spec/dummy/db/migrate/20120413100352_add_fingerprint_to_picture_file.rb +5 -0
  80. data/spec/dummy/db/migrate/20120413161340_add_fingerprint_to_resource_import_file.rb +5 -0
  81. data/spec/dummy/db/migrate/20120413161403_add_fingerprint_to_patron_import_file.rb +5 -0
  82. data/spec/dummy/db/migrate/20120413170705_add_error_message_to_resource_import_file.rb +5 -0
  83. data/spec/dummy/db/migrate/20120413170720_add_error_message_to_patron_import_file.rb +5 -0
  84. data/spec/dummy/db/migrate/20120415060308_rename_resource_import_file_imported_at_to_executed_at.rb +9 -0
  85. data/spec/dummy/db/migrate/20120415060323_rename_patron_import_file_imported_at_to_executed_at.rb +9 -0
  86. data/spec/dummy/db/migrate/20120415164821_add_attachment_meta_to_manifestation.rb +5 -0
  87. data/spec/dummy/db/migrate/20120418081407_add_month_of_publication_to_manifestation.rb +5 -0
  88. data/spec/dummy/db/migrate/20120510140958_add_closed_to_shelf.rb +5 -0
  89. data/spec/dummy/db/migrate/20120602141129_add_edit_mode_to_patron_import_file.rb +5 -0
  90. data/spec/dummy/db/schema.rb +520 -106
  91. data/spec/dummy/db/test.sqlite3 +0 -0
  92. data/spec/fixtures/libraries.yml +0 -5
  93. metadata +141 -139
  94. data/lib/enju_bookmark/master_model.rb +0 -41
  95. data/lib/enju_bookmark/url_validator.rb +0 -10
  96. data/spec/dummy/app/models/bookstore.rb +0 -31
  97. data/spec/dummy/app/models/carrier_type.rb +0 -33
  98. data/spec/dummy/app/models/exemplify.rb +0 -45
  99. data/spec/dummy/app/models/item.rb +0 -121
  100. data/spec/dummy/app/models/language.rb +0 -4
  101. data/spec/dummy/app/models/library.rb +0 -128
  102. data/spec/dummy/app/models/library_group.rb +0 -86
  103. data/spec/dummy/app/models/manifestation.rb +0 -396
  104. data/spec/dummy/app/models/patron.rb +0 -168
  105. data/spec/dummy/app/models/patron_type.rb +0 -19
  106. data/spec/dummy/app/models/series_has_manifestation.rb +0 -35
  107. data/spec/dummy/app/models/series_statement.rb +0 -88
  108. data/spec/dummy/app/models/shelf.rb +0 -54
@@ -1,396 +0,0 @@
1
- class Manifestation < ActiveRecord::Base
2
- scope :periodical_master, where(:periodical => false)
3
- scope :periodical_children, where(:periodical => true)
4
- has_many :creates, :dependent => :destroy, :foreign_key => 'work_id'
5
- has_many :creators, :through => :creates, :source => :patron
6
- has_many :realizes, :dependent => :destroy, :foreign_key => 'expression_id'
7
- has_many :contributors, :through => :realizes, :source => :patron
8
- has_many :produces, :dependent => :destroy, :foreign_key => 'manifestation_id'
9
- has_many :publishers, :through => :produces, :source => :patron
10
- has_many :exemplifies, :foreign_key => 'manifestation_id'
11
- has_many :items, :through => :exemplifies #, :foreign_key => 'manifestation_id'
12
- has_many :children, :foreign_key => 'parent_id', :class_name => 'ManifestationRelationship', :dependent => :destroy
13
- has_many :parents, :foreign_key => 'child_id', :class_name => 'ManifestationRelationship', :dependent => :destroy
14
- has_many :derived_manifestations, :through => :children, :source => :child
15
- has_many :original_manifestations, :through => :parents, :source => :parent
16
- has_many :picture_files, :as => :picture_attachable, :dependent => :destroy
17
- belongs_to :language
18
- belongs_to :carrier_type
19
- belongs_to :content_type
20
- has_one :series_has_manifestation, :dependent => :destroy
21
- has_one :series_statement, :through => :series_has_manifestation
22
- belongs_to :manifestation_relationship_type
23
- belongs_to :frequency
24
- belongs_to :required_role, :class_name => 'Role', :foreign_key => 'required_role_id', :validate => true
25
- has_one :resource_import_result
26
-
27
- searchable do
28
- text :title, :default_boost => 2 do
29
- titles
30
- end
31
- text :fulltext, :note, :creator, :contributor, :publisher, :description
32
- string :title, :multiple => true
33
- # text フィールドだと区切りのない文字列の index が上手く作成
34
- #できなかったので。 downcase することにした。
35
- #他の string 項目も同様の問題があるので、必要な項目は同様の処置が必要。
36
- string :connect_title do
37
- title.join('').gsub(/\s/, '').downcase
38
- end
39
- string :connect_creator do
40
- creator.join('').gsub(/\s/, '').downcase
41
- end
42
- string :connect_publisher do
43
- publisher.join('').gsub(/\s/, '').downcase
44
- end
45
- string :isbn, :multiple => true do
46
- [isbn, isbn10, wrong_isbn]
47
- end
48
- string :issn
49
- string :lccn
50
- string :nbn
51
- string :carrier_type do
52
- carrier_type.name
53
- end
54
- string :library, :multiple => true do
55
- items.map{|i| i.shelf.library.name}
56
- end
57
- string :language do
58
- language.try(:name)
59
- end
60
- string :item_identifier, :multiple => true do
61
- items.collect(&:item_identifier)
62
- end
63
- string :shelf, :multiple => true do
64
- items.collect{|i| "#{i.shelf.library.name}_#{i.shelf.name}"}
65
- end
66
- time :created_at
67
- time :updated_at
68
- time :deleted_at
69
- time :date_of_publication
70
- integer :creator_ids, :multiple => true
71
- integer :contributor_ids, :multiple => true
72
- integer :publisher_ids, :multiple => true
73
- integer :item_ids, :multiple => true
74
- integer :original_manifestation_ids, :multiple => true
75
- integer :required_role_id
76
- integer :height
77
- integer :width
78
- integer :depth
79
- integer :volume_number, :multiple => true
80
- integer :issue_number, :multiple => true
81
- integer :serial_number, :multiple => true
82
- integer :start_page
83
- integer :end_page
84
- integer :number_of_pages
85
- float :price
86
- integer :series_statement_id do
87
- series_has_manifestation.try(:series_statement_id)
88
- end
89
- boolean :repository_content
90
- # for OpenURL
91
- text :aulast do
92
- creators.map{|creator| creator.last_name}
93
- end
94
- text :aufirst do
95
- creators.map{|creator| creator.first_name}
96
- end
97
- # OTC start
98
- string :creator, :multiple => true do
99
- creator.map{|au| au.gsub(' ', '')}
100
- end
101
- text :au do
102
- creator
103
- end
104
- text :atitle do
105
- title if original_manifestations.present? # 親がいることが条件
106
- end
107
- text :btitle do
108
- title if frequency_id == 1 # 発行頻度1が単行本
109
- end
110
- text :jtitle do
111
- if frequency_id != 1 # 雑誌の場合
112
- title
113
- else # 雑誌以外(雑誌の記事も含む)
114
- titles = []
115
- original_manifestations.each do |m|
116
- if m.frequency_id != 1
117
- titles << m.title
118
- end
119
- end
120
- titles.flatten
121
- end
122
- end
123
- text :isbn do # 前方一致検索のためtext指定を追加
124
- [isbn, isbn10, wrong_isbn]
125
- end
126
- text :issn # 前方一致検索のためtext指定を追加
127
- #text :ndl_jpno do
128
- # TODO 詳細不明
129
- #end
130
- #string :ndl_dpid do
131
- # TODO 詳細不明
132
- #end
133
- # OTC end
134
- string :sort_title
135
- boolean :periodical do
136
- periodical?
137
- end
138
- boolean :periodical_master do
139
- periodical_master?
140
- end
141
- time :acquired_at
142
- end
143
-
144
- validates_presence_of :original_title, :carrier_type, :language
145
- validates_associated :carrier_type, :language
146
- validates :start_page, :numericality => true, :allow_blank => true
147
- validates :end_page, :numericality => true, :allow_blank => true
148
- validates :manifestation_identifier, :uniqueness => true, :allow_blank => true
149
- validates :pub_date, :format => {:with => /^\d+(-\d{0,2}){0,2}$/}, :allow_blank => true
150
- validates :access_address, :url => true, :allow_blank => true, :length => {:maximum => 255}
151
- validates :issue_number, :numericality => {:greater_than => 0}, :allow_blank => true
152
- validates :volume_number, :numericality => {:greater_than => 0}, :allow_blank => true
153
- validates :serial_number, :numericality => {:greater_than => 0}, :allow_blank => true
154
- validates :edition, :numericality => {:greater_than => 0}, :allow_blank => true
155
- before_validation :set_wrong_isbn, :check_issn, :check_lccn, :if => :during_import
156
- after_create :clear_cached_numdocs
157
- before_save :set_date_of_publication
158
- before_save :set_periodical
159
- after_save :index_series_statement
160
- after_destroy :index_series_statement
161
- normalize_attributes :manifestation_identifier, :pub_date, :isbn, :issn, :nbn, :lccn, :original_title
162
- attr_accessor :during_import, :series_statement_id
163
-
164
- def self.per_page
165
- 10
166
- end
167
-
168
- def set_date_of_publication
169
- return if pub_date.blank?
170
- begin
171
- date = Time.zone.parse("#{pub_date}")
172
- rescue ArgumentError
173
- begin
174
- date = Time.zone.parse("#{pub_date}-01")
175
- rescue ArgumentError
176
- begin
177
- date = Time.zone.parse("#{pub_date}-01-01")
178
- rescue ArgumentError
179
- nil
180
- end
181
- end
182
- end
183
- self.date_of_publication = date
184
- end
185
-
186
- def self.cached_numdocs
187
- Rails.cache.fetch("manifestation_search_total"){Manifestation.search.total}
188
- end
189
-
190
- def clear_cached_numdocs
191
- Rails.cache.delete("manifestation_search_total")
192
- end
193
-
194
- def parent_of_series
195
- original_manifestations
196
- end
197
-
198
- def serial?
199
- if new_record?
200
- if SeriesStatement.where(:id => series_statement_id).first.try(:periodical)
201
- return true
202
- end
203
- else
204
- if series_statement.try(:periodical)
205
- return true
206
- elsif periodical?
207
- return true unless series_statement.try(:root_manifestation) == self
208
- end
209
- end
210
- false
211
- end
212
-
213
- def number_of_pages
214
- if self.start_page and self.end_page
215
- page = self.end_page.to_i - self.start_page.to_i + 1
216
- end
217
- end
218
-
219
- def titles
220
- title = []
221
- title << original_title.to_s.strip
222
- title << title_transcription.to_s.strip
223
- title << title_alternative.to_s.strip
224
- title << volume_number_string
225
- title << issue_number_string
226
- title << serial_number.to_s
227
- title << edition_string
228
- title << series_statement.titles if series_statement
229
- #title << original_title.wakati
230
- #title << title_transcription.wakati rescue nil
231
- #title << title_alternative.wakati rescue nil
232
- title.flatten
233
- end
234
-
235
- def url
236
- #access_address
237
- "#{LibraryGroup.site_config.url}#{self.class.to_s.tableize}/#{self.id}"
238
- end
239
-
240
- def set_serial_information
241
- return nil unless periodical?
242
- if new_record?
243
- series_statement = SeriesStatement.where(:id => series_statement_id).first
244
- manifestation = series_statement.try(:last_issue)
245
- else
246
- manifestation = series_statement.try(:last_issue)
247
- end
248
- if manifestation
249
- self.original_title = manifestation.original_title
250
- self.title_transcription = manifestation.title_transcription
251
- self.title_alternative = manifestation.title_alternative
252
- self.issn = series_statement.issn
253
- # TODO: 雑誌ごとに巻・号・通号のパターンを設定できるようにする
254
- if manifestation.serial_number.to_i > 0
255
- self.serial_number = manifestation.serial_number.to_i + 1
256
- if manifestation.issue_number.to_i > 0
257
- self.issue_number = manifestation.issue_number.to_i + 1
258
- else
259
- self.issue_number = manifestation.issue_number
260
- end
261
- self.volume_number = manifestation.volume_number
262
- else
263
- if manifestation.issue_number.to_i > 0
264
- self.issue_number = manifestation.issue_number.to_i + 1
265
- self.volume_number = manifestation.volume_number
266
- else
267
- if manifestation.volume_number.to_i > 0
268
- self.volume_number = manifestation.volume_number.to_i + 1
269
- end
270
- end
271
- end
272
- end
273
- self
274
- end
275
-
276
- def creator
277
- creators.collect(&:name).flatten
278
- end
279
-
280
- def contributor
281
- contributors.collect(&:name).flatten
282
- end
283
-
284
- def publisher
285
- publishers.collect(&:name).flatten
286
- end
287
-
288
- def title
289
- titles
290
- end
291
-
292
- # TODO: よりよい推薦方法
293
- def self.pickup(keyword = nil)
294
- return nil if self.cached_numdocs < 5
295
- manifestation = nil
296
- # TODO: ヒット件数が0件のキーワードがあるときに指摘する
297
- response = Manifestation.search(:include => [:creators, :contributors, :publishers, :items]) do
298
- fulltext keyword if keyword
299
- order_by(:random)
300
- paginate :page => 1, :per_page => 1
301
- end
302
- manifestation = response.results.first
303
- end
304
-
305
- def created(patron)
306
- creates.where(:patron_id => patron.id).first
307
- end
308
-
309
- def realized(patron)
310
- realizes.where(:patron_id => patron.id).first
311
- end
312
-
313
- def produced(patron)
314
- produces.where(:patron_id => patron.id).first
315
- end
316
-
317
- def sort_title
318
- NKF.nkf('-w --katakana', title_transcription) if title_transcription
319
- end
320
-
321
- def self.find_by_isbn(isbn)
322
- if ISBN_Tools.is_valid?(isbn)
323
- ISBN_Tools.cleanup!(isbn)
324
- if isbn.size == 10
325
- Manifestation.where(:isbn => ISBN_Tools.isbn10_to_isbn13(isbn)).first || Manifestation.where(:isbn => isbn).first
326
- else
327
- Manifestation.where(:isbn => isbn).first || Manifestation.where(:isbn => ISBN_Tools.isbn13_to_isbn10(isbn)).first
328
- end
329
- end
330
- end
331
-
332
- def index_series_statement
333
- series_statement.try(:index)
334
- end
335
-
336
- def acquired_at
337
- items.order(:acquired_at).first.try(:acquired_at)
338
- end
339
-
340
- def set_periodical
341
- unless series_statement
342
- series_statement = SeriesStatement.where(:id => series_statement_id).first
343
- end
344
- end
345
-
346
- def root_of_series?
347
- return true if series_statement.try(:root_manifestation) == self
348
- false
349
- end
350
-
351
- def periodical_master?
352
- if series_statement
353
- return true if series_statement.periodical and root_of_series?
354
- end
355
- false
356
- end
357
-
358
- def periodical?
359
- if self.new_record?
360
- series_statement = SeriesStatement.where(:id => series_statement_id).first
361
- end
362
- if series_statement.try(:periodical)
363
- return true unless root_of_series?
364
- end
365
- false
366
- end
367
-
368
- def web_item
369
- items.where(:shelf_id => Shelf.web.id).first
370
- end
371
-
372
- has_many :bookmarks, :include => :tags, :dependent => :destroy, :foreign_key => :manifestation_id
373
- has_many :users, :through => :bookmarks
374
-
375
- searchable do
376
- string :tag, :multiple => true do
377
- tags.collect(&:name)
378
- end
379
- text :tag do
380
- tags.collect(&:name)
381
- end
382
- end
383
-
384
- def bookmarked?(user)
385
- return true if user.bookmarks.where(:url => url).first
386
- false
387
- end
388
-
389
- def tags
390
- if self.bookmarks.first
391
- self.bookmarks.tag_counts
392
- else
393
- []
394
- end
395
- end
396
- end
@@ -1,168 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- class Patron < ActiveRecord::Base
3
- scope :readable_by, lambda{|user| {:conditions => ['required_role_id <= ?', user.try(:user_has_role).try(:role_id) || Role.where(:name => 'Guest').select(:id).first.id]}}
4
- belongs_to :user
5
- belongs_to :patron_type
6
- belongs_to :required_role, :class_name => 'Role', :foreign_key => 'required_role_id', :validate => true
7
- belongs_to :language
8
-
9
- validates_presence_of :language, :patron_type
10
- validates_associated :language, :patron_type
11
- validates :full_name, :presence => true, :length => {:maximum => 255}
12
- validates :user_id, :uniqueness => true, :allow_nil => true
13
- validates :email, :format => {:with => /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i}, :allow_blank => true
14
- before_validation :set_role_and_name, :on => :create
15
-
16
- #has_paper_trail
17
- attr_accessor :user_username
18
- #[:address_1, :address_2].each do |column|
19
- # encrypt_with_public_key column,
20
- # :key_pair => File.join(Rails.root.to_s,'config','keypair.pem'),
21
- # :base64 => true
22
- #end
23
-
24
- searchable do
25
- text :name, :place, :address_1, :address_2, :other_designation, :note
26
- string :zip_code_1
27
- string :zip_code_2
28
- string :username do
29
- user.username if user
30
- end
31
- time :created_at
32
- time :updated_at
33
- string :user
34
- integer :work_ids, :multiple => true
35
- integer :expression_ids, :multiple => true
36
- integer :manifestation_ids, :multiple => true
37
- integer :patron_merge_list_ids, :multiple => true if defined?(EnjuResourceMerge)
38
- integer :original_patron_ids, :multiple => true
39
- integer :required_role_id
40
- integer :patron_type_id
41
- end
42
-
43
- def self.per_page
44
- 10
45
- end
46
-
47
- def full_name_without_space
48
- full_name.gsub(/\s/, "")
49
- end
50
-
51
- def set_role_and_name
52
- self.required_role = Role.where(:name => 'Librarian').first if self.required_role_id.nil?
53
- set_full_name
54
- end
55
-
56
- def set_full_name
57
- if self.full_name.blank?
58
- if self.last_name.to_s.strip and self.first_name.to_s.strip and configatron.family_name_first == true
59
- self.full_name = [last_name, middle_name, first_name].compact.join(" ").to_s.strip
60
- else
61
- self.full_name = [first_name, last_name, middle_name].compact.join(" ").to_s.strip
62
- end
63
- end
64
- if self.full_name_transcription.blank?
65
- self.full_name_transcription = [last_name_transcription, middle_name_transcription, first_name_transcription].join(" ").to_s.strip
66
- end
67
- [self.full_name, self.full_name_transcription]
68
- end
69
-
70
- def full_name_without_space
71
- full_name.gsub(/\s/, "")
72
- # # TODO: 日本人以外は?
73
- # name = []
74
- # name << self.last_name.to_s.strip
75
- # name << self.middle_name.to_s.strip
76
- # name << self.first_name.to_s.strip
77
- # name << self.corporate_name.to_s.strip
78
- # name.join("").strip
79
- end
80
-
81
- def full_name_transcription_without_space
82
- full_name_transcription.to_s.gsub(/\s/, "")
83
- end
84
-
85
- def full_name_alternative_without_space
86
- full_name_alternative.to_s.gsub(/\s/, "")
87
- end
88
-
89
- def name
90
- name = []
91
- name << full_name.to_s.strip
92
- name << full_name_transcription.to_s.strip
93
- name << full_name_alternative.to_s.strip
94
- #name << full_name_without_space
95
- #name << full_name_transcription_without_space
96
- #name << full_name_alternative_without_space
97
- #name << full_name.wakati rescue nil
98
- #name << full_name_transcription.wakati rescue nil
99
- #name << full_name_alternative.wakati rescue nil
100
- name
101
- end
102
-
103
- def date
104
- if date_of_birth
105
- if date_of_death
106
- "#{date_of_birth} - #{date_of_death}"
107
- else
108
- "#{date_of_birth} -"
109
- end
110
- end
111
- end
112
-
113
- def creator?(resource)
114
- resource.creators.include?(self)
115
- end
116
-
117
- def publisher?(resource)
118
- resource.publishers.include?(self)
119
- end
120
-
121
- def check_required_role(user)
122
- return true if self.user.blank?
123
- return true if self.user.required_role.name == 'Guest'
124
- return true if user == self.user
125
- return true if user.has_role?(self.user.required_role.name)
126
- false
127
- rescue NoMethodError
128
- false
129
- end
130
-
131
- def created(work)
132
- creates.where(:work_id => work.id).first
133
- end
134
-
135
- def realized(expression)
136
- realizes.where(:expression_id => expression.id).first
137
- end
138
-
139
- def produced(manifestation)
140
- produces.where(:manifestation_id => manifestation.id).first
141
- end
142
-
143
- def owned(item)
144
- owns.where(:item_id => item.id)
145
- end
146
-
147
- def self.import_patrons(patron_lists)
148
- list = []
149
- patron_lists.each do |patron_list|
150
- patron = Patron.where(:full_name => patron_list[:full_name]).first
151
- unless patron
152
- patron = Patron.new(
153
- :full_name => patron_list[:full_name],
154
- :full_name_transcription => patron_list[:full_name_transcription],
155
- :language_id => 1
156
- )
157
- patron.required_role = Role.where(:name => 'Guest').first
158
- patron.save
159
- end
160
- list << patron
161
- end
162
- list
163
- end
164
-
165
- def patrons
166
- self.original_patrons + self.derived_patrons
167
- end
168
- end