123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- 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')
- }
-
-
- def human_attending
- HUMAN_ATTENDING[self.attending]
- end
-
-
-
- def row_class
- if self.attending
- "success"
- elsif self.attending == false
- "danger"
- else
- "warning"
- end
- end
- def may_change?(person)
- self.activity.may_change?(person) ||
- self.person == person
- end
-
- def send_reminder
- return unless self.attending.nil?
- self.attending = self.activity.no_response_action
- notes = self.notes || ""
- notes << '[auto]'
- self.notes = notes
- self.save
- return unless self.person.send_attendance_reminder
- ParticipantMailer.attendance_reminder(self.person, self.activity).deliver_later
- end
-
- def send_subgroup_notification
- return unless self.attending && self.subgroup
- ParticipantMailer.subgroup_notification(self.person, self.activity, self).deliver_later
- end
-
- def clear_subgroup
- self.subgroup = nil
- end
- end
|