Sprankelprachtig aan/afmeldsysteem

group.rb 1021B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # A Group contains Members, which can organize and participate in Activities.
  2. # Some of the Members may be group leaders, with the ability to see all
  3. # information and add or remove members from the group.
  4. class Group < ApplicationRecord
  5. # @!attribute name
  6. # @return [String]
  7. # the name of the group. Must be unique across all groups.
  8. has_many :members
  9. has_many :people, through: :members
  10. has_many :activities
  11. validates :name,
  12. presence: true,
  13. uniqueness: {
  14. case_sensitive: false
  15. }
  16. # @return [Array<Member>] the members in the group who are also group leaders.
  17. def leaders
  18. self.members.includes(:person).where(is_leader: true)
  19. end
  20. # @return [Array<Activity>] the activities that haven't started yet.
  21. def future_activities
  22. self.activities.where('start > ?', DateTime.now)
  23. end
  24. # Determine whether the passed person is a group leader.
  25. def is_leader?(person)
  26. Member.exists?(
  27. person: person,
  28. group: self,
  29. is_leader: true
  30. )
  31. end
  32. end