Introduce Program to include cfp/rooms/tracks/events/event_types/difficulty_levels
This commit is contained in:
parent
028b82fda8
commit
444356fbc7
117 changed files with 1812 additions and 905 deletions
|
|
@ -39,7 +39,7 @@ class Ability
|
|||
end
|
||||
# Can view the schedule
|
||||
can [:schedule], Conference do |conference|
|
||||
conference.call_for_paper && conference.call_for_paper.schedule_public
|
||||
conference.program.cfp && conference.program.schedule_public
|
||||
end
|
||||
|
||||
can :show, Event do |event|
|
||||
|
|
@ -53,9 +53,13 @@ class Ability
|
|||
can [:show, :create], Registration do |registration|
|
||||
registration.new_record?
|
||||
end
|
||||
can [:show, :create], Event do |event|
|
||||
can :show, Event do |event|
|
||||
event.new_record?
|
||||
end
|
||||
|
||||
can [:new, :create], Event do |event|
|
||||
event.program.cfp_open? && event.new_record?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -77,7 +81,7 @@ class Ability
|
|||
event.users.include?(user)
|
||||
end
|
||||
# can create an event until the last day of a conference
|
||||
can :create, Event, conference_id: Conference.where('end_date >= ?', Date.today).pluck(:id)
|
||||
can :create, Event, program_id: Conference.where('end_date >= ?', Date.today).map { |conference| conference.program.id}.compact
|
||||
|
||||
# can manage the commercials of their own events
|
||||
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id)
|
||||
|
|
@ -100,6 +104,8 @@ class Ability
|
|||
cannot [:edit, :update, :destroy], Question, global: true
|
||||
# for admins
|
||||
can :manage, :all if user.is_admin
|
||||
|
||||
cannot :destroy, Program
|
||||
end
|
||||
|
||||
def signed_in_with_organizer_role(user)
|
||||
|
|
@ -125,21 +131,22 @@ class Ability
|
|||
end
|
||||
can :manage, Vposition, conference_id: conf_ids_for_organizer
|
||||
can :manage, Vday, conference_id: conf_ids_for_organizer
|
||||
can :manage, CallForPaper, conference_id: conf_ids_for_organizer
|
||||
can :manage, Event, conference_id: conf_ids_for_organizer
|
||||
can :manage, EventType, conference_id: conf_ids_for_organizer
|
||||
can :manage, Track, conference_id: conf_ids_for_organizer
|
||||
can :manage, DifficultyLevel, conference_id: conf_ids_for_organizer
|
||||
can :manage, Program, conference_id: conf_ids_for_organizer
|
||||
can :manage, Cfp, program: { conference_id: conf_ids_for_organizer}
|
||||
can :manage, Event, program: { conference_id: conf_ids_for_organizer}
|
||||
can :manage, EventType, program: { conference_id: conf_ids_for_organizer}
|
||||
can :manage, Track, program: { conference_id: conf_ids_for_organizer}
|
||||
can :manage, DifficultyLevel, program: { conference_id: conf_ids_for_organizer}
|
||||
can :manage, Commercial, commercialable_type: 'Event',
|
||||
commercialable_id: Event.where(conference_id: conf_ids_for_organizer).pluck(:id)
|
||||
commercialable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organizer).pluck(:id)).pluck(:id)
|
||||
can :manage, Venue, conference_id: conf_ids_for_organizer
|
||||
can :manage, Lodging, conference_id: conf_ids_for_organizer
|
||||
can :manage, Room, conference_id: conf_ids_for_organizer
|
||||
can :manage, Room, program: { conference_id: conf_ids_for_organizer}
|
||||
can :manage, Sponsor, conference_id: conf_ids_for_organizer
|
||||
can :manage, SponsorshipLevel, conference_id: conf_ids_for_organizer
|
||||
can :manage, Ticket, conference_id: conf_ids_for_organizer
|
||||
can :index, Comment, commentable_type: 'Event',
|
||||
commentable_id: Event.where(conference_id: conf_ids_for_organizer).pluck(:id)
|
||||
commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organizer).pluck(:id)).pluck(:id)
|
||||
end
|
||||
|
||||
def signed_in_with_cfp_role(user)
|
||||
|
|
@ -148,18 +155,19 @@ class Ability
|
|||
conf_ids_for_cfp =
|
||||
Conference.with_role(:cfp, user).pluck(:id) if user.has_role? :cfp, :any
|
||||
|
||||
can :manage, Event, conference_id: conf_ids_for_cfp
|
||||
can :manage, EventType, conference_id: conf_ids_for_cfp
|
||||
can :manage, Track, conference_id: conf_ids_for_cfp
|
||||
can :manage, DifficultyLevel, conference_id: conf_ids_for_cfp
|
||||
can :manage, Event, program: { conference_id: conf_ids_for_cfp }
|
||||
can :manage, EventType, program: { conference_id: conf_ids_for_cfp }
|
||||
can :manage, Track, program: { conference_id: conf_ids_for_cfp }
|
||||
can :manage, DifficultyLevel, program: { conference_id: conf_ids_for_cfp }
|
||||
can :manage, EmailSettings, conference_id: conf_ids_for_cfp
|
||||
can :manage, Room, conference_id: conf_ids_for_cfp
|
||||
can :show, Venue, conference_id: conf_ids_for_cfp
|
||||
can :manage, CallForPaper, conference_id: conf_ids_for_cfp
|
||||
can :manage, Room, program: { conference_id: conf_ids_for_cfp }
|
||||
can :index, Venue, conference_id: conf_ids_for_cfp
|
||||
can :manage, Cfp, program: { conference_id: conf_ids_for_cfp }
|
||||
can :manage, Program, conference_id: conf_ids_for_cfp
|
||||
can :manage, Commercial, commercialable_type: 'Event',
|
||||
commercialable_id: Event.where(conference_id: conf_ids_for_cfp).pluck(:id)
|
||||
commercialable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_cfp).pluck(:id)).pluck(:id)
|
||||
can :index, Comment, commentable_type: 'Event',
|
||||
commentable_id: Event.where(conference_id: conf_ids_for_cfp).pluck(:id)
|
||||
commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_cfp).pluck(:id)).pluck(:id)
|
||||
end
|
||||
|
||||
def signed_in_with_info_desk_role(user)
|
||||
|
|
|
|||
117
app/models/ahoy/program.rb
Normal file
117
app/models/ahoy/program.rb
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
# cannot delete program if there are events submitted
|
||||
|
||||
class Program < ActiveRecord::Base
|
||||
belongs_to :conference
|
||||
|
||||
has_one :cfp, dependent: :destroy
|
||||
has_many :event_types, dependent: :destroy
|
||||
has_many :tracks, dependent: :destroy
|
||||
has_many :difficulty_levels, dependent: :destroy
|
||||
has_many :rooms, dependent: :destroy
|
||||
has_many :events, dependent: :destroy do
|
||||
def workshops
|
||||
where(require_registration: true, state: :confirmed)
|
||||
end
|
||||
|
||||
def confirmed
|
||||
where(state: :confirmed)
|
||||
end
|
||||
|
||||
def scheduled
|
||||
where.not(start_time: nil)
|
||||
end
|
||||
|
||||
def highlights
|
||||
where(state: :confirmed, is_highlight: true)
|
||||
end
|
||||
end
|
||||
|
||||
has_many :event_users, through: :events
|
||||
has_many :speakers, -> { distinct }, through: :event_users, source: :user do
|
||||
def confirmed
|
||||
joins(:events).where(events: { state: :confirmed })
|
||||
end
|
||||
end
|
||||
|
||||
accepts_nested_attributes_for :event_types, allow_destroy: true
|
||||
accepts_nested_attributes_for :tracks, reject_if: proc { |r| r['name'].blank? }, allow_destroy: true
|
||||
accepts_nested_attributes_for :difficulty_levels, allow_destroy: true
|
||||
accepts_nested_attributes_for :rooms, reject_if: proc { |r| r['name'].blank? }, allow_destroy: true
|
||||
|
||||
attr_accessible :schedule_fluid, :rating,
|
||||
:schedule_public, :include_cfp_in_splash, :conference_id,
|
||||
:event_types_attributes, :difficulty_levels_attributes, :rooms_attributes, :tracks_attributes
|
||||
|
||||
# validates :conference_id, presence: true, uniqueness: true
|
||||
validates :rating, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 10 }
|
||||
|
||||
before_create :create_event_types
|
||||
before_create :create_difficulty_levels
|
||||
|
||||
##
|
||||
# Checcks if the program has rating enabled
|
||||
#
|
||||
# ====Returns
|
||||
# * +false+ -> If rating is not enabled
|
||||
# * +true+ -> If rating is enabled
|
||||
def rating_enabled?
|
||||
self.rating && self.rating > 0
|
||||
end
|
||||
|
||||
##
|
||||
# Checks if the call for papers for the conference is currently open
|
||||
#
|
||||
# ====Returns
|
||||
# * +false+ -> If the CFP is not set or today isn't in the CFP period.
|
||||
# * +true+ -> If today is in the CFP period.
|
||||
def cfp_open?
|
||||
cfp = self.cfp
|
||||
|
||||
cfp.present? && (cfp.start_date..cfp.end_date).cover?(Date.current)
|
||||
end
|
||||
|
||||
##
|
||||
# Checks whether cfp dates is updated
|
||||
#
|
||||
# ====Returns
|
||||
# * +True+ -> If cfp dates is updated and all other parameters are set
|
||||
# * +False+ -> Either cfp date is not updated or one or more parameter is not set
|
||||
def notify_on_schedule_public?
|
||||
self.cfp && !self.cfp.end_date.blank? && !self.cfp.start_date.blank?\
|
||||
&& (self.cfp.start_date_changed? || self.cfp.end_date_changed?)\
|
||||
&& self.conference.email_settings.send_on_cfp_dates_updates\
|
||||
&& !self.conference.email_settings.cfp_dates_updates_subject.blank?\
|
||||
&& !self.conference.email_settings.cfp_dates_updates_template.blank?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
##
|
||||
# Creates default EventTypes for this Conference. Used as before_create.
|
||||
#
|
||||
def create_event_types
|
||||
event_types << EventType.create(title: 'Talk', length: 30, color: '#FF0000', description: 'Presentation in lecture format',
|
||||
minimum_abstract_length: 0,
|
||||
maximum_abstract_length: 500)
|
||||
event_types << EventType.create(title: 'Workshop', length: 60, color: '#0000FF', description: 'Interactive hands-on practice',
|
||||
minimum_abstract_length: 0,
|
||||
maximum_abstract_length: 500)
|
||||
true
|
||||
end
|
||||
|
||||
##
|
||||
# Creates default DifficultyLevels for this Conference. Used as before_create.
|
||||
#
|
||||
def create_difficulty_levels
|
||||
difficulty_levels << DifficultyLevel.create(title: 'Easy',
|
||||
description: 'Events are understandable for everyone without knowledge of the topic.',
|
||||
color: '#70EF69')
|
||||
difficulty_levels << DifficultyLevel.create(title: 'Medium',
|
||||
description: 'Events require a basic understanding of the topic.',
|
||||
color: '#EEEF69')
|
||||
difficulty_levels << DifficultyLevel.create(title: 'Hard',
|
||||
description: 'Events require expert knowledge of the topic.',
|
||||
color: '#EF6E69')
|
||||
true
|
||||
end
|
||||
end
|
||||
73
app/models/cfp.rb
Normal file
73
app/models/cfp.rb
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
# cannot delete program if there are events submitted
|
||||
|
||||
class Cfp < ActiveRecord::Base
|
||||
belongs_to :program
|
||||
|
||||
attr_accessible :start_date, :end_date, :program_id
|
||||
|
||||
validates :program_id, presence: true, uniqueness: true
|
||||
validates :start_date, :end_date, presence: true
|
||||
validate :before_end_of_conference
|
||||
validate :start_after_end_date
|
||||
|
||||
##
|
||||
# Checks whether cfp date is updated
|
||||
#
|
||||
# ====Returns
|
||||
# * +True+ -> If cfp dates is updated and all other parameters are set
|
||||
# * +False+ -> Either cfp date is not updated or one or more parameter is not set
|
||||
def notify_on_cfp_date_update?
|
||||
!self.end_date.blank? && !self.start_date.blank?\
|
||||
&& (self.start_date_changed? || self.end_date_changed?)\
|
||||
&& self.program.conference.email_settings.send_on_cfp_dates_updates\
|
||||
&& !self.program.conference.email_settings.cfp_dates_updates_subject.blank?\
|
||||
&& !self.program.conference.email_settings.cfp_dates_updates_template.blank?
|
||||
end
|
||||
|
||||
##
|
||||
# Calculates how many weeks the call for paper is.
|
||||
#
|
||||
# ====Returns
|
||||
# * +Integer+ -> start week
|
||||
def weeks
|
||||
result = end_week - start_week + 1
|
||||
weeks = Date.new(start_date.year, 12, 31).strftime('%W').to_i
|
||||
result < 0 ? result + weeks : result
|
||||
end
|
||||
|
||||
##
|
||||
# Calculates the end week of the cfp
|
||||
#
|
||||
# ====Returns
|
||||
def start_week
|
||||
start_date.strftime('%W').to_i
|
||||
end
|
||||
|
||||
##
|
||||
# Calculates the end week of the cfp
|
||||
#
|
||||
# ====Returns
|
||||
def end_week
|
||||
end_date.strftime('%W').to_i
|
||||
end
|
||||
|
||||
def remaining_days(date = Date.today)
|
||||
result = (self.end_date - date).to_i
|
||||
result > 0 ? result : 0
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def before_end_of_conference
|
||||
errors.
|
||||
add(:end_date, "can't be after the conference end date (#{program.conference.end_date})") if program.conference && program.conference.end_date && end_date && (end_date > program.conference.end_date)
|
||||
|
||||
errors.
|
||||
add(:start_date, "can't be after the conference end date (#{program.conference.end_date})") if program.conference && program.conference.end_date && start_date && (start_date > program.conference.end_date)
|
||||
end
|
||||
|
||||
def start_after_end_date
|
||||
errors.
|
||||
add(:start_date, "can't be after the end date") if start_date && end_date && start_date > end_date
|
||||
end
|
||||
end
|
||||
|
|
@ -16,40 +16,14 @@ class Conference < ActiveRecord::Base
|
|||
has_one :contact, dependent: :destroy
|
||||
has_one :registration_period, dependent: :destroy
|
||||
has_one :email_settings, dependent: :destroy
|
||||
has_one :call_for_paper, dependent: :destroy
|
||||
has_one :program, dependent: :destroy
|
||||
has_one :venue, dependent: :destroy
|
||||
has_many :social_events, dependent: :destroy
|
||||
has_many :ticket_purchases, dependent: :destroy
|
||||
has_many :supporters, through: :ticket_purchases, source: :user
|
||||
has_many :tickets, dependent: :destroy
|
||||
has_many :dietary_choices, dependent: :destroy
|
||||
has_many :events, dependent: :destroy do
|
||||
def workshops
|
||||
where(require_registration: true, state: :confirmed)
|
||||
end
|
||||
|
||||
def confirmed
|
||||
where(state: :confirmed)
|
||||
end
|
||||
|
||||
def scheduled
|
||||
where.not(start_time: nil)
|
||||
end
|
||||
|
||||
def highlights
|
||||
where(state: :confirmed, is_highlight: true)
|
||||
end
|
||||
end
|
||||
has_many :event_users, through: :events
|
||||
has_many :speakers, -> { distinct }, through: :event_users, source: :user do
|
||||
def confirmed
|
||||
joins(:events).where(events: { state: :confirmed })
|
||||
end
|
||||
end
|
||||
has_many :event_types, dependent: :destroy
|
||||
has_many :tracks, dependent: :destroy
|
||||
has_many :difficulty_levels, dependent: :destroy
|
||||
has_many :rooms, dependent: :destroy
|
||||
has_many :lodgings, dependent: :destroy
|
||||
has_many :registrations, dependent: :destroy
|
||||
has_many :participants, through: :registrations, source: :user
|
||||
|
|
@ -63,16 +37,12 @@ class Conference < ActiveRecord::Base
|
|||
has_many :commercials, as: :commercialable, dependent: :destroy
|
||||
has_many :subscriptions, dependent: :destroy
|
||||
|
||||
accepts_nested_attributes_for :rooms, reject_if: proc { |r| r['name'].blank? }, allow_destroy: true
|
||||
accepts_nested_attributes_for :tracks, reject_if: proc { |r| r['name'].blank? }, allow_destroy: true
|
||||
accepts_nested_attributes_for :difficulty_levels, allow_destroy: true
|
||||
accepts_nested_attributes_for :social_events, allow_destroy: true
|
||||
accepts_nested_attributes_for :venue
|
||||
accepts_nested_attributes_for :dietary_choices, allow_destroy: true
|
||||
accepts_nested_attributes_for :tickets, allow_destroy: true
|
||||
accepts_nested_attributes_for :sponsorship_levels, allow_destroy: true
|
||||
accepts_nested_attributes_for :sponsors, allow_destroy: true
|
||||
accepts_nested_attributes_for :event_types, allow_destroy: true
|
||||
accepts_nested_attributes_for :email_settings
|
||||
accepts_nested_attributes_for :questions, allow_destroy: true
|
||||
accepts_nested_attributes_for :vdays, allow_destroy: true
|
||||
|
|
@ -99,10 +69,8 @@ class Conference < ActiveRecord::Base
|
|||
# This validation is needed since a conference with a start date greater than the end date is not possible
|
||||
validate :valid_date_range?
|
||||
before_create :generate_guid
|
||||
before_create :create_event_types
|
||||
before_create :create_difficulty_levels
|
||||
before_create :create_email_settings
|
||||
before_create :add_color
|
||||
before_create :create_email_settings
|
||||
|
||||
def date_range_string
|
||||
startstr = 'Unknown - '
|
||||
|
|
@ -158,18 +126,6 @@ class Conference < ActiveRecord::Base
|
|||
registration_period.end_date.present?
|
||||
end
|
||||
|
||||
##
|
||||
# Checks if the call for papers for the conference is currently open
|
||||
#
|
||||
# ====Returns
|
||||
# * +false+ -> If the CFP is not set or today isn't in the CFP period.
|
||||
# * +true+ -> If today is in the CFP period.
|
||||
def cfp_open?
|
||||
cfp = self.call_for_paper
|
||||
|
||||
cfp.present? && (cfp.start_date..cfp.end_date).cover?(Date.current)
|
||||
end
|
||||
|
||||
##
|
||||
# Returns an array with the summarized event submissions per week.
|
||||
#
|
||||
|
|
@ -178,10 +134,10 @@ class Conference < ActiveRecord::Base
|
|||
def get_submissions_per_week
|
||||
result = []
|
||||
|
||||
if call_for_paper && events
|
||||
submissions = events.group(:week).count
|
||||
start_week = call_for_paper.start_week
|
||||
weeks = call_for_paper.weeks
|
||||
if program && program.cfp && program.events
|
||||
submissions = program.events.group(:week).count
|
||||
start_week = program.cfp.start_week
|
||||
weeks = program.cfp.weeks
|
||||
result = calculate_items_per_week(start_week, weeks, submissions)
|
||||
end
|
||||
result
|
||||
|
|
@ -195,10 +151,10 @@ class Conference < ActiveRecord::Base
|
|||
# * +Array+ -> e.g. 'Submitted' => [0, 3, 3, 5] -> first week 0 events, second week 3 events.
|
||||
def get_submissions_data
|
||||
result = {}
|
||||
if call_for_paper && events
|
||||
if program && program.cfp && program.events
|
||||
result = get_events_per_week_by_state
|
||||
|
||||
start_week = call_for_paper.start_week
|
||||
start_week = program.cfp.start_week
|
||||
end_week = end_date.strftime('%W').to_i
|
||||
weeks = weeks(start_week, end_week)
|
||||
|
||||
|
|
@ -260,8 +216,8 @@ class Conference < ActiveRecord::Base
|
|||
# ====Returns
|
||||
# * +Integer+ -> weeks
|
||||
def cfp_weeks
|
||||
if call_for_paper
|
||||
call_for_paper.weeks
|
||||
if program
|
||||
program.cfp.weeks
|
||||
else
|
||||
0
|
||||
end
|
||||
|
|
@ -344,7 +300,7 @@ class Conference < ActiveRecord::Base
|
|||
# * +hash+ -> user: submissions
|
||||
def get_top_submitter(limit = 5)
|
||||
submitter = EventUser.joins(:event).
|
||||
where('event_role = ? and conference_id = ?', 'submitter', id).
|
||||
where('event_role = ? and program_id = ?', 'submitter', Conference.find(id).program.id).
|
||||
limit(limit).group(:user_id)
|
||||
counter = submitter.order('count_all desc').count
|
||||
Conference.calculate_user_submission_hash(submitter, counter)
|
||||
|
|
@ -366,7 +322,7 @@ class Conference < ActiveRecord::Base
|
|||
# ====Returns
|
||||
# * +hash+ -> hash
|
||||
def event_distribution
|
||||
Conference.calculate_event_distribution_hash(events.select(:state).group(:state).count)
|
||||
Conference.calculate_event_distribution_hash(program.events.select(:state).group(:state).count)
|
||||
end
|
||||
|
||||
##
|
||||
|
|
@ -391,7 +347,7 @@ class Conference < ActiveRecord::Base
|
|||
# ====Returns
|
||||
# * +hash+ -> Fixnum minutes
|
||||
def current_program_minutes
|
||||
events_grouped = events.select(:event_type_id).group(:event_type_id)
|
||||
events_grouped = program.events.select(:event_type_id).group(:event_type_id)
|
||||
events_counted = events_grouped.count
|
||||
calculate_program_minutes(events_grouped, events_counted)
|
||||
end
|
||||
|
|
@ -411,7 +367,7 @@ class Conference < ActiveRecord::Base
|
|||
# ====Returns
|
||||
# * +hash+ -> Fixnum minutes
|
||||
def new_program_minutes(date)
|
||||
events_grouped = events.select(:event_type_id).where('created_at > ?', date).group(:event_type_id)
|
||||
events_grouped = program.events.select(:event_type_id).where('created_at > ?', date).group(:event_type_id)
|
||||
events_counted = events_grouped.count
|
||||
calculate_program_minutes(events_grouped, events_counted)
|
||||
end
|
||||
|
|
@ -450,9 +406,9 @@ class Conference < ActiveRecord::Base
|
|||
# * +hash+ -> track => {color, value}
|
||||
def tracks_distribution(state = nil)
|
||||
if state
|
||||
tracks_grouped = events.select(:track_id).where('state = ?', state).group(:track_id)
|
||||
tracks_grouped = program.events.select(:track_id).where('state = ?', state).group(:track_id)
|
||||
else
|
||||
tracks_grouped = events.select(:track_id).group(:track_id)
|
||||
tracks_grouped = program.events.select(:track_id).group(:track_id)
|
||||
end
|
||||
tracks_counted = tracks_grouped.count
|
||||
|
||||
|
|
@ -539,7 +495,7 @@ class Conference < ActiveRecord::Base
|
|||
Conference.where('end_date > ?', Date.today).each do |conference|
|
||||
result = {}
|
||||
Event.state_machine.states.each do |state|
|
||||
count = conference.events.where('state = ?', state.name).count
|
||||
count = conference.program.events.where('state = ?', state.name).count
|
||||
result[state.name] = count
|
||||
end
|
||||
|
||||
|
|
@ -584,6 +540,7 @@ class Conference < ActiveRecord::Base
|
|||
|
||||
after_create do
|
||||
self.create_contact
|
||||
self.create_program
|
||||
end
|
||||
|
||||
##
|
||||
|
|
@ -631,10 +588,10 @@ class Conference < ActiveRecord::Base
|
|||
|
||||
# Actual week
|
||||
this_week = Date.today.end_of_week.strftime('%W').to_i
|
||||
result['Confirmed'][this_week] = events.where('state = ?', :confirmed).count
|
||||
result['Unconfirmed'][this_week] = events.where('state = ?', :unconfirmed).count
|
||||
result['Submitted'] = events.select(:week).group(:week).count
|
||||
result['Submitted'][this_week] = events.where(week: this_week).count
|
||||
result['Confirmed'][this_week] = program.events.where('state = ?', :confirmed).count
|
||||
result['Unconfirmed'][this_week] = program.events.where('state = ?', :unconfirmed).count
|
||||
result['Submitted'] = program.events.select(:week).group(:week).count
|
||||
result['Submitted'][this_week] = program.events.where(week: this_week).count
|
||||
result
|
||||
end
|
||||
|
||||
|
|
@ -720,7 +677,7 @@ class Conference < ActiveRecord::Base
|
|||
# * +True+ -> One difficulty level or more
|
||||
# * +False+ -> No diffculty level
|
||||
def difficulty_levels_set?
|
||||
difficulty_levels.count > 0
|
||||
program.difficulty_levels.count > 0
|
||||
end
|
||||
|
||||
##
|
||||
|
|
@ -730,7 +687,7 @@ class Conference < ActiveRecord::Base
|
|||
# * +True+ -> One difficulty level or more
|
||||
# * +False+ -> No diffculty level
|
||||
def event_types_set?
|
||||
event_types.count > 0
|
||||
program.event_types.count > 0
|
||||
end
|
||||
|
||||
##
|
||||
|
|
@ -740,7 +697,7 @@ class Conference < ActiveRecord::Base
|
|||
# * +True+ -> One track or more
|
||||
# * +False+ -> No track
|
||||
def tracks_set?
|
||||
tracks.count > 0
|
||||
program.tracks.count > 0
|
||||
end
|
||||
|
||||
##
|
||||
|
|
@ -750,7 +707,7 @@ class Conference < ActiveRecord::Base
|
|||
# * +True+ -> One room or more
|
||||
# * +False+ -> No room
|
||||
def rooms_set?
|
||||
rooms.count > 0
|
||||
program.rooms.count > 0
|
||||
end
|
||||
|
||||
# Checks if the conference has a venue object.
|
||||
|
|
@ -769,7 +726,7 @@ class Conference < ActiveRecord::Base
|
|||
# * +True+ -> If conference has a cfp object.
|
||||
# * +False+ -> If conference has no cfp object.
|
||||
def cfp_set?
|
||||
!!call_for_paper
|
||||
!!program.cfp
|
||||
end
|
||||
|
||||
##
|
||||
|
|
@ -788,9 +745,9 @@ class Conference < ActiveRecord::Base
|
|||
# * +hash+ -> object_type => {color, value}
|
||||
def calculate_event_distribution(group_by_id, association_symbol, state = nil)
|
||||
if state
|
||||
grouped = events.select(group_by_id).where('state = ?', 'confirmed').group(group_by_id)
|
||||
grouped = program.events.select(group_by_id).where('state = ?', 'confirmed').group(group_by_id)
|
||||
else
|
||||
grouped = events.select(group_by_id).group(group_by_id)
|
||||
grouped = program.events.select(group_by_id).group(group_by_id)
|
||||
end
|
||||
counted = grouped.count
|
||||
|
||||
|
|
@ -910,35 +867,6 @@ class Conference < ActiveRecord::Base
|
|||
result
|
||||
end
|
||||
|
||||
##
|
||||
# Creates default EventTypes for this Conference. Used as before_create.
|
||||
#
|
||||
def create_event_types
|
||||
event_types << EventType.create(title: 'Talk', length: 30, color: '#FF0000', description: 'Presentation in lecture format',
|
||||
minimum_abstract_length: 0,
|
||||
maximum_abstract_length: 500)
|
||||
event_types << EventType.create(title: 'Workshop', length: 60, color: '#0000FF', description: 'Interactive hands-on practice',
|
||||
minimum_abstract_length: 0,
|
||||
maximum_abstract_length: 500)
|
||||
true
|
||||
end
|
||||
|
||||
##
|
||||
# Creates default DifficultyLevels for this Conference. Used as before_create.
|
||||
#
|
||||
def create_difficulty_levels
|
||||
difficulty_levels << DifficultyLevel.create(title: 'Easy',
|
||||
description: 'Events are understandable for everyone without knowledge of the topic.',
|
||||
color: '#70EF69')
|
||||
difficulty_levels << DifficultyLevel.create(title: 'Medium',
|
||||
description: 'Events require a basic understanding of the topic.',
|
||||
color: '#EEEF69')
|
||||
difficulty_levels << DifficultyLevel.create(title: 'Hard',
|
||||
description: 'Events require expert knowledge of the topic.',
|
||||
color: '#EF6E69')
|
||||
true
|
||||
end
|
||||
|
||||
##
|
||||
# Creates a EmailSettings association proxy. Used as before_create.
|
||||
#
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class DifficultyLevel < ActiveRecord::Base
|
||||
belongs_to :conference
|
||||
belongs_to :program
|
||||
has_many :events, dependent: :nullify
|
||||
|
||||
validates :title, presence: true
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ class EmailSettings < ActiveRecord::Base
|
|||
conference.short_title, host: CONFIG['url_for_emails'])
|
||||
}
|
||||
|
||||
if conference.call_for_paper
|
||||
h['cfp_start_date'] = conference.call_for_paper.start_date
|
||||
h['cfp_end_date'] = conference.call_for_paper.end_date
|
||||
if conference.program.cfp
|
||||
h['cfp_start_date'] = conference.program.cfp.start_date
|
||||
h['cfp_end_date'] = conference.program.cfp.end_date
|
||||
else
|
||||
h['cfp_start_date'] = 'Unknown'
|
||||
h['cfp_end_date'] = 'Unknown'
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class Event < ActiveRecord::Base
|
|||
belongs_to :track
|
||||
belongs_to :room
|
||||
belongs_to :difficulty_level
|
||||
belongs_to :conference
|
||||
belongs_to :program
|
||||
|
||||
accepts_nested_attributes_for :event_users, allow_destroy: true
|
||||
accepts_nested_attributes_for :users
|
||||
|
|
@ -31,7 +31,7 @@ class Event < ActiveRecord::Base
|
|||
validates :title, presence: true
|
||||
validates :abstract, presence: true
|
||||
validates :event_type, presence: true
|
||||
validates :conference, presence: true
|
||||
validates :program, presence: true
|
||||
|
||||
scope :confirmed, -> { where(state: 'confirmed') }
|
||||
scope :highlighted, -> { where(is_highlight: true) }
|
||||
|
|
@ -108,9 +108,9 @@ class Event < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def process_confirmation
|
||||
if conference.email_settings.send_on_confirmed_without_registration? &&
|
||||
conference.email_settings.confirmed_without_registration_body &&
|
||||
conference.email_settings.confirmed_without_registration_subject
|
||||
if program.conference.email_settings.send_on_confirmed_without_registration? &&
|
||||
program.conference.email_settings.confirmed_without_registration_body &&
|
||||
program.conference.email_settings.confirmed_without_registration_subject
|
||||
if conference.registrations.where(user_id: submitter.id).first.nil?
|
||||
Mailbot.delay.confirm_reminder_mail(self)
|
||||
end
|
||||
|
|
@ -118,9 +118,9 @@ class Event < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def process_acceptance(options)
|
||||
if conference.email_settings.send_on_accepted &&
|
||||
conference.email_settings.accepted_body &&
|
||||
conference.email_settings.accepted_subject &&
|
||||
if program.conference.email_settings.send_on_accepted &&
|
||||
program.conference.email_settings.accepted_body &&
|
||||
program.conference.email_settings.accepted_subject &&
|
||||
!options[:send_mail].blank?
|
||||
Rails.logger.debug 'Sending event acceptance mail'
|
||||
Mailbot.delay.acceptance_mail(self)
|
||||
|
|
@ -128,9 +128,9 @@ class Event < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def process_rejection(options)
|
||||
if conference.email_settings.send_on_rejected &&
|
||||
conference.email_settings.rejected_body &&
|
||||
conference.email_settings.rejected_subject &&
|
||||
if program.conference.email_settings.send_on_rejected &&
|
||||
program.conference.email_settings.rejected_body &&
|
||||
program.conference.email_settings.rejected_subject &&
|
||||
!options[:send_mail].blank?
|
||||
Rails.logger.debug 'Sending rejected mail'
|
||||
Mailbot.delay.rejection_mail(self)
|
||||
|
|
@ -190,7 +190,7 @@ class Event < ActiveRecord::Base
|
|||
# Returns +Hash+
|
||||
def progress_status
|
||||
{
|
||||
registered: self.conference.user_registered?(self.submitter),
|
||||
registered: self.program.conference.user_registered?(self.submitter),
|
||||
commercials: self.commercials.any?,
|
||||
biography: !self.submitter.biography.blank?,
|
||||
subtitle: !self.subtitle.blank?,
|
||||
|
|
@ -241,7 +241,7 @@ class Event < ActiveRecord::Base
|
|||
|
||||
def before_end_of_conference
|
||||
errors.
|
||||
add(:created_at, "can't be after the conference end date!") if conference.end_date &&
|
||||
(Date.today > conference.end_date)
|
||||
add(:created_at, "can't be after the conference end date!") if program.conference && program.conference.end_date &&
|
||||
(Date.today > program.conference.end_date)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class EventType < ActiveRecord::Base
|
||||
belongs_to :conference
|
||||
belongs_to :program
|
||||
has_many :events, dependent: :restrict_with_error
|
||||
|
||||
validates :title, presence: true
|
||||
|
|
|
|||
103
app/models/program.rb
Normal file
103
app/models/program.rb
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
# cannot delete program if there are events submitted
|
||||
|
||||
class Program < ActiveRecord::Base
|
||||
belongs_to :conference
|
||||
|
||||
has_one :cfp, dependent: :destroy
|
||||
has_many :event_types, dependent: :destroy
|
||||
has_many :tracks, dependent: :destroy
|
||||
has_many :difficulty_levels, dependent: :destroy
|
||||
has_many :rooms, dependent: :destroy
|
||||
has_many :events, dependent: :destroy do
|
||||
def workshops
|
||||
where(require_registration: true, state: :confirmed)
|
||||
end
|
||||
|
||||
def confirmed
|
||||
where(state: :confirmed)
|
||||
end
|
||||
|
||||
def scheduled
|
||||
where.not(start_time: nil)
|
||||
end
|
||||
|
||||
def highlights
|
||||
where(state: :confirmed, is_highlight: true)
|
||||
end
|
||||
end
|
||||
|
||||
has_many :event_users, through: :events
|
||||
has_many :speakers, -> { distinct }, through: :event_users, source: :user do
|
||||
def confirmed
|
||||
joins(:events).where(events: { state: :confirmed })
|
||||
end
|
||||
end
|
||||
|
||||
accepts_nested_attributes_for :event_types, allow_destroy: true
|
||||
accepts_nested_attributes_for :tracks, reject_if: proc { |r| r['name'].blank? }, allow_destroy: true
|
||||
accepts_nested_attributes_for :difficulty_levels, allow_destroy: true
|
||||
accepts_nested_attributes_for :rooms, reject_if: proc { |r| r['name'].blank? }, allow_destroy: true
|
||||
|
||||
attr_accessible :schedule_fluid, :rating,
|
||||
:schedule_public, :include_cfp_in_splash, :conference_id,
|
||||
:event_types_attributes, :difficulty_levels_attributes, :rooms_attributes, :tracks_attributes
|
||||
|
||||
# validates :conference_id, presence: true, uniqueness: true
|
||||
validates :rating, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 10 }
|
||||
|
||||
before_create :create_event_types
|
||||
before_create :create_difficulty_levels
|
||||
|
||||
##
|
||||
# Checcks if the program has rating enabled
|
||||
#
|
||||
# ====Returns
|
||||
# * +false+ -> If rating is not enabled
|
||||
# * +true+ -> If rating is enabled
|
||||
def rating_enabled?
|
||||
self.rating && self.rating > 0
|
||||
end
|
||||
|
||||
##
|
||||
# Checks if the call for papers for the conference is currently open
|
||||
#
|
||||
# ====Returns
|
||||
# * +false+ -> If the CFP is not set or today isn't in the CFP period.
|
||||
# * +true+ -> If today is in the CFP period.
|
||||
def cfp_open?
|
||||
cfp = self.cfp
|
||||
|
||||
cfp.present? && (cfp.start_date..cfp.end_date).cover?(Date.current)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
##
|
||||
# Creates default EventTypes for this Conference. Used as before_create.
|
||||
#
|
||||
def create_event_types
|
||||
event_types << EventType.create(title: 'Talk', length: 30, color: '#FF0000', description: 'Presentation in lecture format',
|
||||
minimum_abstract_length: 0,
|
||||
maximum_abstract_length: 500)
|
||||
event_types << EventType.create(title: 'Workshop', length: 60, color: '#0000FF', description: 'Interactive hands-on practice',
|
||||
minimum_abstract_length: 0,
|
||||
maximum_abstract_length: 500)
|
||||
true
|
||||
end
|
||||
|
||||
##
|
||||
# Creates default DifficultyLevels for this Conference. Used as before_create.
|
||||
#
|
||||
def create_difficulty_levels
|
||||
difficulty_levels << DifficultyLevel.create(title: 'Easy',
|
||||
description: 'Events are understandable for everyone without knowledge of the topic.',
|
||||
color: '#70EF69')
|
||||
difficulty_levels << DifficultyLevel.create(title: 'Medium',
|
||||
description: 'Events require a basic understanding of the topic.',
|
||||
color: '#EEEF69')
|
||||
difficulty_levels << DifficultyLevel.create(title: 'Hard',
|
||||
description: 'Events require expert knowledge of the topic.',
|
||||
color: '#EF6E69')
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
class Room < ActiveRecord::Base
|
||||
belongs_to :conference
|
||||
belongs_to :program
|
||||
has_many :events, dependent: :nullify
|
||||
|
||||
before_create :generate_guid
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class Target < ActiveRecord::Base
|
|||
numerator =
|
||||
case unit
|
||||
when Target.units[:submissions]
|
||||
conference.events.where('created_at < ?', due_date).count
|
||||
conference.program.events.where('created_at < ?', due_date).count
|
||||
when Target.units[:registrations]
|
||||
conference.registrations.where('created_at < ?', due_date).count
|
||||
when Target.units[:program_minutes]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class Track < ActiveRecord::Base
|
||||
belongs_to :conference
|
||||
belongs_to :program
|
||||
has_many :events, dependent: :nullify
|
||||
|
||||
before_create :generate_guid
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def proposals(conference)
|
||||
events.where('conference_id = ? AND event_users.event_role=?', conference.id, 'submitter')
|
||||
events.where('program_id = ? AND event_users.event_role=?', conference.program.id, 'submitter')
|
||||
end
|
||||
|
||||
def proposal_count(conference)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue