enju_circulation 0.0.63 → 0.0.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,8 +46,8 @@ class BasketsController < ApplicationController
46
46
  # POST /baskets
47
47
  # POST /baskets.json
48
48
  def create
49
- @basket = Basket.new
50
- @user = User.where(:user_number => params[:basket][:user_number]).first rescue nil
49
+ @basket = Basket.new(params[:basket])
50
+ @user = User.where(:user_number => @basket.user_number).first if @basket.user_number
51
51
  if @user
52
52
  if @user.user_number?
53
53
  @basket.user = @user
@@ -81,7 +81,6 @@ class BasketsController < ApplicationController
81
81
  return
82
82
  end
83
83
 
84
- #@checkout_count = @basket.user.checkouts.count
85
84
  respond_to do |format|
86
85
  #if @basket.update_attributes({})
87
86
  if @basket.save(:validate => false)
@@ -0,0 +1,65 @@
1
+ module EnjuCirculation
2
+ module User
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ def enju_circulation_user
9
+ include InstanceMethods
10
+ attr_accessible :save_checkout_history, :checkout_icalendar_token
11
+ attr_accessible :save_checkout_history, :checkout_icalendar_token,
12
+ :as => :admin
13
+
14
+ has_many :checkouts, :dependent => :nullify
15
+ has_many :reserves, :dependent => :destroy
16
+ has_many :reserved_manifestations, :through => :reserves, :source => :manifestation
17
+ has_many :checkout_stat_has_users
18
+ has_many :user_checkout_stats, :through => :checkout_stat_has_users
19
+ has_many :reserve_stat_has_users
20
+ has_many :user_reserve_stats, :through => :reserve_stat_has_users
21
+ has_many :baskets, :dependent => :destroy
22
+
23
+ before_destroy :check_item_before_destroy
24
+ end
25
+ end
26
+
27
+ module InstanceMethods
28
+ def check_item_before_destroy
29
+ # TODO: 貸出記録を残す場合
30
+ if checkouts.size > 0
31
+ raise 'This user has items still checked out.'
32
+ end
33
+ end
34
+
35
+ def reset_checkout_icalendar_token
36
+ self.checkout_icalendar_token = Devise.friendly_token
37
+ end
38
+
39
+ def delete_checkout_icalendar_token
40
+ self.checkout_icalendar_token = nil
41
+ end
42
+
43
+ def checked_item_count
44
+ checkout_count = {}
45
+ CheckoutType.all.each do |checkout_type|
46
+ # 資料種別ごとの貸出中の冊数を計算
47
+ checkout_count[:"#{checkout_type.name}"] = self.checkouts.count_by_sql(["
48
+ SELECT count(item_id) FROM checkouts
49
+ WHERE item_id IN (
50
+ SELECT id FROM items
51
+ WHERE checkout_type_id = ?
52
+ )
53
+ AND user_id = ? AND checkin_id IS NULL", checkout_type.id, self.id]
54
+ )
55
+ end
56
+ return checkout_count
57
+ end
58
+
59
+ def reached_reservation_limit?(manifestation)
60
+ return true if user_group.user_group_has_checkout_types.available_for_carrier_type(manifestation.carrier_type).where(:user_group_id => user_group.id).collect(&:reservation_limit).max.to_i <= reserves.waiting.size
61
+ false
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1,3 +1,3 @@
1
1
  module EnjuCirculation
2
- VERSION = "0.0.63"
2
+ VERSION = "0.0.64"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require "enju_circulation/engine"
2
2
  require "enju_circulation/manifestation"
3
+ require "enju_circulation/user"
3
4
  require "enju_circulation/controller"
4
5
 
5
6
  module EnjuCirculation
@@ -7,3 +8,4 @@ end
7
8
 
8
9
  ActionController::Base.send :include, EnjuCirculation::Controller
9
10
  ActiveRecord::Base.send :include, EnjuCirculation::Manifestation
11
+ ActiveRecord::Base.send :include, EnjuCirculation::User
@@ -12,56 +12,11 @@ class User < ActiveRecord::Base
12
12
  has_one :role, :through => :user_has_role
13
13
  belongs_to :user_group
14
14
  belongs_to :required_role, :class_name => 'Role', :foreign_key => 'required_role_id'
15
- has_many :checkouts, :dependent => :nullify
16
- has_many :reserves, :dependent => :destroy
17
- has_many :reserved_manifestations, :through => :reserves, :source => :manifestation
18
- has_many :checkout_stat_has_users
19
- has_many :user_checkout_stats, :through => :checkout_stat_has_users
20
- has_many :reserve_stat_has_users
21
- has_many :user_reserve_stats, :through => :reserve_stat_has_users
22
- has_many :baskets, :dependent => :destroy
23
15
  belongs_to :library
24
16
 
25
- before_destroy :check_item_before_destroy
26
-
27
17
  extend FriendlyId
28
18
  friendly_id :username
29
-
30
- def check_item_before_destroy
31
- # TODO: 貸出記録を残す場合
32
- if checkouts.size > 0
33
- raise 'This user has items still checked out.'
34
- end
35
- end
36
-
37
- def reset_checkout_icalendar_token
38
- self.checkout_icalendar_token = Devise.friendly_token
39
- end
40
-
41
- def delete_checkout_icalendar_token
42
- self.checkout_icalendar_token = nil
43
- end
44
-
45
- def checked_item_count
46
- checkout_count = {}
47
- CheckoutType.all.each do |checkout_type|
48
- # 資料種別ごとの貸出中の冊数を計算
49
- checkout_count[:"#{checkout_type.name}"] = self.checkouts.count_by_sql(["
50
- SELECT count(item_id) FROM checkouts
51
- WHERE item_id IN (
52
- SELECT id FROM items
53
- WHERE checkout_type_id = ?
54
- )
55
- AND user_id = ? AND checkin_id IS NULL", checkout_type.id, self.id]
56
- )
57
- end
58
- return checkout_count
59
- end
60
-
61
- def reached_reservation_limit?(manifestation)
62
- return true if self.user_group.user_group_has_checkout_types.available_for_carrier_type(manifestation.carrier_type).where(:user_group_id => self.user_group.id).collect(&:reservation_limit).max.to_i <= self.reserves.waiting.size
63
- false
64
- end
19
+ enju_circulation_user
65
20
 
66
21
  def has_role?(role_in_question)
67
22
  return false unless role
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enju_circulation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.63
4
+ version: 0.0.64
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -450,6 +450,7 @@ files:
450
450
  - lib/enju_circulation/controller.rb
451
451
  - lib/enju_circulation/engine.rb
452
452
  - lib/enju_circulation/manifestation.rb
453
+ - lib/enju_circulation/user.rb
453
454
  - lib/enju_circulation/version.rb
454
455
  - lib/enju_circulation.rb
455
456
  - lib/tasks/enju_circulation_tasks.rake