aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/blog_comment.rb23
-rw-r--r--app/models/blog_post.rb30
2 files changed, 41 insertions, 12 deletions
diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb
index b888e35..9b84ece 100644
--- a/app/models/blog_comment.rb
+++ b/app/models/blog_comment.rb
@@ -60,11 +60,16 @@ class BlogComment < ActiveRecord::Base
end
def toggle!
- RefinerySetting[:comment_moderation] = {
- :value => !self.enabled?,
+ new_value = {
+ :value => !BlogComment::Moderation.enabled?,
:scoping => :blog,
:restricted => false
}
+ if RefinerySetting.respond_to?(:set)
+ RefinerySetting.set(:comment_moderation, new_value)
+ else
+ RefinerySetting[:comment_moderation] = new_value
+ end
end
end
end
@@ -80,11 +85,16 @@ class BlogComment < ActiveRecord::Base
end
def recipients=(emails)
- RefinerySetting[:comment_notification_recipients] = {
+ new_value = {
:value => emails,
:scoping => :blog,
:restricted => false
}
+ if RefinerySetting.respond_to?(:set)
+ RefinerySetting.set(:comment_notification_recipients, new_value)
+ else
+ RefinerySetting[:comment_notification_recipients] = new_value
+ end
end
def subject
@@ -95,11 +105,16 @@ class BlogComment < ActiveRecord::Base
end
def subject=(subject_line)
- RefinerySetting[:comment_notification_subject] = {
+ new_value = {
:value => subject_line,
:scoping => :blog,
:restricted => false
}
+ if RefinerySetting.respond_to?(:set)
+ RefinerySetting.set(:comment_notification_subject, new_value)
+ else
+ RefinerySetting[:comment_notification_subject] = new_value
+ end
end
end
end
diff --git a/app/models/blog_post.rb b/app/models/blog_post.rb
index 562a9b9..471be72 100644
--- a/app/models/blog_post.rb
+++ b/app/models/blog_post.rb
@@ -9,27 +9,41 @@ class BlogPost < ActiveRecord::Base
validates_uniqueness_of :title
has_friendly_id :title, :use_slug => true
-
- default_scope :order => "published_at DESC"
if Rails.version < '3.0.0'
- named_scope :by_archive, lambda { |archive_date| {:conditions => ['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]} }
+ named_scope :by_archive, lambda { |archive_date| {:conditions => ['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month], :order => "published_at DESC"} }
else
scope :by_archive, lambda { |archive_date|
- where ['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]
+ where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]).order("published_at DESC")
}
end
if Rails.version < '3.0.0'
- named_scope :all_previous, :conditions => ['published_at <= ?', Time.now.beginning_of_month]
+ named_scope :all_previous, :conditions => ['published_at <= ?', Time.now.beginning_of_month], :order => "published_at DESC"
else
- scope :all_previous, where(['published_at <= ?', Time.now.beginning_of_month])
+ scope :all_previous, where(['published_at <= ?', Time.now.beginning_of_month]).order("published_at DESC")
end
if Rails.version < '3.0.0'
- named_scope :live, lambda { {:conditions => ["published_at < ? and draft = ?", Time.now, false]} }
+ named_scope :live, lambda { {:conditions => ["published_at < ? and draft = ?", Time.now, false], :order => "published_at DESC"} }
+ else
+ scope :live, lambda { where( "published_at < ? and draft = ?", Time.now, false).order("published_at DESC") }
+ end
+
+ if Rails.version < '3.0.0'
+ named_scope :previous, lambda { |i| { :conditions => ["published_at < ?", i.published_at], :order => "published_at DESC", :limit => 1 } }
+ named_scope :next, lambda { |i| { :condtions => ["published_at > ?", i.published_at], :order => "published_at ASC", :limit => 1 } }
else
- scope :live, lambda { where( "published_at < ? and draft = ?", Time.now, false) }
+ scope :previous, lambda { |i| where(["published_at < ?", i.published_at]).order("published_at DESC").limit(1) }
+ scope :next, lambda { |i| where(["published_at > ?", i.published_at]).order("published_at ASC").limit(1) }
+ end
+
+ def next
+ self.class.next(self).first
+ end
+
+ def prev
+ self.class.previous(self).first
end
def live?