forked from bofh/fetsite
calentry neuigkeit order
This commit is contained in:
@@ -31,6 +31,28 @@ class Calentry < ActiveRecord::Base
|
||||
end
|
||||
|
||||
resourcify
|
||||
|
||||
def is_upcomming?
|
||||
self.start > Time.now
|
||||
end
|
||||
def is_ongoing?
|
||||
(self.start < Time.now) && (Time.now < self.ende)
|
||||
end
|
||||
def is_past?
|
||||
(Time.now > self.ende)
|
||||
end
|
||||
def days_to_today
|
||||
if self.is_ongoing?
|
||||
0
|
||||
else
|
||||
if self.is_upcomming?
|
||||
(self.start.to_date - Date.today).to_i.abs
|
||||
elsif self.is_past?
|
||||
(self.ende.to_date - Date.today).to_i.abs
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
def get_public
|
||||
self.calendar=self.object.calendar unless object.nil? || object.calendar.nil?
|
||||
self.public = (self.try(:object).nil?)? (self.calendar.try(:public?)) : object.try(:public?)
|
||||
|
||||
@@ -103,15 +103,9 @@ class Neuigkeit < ActiveRecord::Base
|
||||
self.update_column(:cache_relevant_date, self.meeting.calentry.start.to_date)
|
||||
else
|
||||
if self.is_event?
|
||||
unless self.calentries.upcoming.first.nil?
|
||||
self.update_column(:cache_order, (self.calentries.upcoming.first.start.to_date - Date.today).to_i.abs)
|
||||
self.update_column(:cache_relevant_date, self.calentries.upcoming.first.start.to_date)
|
||||
else
|
||||
unless self.calentries.recent.first.nil?
|
||||
self.update_column(:cache_order, (self.calentries.recent.first.start.to_date - Date.today).to_i.abs)
|
||||
self.update_column(:cache_relevant_date, self.calentries.recent.first.start.to_date)
|
||||
end
|
||||
end
|
||||
c = n.calentries.min{|c| c.days_to_today * ((c.is_past?)? 2:1)}
|
||||
self.update_column(:cache_order, c.days_to_today * ((c.is_past?)? 2:1))
|
||||
self.update_column(:cache_relevant_date, (c.is_past?) ? c.ende.to_date : c.start.to_date)
|
||||
else
|
||||
unless self.datum.nil?
|
||||
self.update_column(:cache_order, (self.datum.to_date - Date.today).to_i.abs)
|
||||
|
||||
Reference in New Issue
Block a user