Skip to content

Commit

Permalink
Move ordering inside the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
angusmcleod committed Jul 14, 2019
1 parent bf28402 commit 905ebaa
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions plugin.rb
Expand Up @@ -385,10 +385,8 @@ class ::ListableTopicSerializer

require_dependency 'topic_query'
class ::TopicQuery
SORTABLE_MAPPING['event'] = 'custom_fields.event_start'

def list_agenda
@options[:order] = 'event'
@options[:unordered] = true
@options[:list] = 'agenda'

opts = {
Expand All @@ -401,7 +399,7 @@ def list_agenda
end

def list_calendar
@options[:order] = 'event'
@options[:unordered] = true
@options[:list] = 'calendar'

opts = {
Expand Down Expand Up @@ -434,6 +432,21 @@ def event_results(options = {})
)")
end

topics = topics.order("(
SELECT CASE
WHEN EXISTS (
SELECT true FROM topic_custom_fields tcf
WHERE tcf.topic_id::integer = topics.id::integer
AND tcf.name = 'event_start' LIMIT 1
)
THEN (
SELECT value::integer FROM topic_custom_fields tcf
WHERE tcf.topic_id::integer = topics.id::integer
AND tcf.name = 'event_start' LIMIT 1
)
ELSE 0 END
) DESC")

if options[:include_excerpt]
topics.each { |t| t.include_excerpt = true }
end
Expand Down Expand Up @@ -504,7 +517,7 @@ def event_ics(opts = {})
cal.x_wr_calname = calendar_name
cal.x_wr_timezone = tzid
# add timezone once per calendar
event_now = DateTime.now
event_now = DateTime.now
timezone = tz.ical_timezone event_now
cal.add_timezone timezone

Expand Down

0 comments on commit 905ebaa

Please sign in to comment.