Add survey with target after_event

This commit is contained in:
Stella Rouzi 2018-02-23 11:52:27 +02:00
parent e1adf28081
commit 9908f88570
10 changed files with 45 additions and 9 deletions

View file

@ -785,6 +785,16 @@ class Conference < ApplicationRecord
short_title
end
##
# Returns true or false, if the event is already over or not
#
# ====Returns
# * +true+ -> If the event is over
# * +false+ -> If the event is not over yet
def ended?
end_date < Time.current
end
private
# Returns a different html colour for every i and consecutive colors are

View file

@ -21,6 +21,7 @@ class Event < ApplicationRecord
has_many :votes, dependent: :destroy
has_many :voters, through: :votes, source: :user
has_many :commercials, as: :commercialable, dependent: :destroy
has_many :surveys, as: :surveyable, dependent: :destroy
belongs_to :event_type
has_many :events_registrations

View file

@ -5,12 +5,30 @@ class Survey < ActiveRecord::Base
has_many :survey_questions, dependent: :destroy
has_many :survey_submissions, dependent: :destroy
enum target: [:after_conference, :during_registration]
enum target: [:after_conference, :during_registration, :after_event]
validates :title, presence: true
##
# Finds active surveys
# * if a survey has either start or end date, but not both
# check is performed only on the attribute that exists
# * if a survey does not have start/end dates, then it is marked active
# further check is expected, where appropriate, depending on the survey's target
# ====Returns
# * +true+ -> If the survey is active (will accept replies)
# * +false+ -> If the survey is closed
def active?
return false unless start_date && end_date
now = Time.now.in_time_zone(surveyable.timezone)
now >= start_date && now <= end_date
return true unless start_date || end_date
# Find timezone of conference (survyeable is Conference or Event)
timezone = surveyable.is_a?(Conference) ? surveyable.timezone : surveyable.conference.timezone
now = Time.current.in_time_zone(timezone)
if start_date && end_date
now >= start_date && now <= end_date
elsif start_date && !end_date
now >= start_date
elsif !start_date && end_date
now <= end_date
end
end
end