|
@@ -32,6 +32,31 @@ class Group < ApplicationRecord
|
32
|
32
|
self.activities.where('start > ?', DateTime.now)
|
33
|
33
|
end
|
34
|
34
|
|
|
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.
|
|
42
|
+ def current_activities(reference = Time.zone.now)
|
|
43
|
+ currently_active = self.activities
|
|
44
|
+ .where('start < ?', reference)
|
|
45
|
+ .where('end > ?', reference)
|
|
46
|
+
|
|
47
|
+ previous = self.activities
|
|
48
|
+ .where('end < ?', reference)
|
|
49
|
+ .order(end: :desc)
|
|
50
|
+ .limit(3)
|
|
51
|
+
|
|
52
|
+ upcoming = self.activities
|
|
53
|
+ .where('start > ?', reference)
|
|
54
|
+ .where('start < ?', reference.days_since(2))
|
|
55
|
+ .order(start: :asc)
|
|
56
|
+
|
|
57
|
+ return [currently_active, previous, upcoming].flatten
|
|
58
|
+ end
|
|
59
|
+
|
35
|
60
|
# Determine whether the passed person is a member of the group.
|
36
|
61
|
def is_member?(person)
|
37
|
62
|
Member.exists?(
|