Sprankelprachtig aan/afmeldsysteem

participant.rb 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # A Participant represents the many-to-many relation between People and
  2. # Activities, and contains the information on whether or not the person plans
  3. # to be present at the activity.
  4. class Participant < ApplicationRecord
  5. # @!attribute is_organizer
  6. # @return [Boolean]
  7. # whether the person is an organizer for this event.
  8. #
  9. # @!attribute attending
  10. # @return [Boolean]
  11. # whether or not the person plans to attend the activity.
  12. #
  13. # @!attribute notes
  14. # @return [String]
  15. # a short text indicating any irregularities, such as arriving later or
  16. # leaving earlier.
  17. belongs_to :person
  18. belongs_to :activity
  19. validates :person_id,
  20. uniqueness: {
  21. scope: :activity_id,
  22. message: I18n.t('activities.errors.already_in')
  23. }
  24. # TODO: Move to a more appropriate place
  25. # @return [String]
  26. # the class for a row containing this activity.
  27. def row_class
  28. if self.attending
  29. "success"
  30. elsif self.attending == false
  31. "danger"
  32. else
  33. "warning"
  34. end
  35. end
  36. def may_change?(person)
  37. self.activity.may_change?(person) ||
  38. self.person == person
  39. end
  40. # Set attending to true if nil, and notify the Person via email.
  41. def send_reminder
  42. return unless self.attending.nil?
  43. self.attending = true
  44. notes = self.notes || ""
  45. notes << '[auto]'
  46. self.notes = notes
  47. self.save
  48. return unless self.person.send_attendance_reminder
  49. ParticipantMailer.attendance_reminder(self.person, self.activity).deliver_later
  50. end
  51. end