[Bugfix] Conference methods related to weeks now database independent
This commit is contained in:
parent
fd95570c02
commit
596027e49b
6 changed files with 55 additions and 4 deletions
|
|
@ -179,7 +179,7 @@ class Conference < ActiveRecord::Base
|
|||
result = []
|
||||
|
||||
if call_for_papers && events
|
||||
submissions = events.group("strftime('%W', created_at)").count
|
||||
submissions = events.group(:week).count
|
||||
start_week = call_for_papers.start_week
|
||||
weeks = call_for_papers.weeks
|
||||
result = calculate_items_per_week(start_week, weeks, submissions)
|
||||
|
|
@ -196,7 +196,7 @@ class Conference < ActiveRecord::Base
|
|||
result = []
|
||||
|
||||
if call_for_papers && events
|
||||
submissions = events.where('state = ?', state).group("strftime('%W', created_at)").count
|
||||
submissions = events.where('state = ?', state).group(:week).count
|
||||
start_week = call_for_papers.start_week
|
||||
weeks = call_for_papers.weeks
|
||||
result = calculate_items_per_week(start_week, weeks, submissions)
|
||||
|
|
@ -216,7 +216,7 @@ class Conference < ActiveRecord::Base
|
|||
registration_start_date &&
|
||||
registration_end_date
|
||||
|
||||
reg = registrations.group("strftime('%W', created_at)").count
|
||||
reg = registrations.group(:week).count
|
||||
start_week = get_registration_start_week
|
||||
weeks = registration_weeks
|
||||
result = calculate_items_per_week(start_week, weeks, reg)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ class Event < ActiveRecord::Base
|
|||
|
||||
acts_as_commentable
|
||||
|
||||
after_create :set_week
|
||||
|
||||
has_many :event_people, :dependent => :destroy
|
||||
has_many :event_attachments, :dependent => :destroy
|
||||
has_many :people, :through => :event_people
|
||||
|
|
@ -203,4 +205,8 @@ class Event < ActiveRecord::Base
|
|||
self.guid = guid
|
||||
end
|
||||
|
||||
def set_week
|
||||
self.week = created_at.strftime('%W')
|
||||
save!
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,7 +34,16 @@ class Registration < ActiveRecord::Base
|
|||
|
||||
alias_attribute :other_needs, :other_special_needs
|
||||
|
||||
after_create :set_week
|
||||
|
||||
def week
|
||||
created_at.strftime('%W').to_i
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_week
|
||||
self.week = created_at.strftime('%W')
|
||||
save!
|
||||
end
|
||||
end
|
||||
|
|
|
|||
17
db/migrate/20140625112608_add_week_to_event.rb
Normal file
17
db/migrate/20140625112608_add_week_to_event.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
class AddWeekToEvent < ActiveRecord::Migration
|
||||
class Event < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def up
|
||||
add_column :events, :week, :integer
|
||||
Event.reset_column_information
|
||||
Event.find_each do |event|
|
||||
event.week = event.created_at.strftime('%W')
|
||||
event.save!
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :events, :week
|
||||
end
|
||||
end
|
||||
17
db/migrate/20140625114813_add_week_to_registration.rb
Normal file
17
db/migrate/20140625114813_add_week_to_registration.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
class AddWeekToRegistration < ActiveRecord::Migration
|
||||
class Registration < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def up
|
||||
add_column :registrations, :week, :integer
|
||||
Registration.reset_column_information
|
||||
Registration.find_each do |registration|
|
||||
registration.week = registration.created_at.strftime('%W')
|
||||
registration.save!
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :registrations, :week
|
||||
end
|
||||
end
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20140623101032) do
|
||||
ActiveRecord::Schema.define(version: 20140625114813) do
|
||||
|
||||
create_table "ahoy_events", force: true do |t|
|
||||
t.uuid "visit_id"
|
||||
|
|
@ -224,6 +224,7 @@ ActiveRecord::Schema.define(version: 20140623101032) do
|
|||
t.string "media_type"
|
||||
t.boolean "require_registration"
|
||||
t.integer "difficulty_level_id"
|
||||
t.integer "week"
|
||||
end
|
||||
|
||||
create_table "events_registrations", id: false, force: true do |t|
|
||||
|
|
@ -328,6 +329,7 @@ ActiveRecord::Schema.define(version: 20140623101032) do
|
|||
t.text "other_special_needs"
|
||||
t.boolean "attended", default: false
|
||||
t.boolean "volunteer"
|
||||
t.integer "week"
|
||||
end
|
||||
|
||||
create_table "registrations_social_events", id: false, force: true do |t|
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue