123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- class Participant < ApplicationRecord
-
-
-
-
-
-
-
-
-
-
-
-
- belongs_to :person
- belongs_to :activity
- belongs_to :subgroup, optional: true
- after_validation :clear_subgroup, if: 'self.attending != true'
- validates :person_id,
- uniqueness: {
- scope: :activity_id,
- message: I18n.t('activities.errors.already_in')
- }
- HUMAN_ATTENDING = {
- true => I18n.t('activities.state.present'),
- false => I18n.t('activities.state.absent'),
- nil => I18n.t('activities.state.unknown')
- }.freeze
-
-
- def human_attending
- HUMAN_ATTENDING[attending]
- end
- ICAL_ATTENDING = {
- true => 'ATTENDING',
- false => 'CANCELLED',
- nil => 'TENTATIVE'
- }.freeze
-
-
- def ical_attending
- ICAL_ATTENDING[attending]
- end
-
-
-
- def row_class
- if attending
- "success"
- elsif attending == false
- "danger"
- else
- "warning"
- end
- end
- def may_change?(person)
- activity.may_change?(person) ||
- self.person == person
- end
-
- def send_reminder
- return unless attending.nil?
- self.attending = activity.no_response_action
- notes = self.notes || ""
- notes << '[auto]'
- self.notes = notes
- save
- return unless person.send_attendance_reminder
- ParticipantMailer.attendance_reminder(person, activity).deliver_later
- end
-
- def send_subgroup_notification
- return unless attending && subgroup
- ParticipantMailer.subgroup_notification(person, activity, self).deliver_later
- end
-
- def clear_subgroup
- self.subgroup = nil
- end
- end
|