forked from bofh/fetsite
neuigkeiten sort und ability
This commit is contained in:
@@ -92,7 +92,7 @@ class Ability
|
||||
# Rechteverwaltung fuer Neuigkeiten
|
||||
can :index, Rubrik
|
||||
can [:show], Rubrik, :public=>true
|
||||
can [:list], Neuigkeit, Neuigkeit.public.published
|
||||
can [:list], Neuigkeit, :cache_published=>true, :public=>true
|
||||
can :show, Neuigkeit, :rubrik=>{:public=>true}
|
||||
|
||||
if loggedin
|
||||
|
||||
@@ -40,7 +40,10 @@ class Neuigkeit < ActiveRecord::Base
|
||||
|
||||
|
||||
def is_annoncement?
|
||||
self.meeting.nil?
|
||||
!self.meeting.nil?
|
||||
end
|
||||
def has_meeting?
|
||||
!self.meeting.nil?
|
||||
end
|
||||
def self.published
|
||||
where("datum <= ? AND datum IS NOT NULL", Time.now.to_date)
|
||||
@@ -94,7 +97,11 @@ class Neuigkeit < ActiveRecord::Base
|
||||
self.has_calentries?
|
||||
end
|
||||
def update_cache
|
||||
if is_event?
|
||||
if self.has_meeting? && !self.meeting.calentry.nil?
|
||||
self.update_column(:cache_order, (self.meeting.calentry.start.to_date - Date.today).to_i.abs)
|
||||
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)
|
||||
@@ -112,6 +119,7 @@ class Neuigkeit < ActiveRecord::Base
|
||||
self.update_column(:cache_order,0)
|
||||
end
|
||||
end
|
||||
end
|
||||
unless self.published?
|
||||
self.update_column(:cache_order, self.cache_order-14)
|
||||
end
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
every 1.day, :at =>'5:00 am' do
|
||||
rake "-s sitemap:refresh"
|
||||
end
|
||||
every 1.day, :at =>'4:00 am' do
|
||||
rake "-s neuigkeit_cache:update"
|
||||
end
|
||||
|
||||
7
lib/tasks/neuigkeit_cache.rake
Normal file
7
lib/tasks/neuigkeit_cache.rake
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace :neuigkeit_cache do
|
||||
task :update =>:environment do
|
||||
Neuigkeit.all.each do |n|
|
||||
n.update_cache
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user