Sprankelprachtig aan/afmeldsysteem

participant.rb 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. belongs_to :subgroup, optional: true
  20. validates :person_id,
  21. uniqueness: {
  22. scope: :activity_id,
  23. message: I18n.t('activities.errors.already_in')
  24. }
  25. # TODO: Move to a more appropriate place
  26. # @return [String]
  27. # the class for a row containing this activity.
  28. def row_class
  29. if self.attending
  30. "success"
  31. elsif self.attending == false
  32. "danger"
  33. else
  34. "warning"
  35. end
  36. end
  37. def may_change?(person)
  38. self.activity.may_change?(person) ||
  39. self.person == person
  40. end
  41. # Set attending to true if nil, and notify the Person via email.
  42. def send_reminder
  43. return unless self.attending.nil?
  44. self.attending = true
  45. notes = self.notes || ""
  46. notes << '[auto]'
  47. self.notes = notes
  48. self.save
  49. return unless self.person.send_attendance_reminder
  50. ParticipantMailer.attendance_reminder(self.person, self.activity).deliver_later
  51. end
  52. end