|
@@ -33,31 +33,33 @@ class Group < ApplicationRecord
|
33
|
33
|
end
|
34
|
34
|
|
35
|
35
|
# @return [Array<Activity>]
|
36
|
|
- # the Activity/Activities that are the closest to the given point in time.
|
37
|
|
- # Logic is as follows:
|
38
|
|
- # - If one or more Activities start before and end after the given point
|
39
|
|
- # in time, these are returned.
|
40
|
|
- # - Additionally, the last 3 activities that ended are returned, as well
|
41
|
|
- # as any activities starting within the next 48 hours.
|
|
36
|
+ # all Activities that have started, and not yet ended.
|
42
|
37
|
def current_activities(reference = Time.zone.now)
|
43
|
|
- currently_active = self.activities
|
|
38
|
+ activities
|
44
|
39
|
.where('start < ?', reference)
|
45
|
40
|
.where('end > ?', reference)
|
|
41
|
+ end
|
46
|
42
|
|
47
|
|
- previous = self.activities
|
|
43
|
+ # @return [Array<Activity>]
|
|
44
|
+ # at most 3 activities that ended recently.
|
|
45
|
+ def previous_activities(reference = Time.zone.now)
|
|
46
|
+ activities
|
48
|
47
|
.where('end < ?', reference)
|
49
|
48
|
.order(end: :desc)
|
50
|
49
|
.limit(3)
|
|
50
|
+ end
|
51
|
51
|
|
52
|
|
- upcoming = self.activities
|
|
52
|
+ # @return [Array<Activity>]
|
|
53
|
+ # all Activities starting within the next 48 hours.
|
|
54
|
+ def upcoming_activities(reference = Time.zone.now)
|
|
55
|
+ activities
|
53
|
56
|
.where('start > ?', reference)
|
54
|
57
|
.where('start < ?', reference.days_since(2))
|
55
|
58
|
.order(start: :asc)
|
56
|
|
-
|
57
|
|
- return {currently_active: currently_active, previous: previous, upcoming: upcoming}
|
58
|
59
|
end
|
59
|
60
|
|
60
|
|
- # Determine whether the passed person is a member of the group.
|
|
61
|
+ # @return [Boolean]
|
|
62
|
+ # whether the passed person is a member of the group.
|
61
|
63
|
def is_member?(person)
|
62
|
64
|
Member.exists?(
|
63
|
65
|
person: person,
|
|
@@ -65,7 +67,8 @@ class Group < ApplicationRecord
|
65
|
67
|
) || person.is_admin?
|
66
|
68
|
end
|
67
|
69
|
|
68
|
|
- # Determine whether the passed person is a group leader.
|
|
70
|
+ # @return [Boolean]
|
|
71
|
+ # whether the passed person is a group leader.
|
69
|
72
|
def is_leader?(person)
|
70
|
73
|
Member.exists?(
|
71
|
74
|
person: person,
|