Skip to content

Commit

Permalink
..or maybe not. Since the scope sorts on end_date, we'd need an addit…
Browse files Browse the repository at this point in the history
…ional one; the uses don't overlap
  • Loading branch information
philipp-bode committed Feb 3, 2017
1 parent fda7577 commit b071c66
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Expand Up @@ -19,8 +19,8 @@ def index
# we should if this becomes a perf problem), there is no
# other solution

@events = Event.future
.draft_is(false).hidden_is(false)
@events = Event.sorted_by_start_date(true)
.select { |a| a.start_date > Time.now.yesterday }
.first(3)
render 'index', locals: { full_width: true }
end
Expand Down
11 changes: 11 additions & 0 deletions app/models/event.rb
Expand Up @@ -270,6 +270,17 @@ def material_path
scope :future, -> { with_date_ranges.having('date(MAX(end_date)) > ?', Time.zone.yesterday.end_of_day) }
scope :past, -> { with_date_ranges.having('date(MAX(end_date)) < ?', Time.zone.now.end_of_day) }

# Returns events sorted by start date, returning only public ones
# if requested
#
# @param limit Maximum number of events to return
# @param only_public Set to true to not include drafts and hidden events
# @return List of events
def self.sorted_by_start_date(only_public)
(only_public ? Event.draft_is(false).where(hidden: false) : Event.all)
.sort_by(&:start_date)
end

protected
# Compares two participants to achieve following order:
# 1. All participants that have to submit an letter of agreement but did not yet do so, ordered by email.
Expand Down

0 comments on commit b071c66

Please sign in to comment.