fix sorting
This commit is contained in:
parent
2d2d5fb276
commit
57cf170e1c
|
@ -106,10 +106,18 @@ class EventNews
|
||||||
before_destroy :destroy_email
|
before_destroy :destroy_email
|
||||||
|
|
||||||
scope :open_in_future, ->{where(:is_hidden.ne=>true,:is_preview.ne => true,:postdate.gt=>Time.now).order(postdate: :asc)}
|
scope :open_in_future, ->{where(:is_hidden.ne=>true,:is_preview.ne => true,:postdate.gt=>Time.now).order(postdate: :asc)}
|
||||||
scope :can_display_and_sorted, ->{where(:is_hidden.ne=>true,:is_preview.ne => true).valid_time_range}
|
scope :can_display_and_sorted, ->{
|
||||||
|
where(:is_hidden.ne=>true,:is_preview.ne => true)
|
||||||
|
.valid_time_range
|
||||||
|
.order(
|
||||||
|
EventNewsHelper.is_postdate_sort_first ?
|
||||||
|
{postdate: :desc, event_date: :desc, id: :desc} :
|
||||||
|
{event_date: :desc, postdate: :desc, id: :desc}
|
||||||
|
)
|
||||||
|
}
|
||||||
scope :can_display_and_sorted_according_today, ->{
|
scope :can_display_and_sorted_according_today, ->{
|
||||||
where(:is_hidden.ne=>true,:is_preview.ne => true)
|
where(:is_hidden.ne=>true,:is_preview.ne => true)
|
||||||
.order(event_date: :asc).valid_time_range.where(:event_date.gte => Date.today.to_time)
|
.order(event_date: :asc).valid_time_range.order({postdate: :asc, id: :asc}).where(:event_date.gte => Date.today.to_time)
|
||||||
}
|
}
|
||||||
scope :valid_time_range, ->{
|
scope :valid_time_range, ->{
|
||||||
and_any_of([
|
and_any_of([
|
||||||
|
@ -117,14 +125,9 @@ class EventNews
|
||||||
{"postdate"=>{"$lte"=> Time.now}, "deadline"=>nil}
|
{"postdate"=>{"$lte"=> Time.now}, "deadline"=>nil}
|
||||||
])
|
])
|
||||||
.order(
|
.order(
|
||||||
(EventNewsHelper.enable_manually_sort ?
|
EventNewsHelper.enable_manually_sort ?
|
||||||
{is_top: :desc, sort_number: :asc} :
|
{is_top: :desc, sort_number: :asc} :
|
||||||
{is_top: :desc}
|
{is_top: :desc}
|
||||||
).merge(
|
|
||||||
EventNewsHelper.is_postdate_sort_first ?
|
|
||||||
{postdate: :desc, event_date: :desc, id: :desc} :
|
|
||||||
{event_date: :desc, postdate: :desc, id: :desc}
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
scope :is_approved, ->{where(:approved => true)}
|
scope :is_approved, ->{where(:approved => true)}
|
||||||
|
|
Loading…
Reference in New Issue