diff options
author | James Thompson <james.b.thompson@gmail.com> | 2012-03-14 11:40:16 +0200 |
---|---|---|
committer | James Thompson <james.b.thompson@gmail.com> | 2012-03-14 11:40:16 +0200 |
commit | 56d7747f54e86993415b76c92e101608e5ea44e2 (patch) | |
tree | 025b7b37f50c4c291e7e676286e7767c40adb1f9 /app/models/refinery/banners | |
download | refinerycms-pc_banners-56d7747f54e86993415b76c92e101608e5ea44e2.tar.gz refinerycms-pc_banners-56d7747f54e86993415b76c92e101608e5ea44e2.tar.bz2 refinerycms-pc_banners-56d7747f54e86993415b76c92e101608e5ea44e2.zip |
initial commit
Diffstat (limited to 'app/models/refinery/banners')
-rw-r--r-- | app/models/refinery/banners/banner.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/app/models/refinery/banners/banner.rb b/app/models/refinery/banners/banner.rb new file mode 100644 index 0000000..eaa1713 --- /dev/null +++ b/app/models/refinery/banners/banner.rb @@ -0,0 +1,27 @@ +module Refinery + module Banners + class Banner < Refinery::Core::BaseModel + self.table_name = 'refinery_banners' + + acts_as_indexed :fields => [:name, :url, :title, :description] + + validates :name, :presence => true + validates_presence_of :start_date + validates_length_of :title, :in => 0..255, :allow_nil => true + validates_length_of :description, :in => 0..255, :allow_nil => true + + belongs_to :image, :class_name => '::Refinery::Image' + has_and_belongs_to_many :pages, :class_name => '::Refinery::Page', :join_table => 'refinery_banners_pages' + + scope :not_expired, lambda { + banners = Arel::Table.new(::Refinery::Banners::Banner.table_name) + where(banners[:expiry_date].eq(nil).or(banners[:expiry_date].gt(Time.now))) + } + scope :active, where(:is_active => true) + scope :published, lambda { + not_expired.active.where("start_date <= ?", Time.now).order(:position) + } + + end + end +end
\ No newline at end of file |