app/models/alchemy/page/page_scopes.rb in alchemy_cms-3.3.3 vs app/models/alchemy/page/page_scopes.rb in alchemy_cms-3.4.0.rc1

- old
+ new

@@ -13,11 +13,11 @@ # scope :layoutpages, -> { where(layoutpage: true) } # All locked pages # - scope :locked, -> { where(locked: true) } + scope :locked, -> { where.not(locked_at: nil, locked_by: nil) } # All pages locked by given user # scope :locked_by, ->(user) { if user.class.respond_to? :primary_key @@ -25,20 +25,16 @@ end } # All not locked pages # - scope :not_locked, -> { where(locked: false) } + scope :not_locked, -> { where(locked_at: nil, locked_by: nil) } # All visible pages # scope :visible, -> { where(visible: true) } - # All public pages - # - scope :published, -> { where(public: true) } - # All not restricted pages # scope :not_restricted, -> { where(restricted: false) } # All restricted pages @@ -96,8 +92,26 @@ } # All pages for xml sitemap # scope :sitemap, -> { from_current_site.published.contentpages.where(sitemap: true) } + end + + module ClassMethods + # All public pages + # + def published + where("#{table_name}.public_on <= :time AND " \ + "(#{table_name}.public_until IS NULL " \ + "OR #{table_name}.public_until >= :time)", time: Time.current) + end + + # All not public pages + # + def not_public + where("#{table_name}.public_on IS NULL OR " \ + "#{table_name}.public_on >= :time OR " \ + "#{table_name}.public_until <= :time", time: Time.current) + end end end end