diff --git a/lib/orbit_model/approval.rb b/lib/orbit_model/approval.rb index 99c27c0d5..5f5815417 100644 --- a/lib/orbit_model/approval.rb +++ b/lib/orbit_model/approval.rb @@ -9,9 +9,12 @@ module OrbitModel field :is_pending, :type => Boolean, :default => true field :is_rejected, :type => Boolean, :default => false field :not_checked_reason - class_variable_defined?(:@@can_display) ? \ - class_variable_set(:@@can_display, class_variable_get(:@@can_display).merge({is_checked: true, is_rejected: false, is_pending: false})) : \ - class_variable_set(:@@can_display, {is_checked: true, is_rejected: false, is_pending: false}) + query = {type: 'where', conditions: {is_checked: true, is_rejected: false, is_pending: false}} + if class_variable_defined?(:@@can_display) + class_variable_set(:@@can_display, (class_variable_get(:@@can_display) << query)) + else + class_variable_set(:@@can_display, [query]) + end send :include, InstanceMethods end end @@ -54,9 +57,14 @@ module OrbitModel module ClassMethods define_method(:can_display) do - where(class_variable_get(:@@can_display)) + final_query = class_variable_get(:@@can_display).inject('') do |result, query_hash| + result << "." if result.present? + result << "#{query_hash[:type]}(#{query_hash[:conditions]})" + result + end + eval(final_query) end unless method_defined? :can_display - + end end diff --git a/lib/orbit_model/status.rb b/lib/orbit_model/status.rb index 2b2fed7ae..672ebb478 100644 --- a/lib/orbit_model/status.rb +++ b/lib/orbit_model/status.rb @@ -8,9 +8,12 @@ module OrbitModel field :is_top, :type => Boolean, :default => false field :is_hot, :type => Boolean, :default => false field :is_hidden, :type => Boolean, :default => false - self.class_variable_defined?(:@@can_display) ? \ - self.class_variable_set(:@@can_display, self.class_variable_get(:@@can_display).merge({is_hidden: false})) : \ - self.class_variable_set(:@@can_display, {is_hidden: false}) + query = {type: 'where', conditions: {is_hidden: false}} + if class_variable_defined?(:@@can_display) + class_variable_set(:@@can_display, (class_variable_get(:@@can_display) << query)) + else + class_variable_set(:@@can_display, [query]) + end send :include, InstanceMethods end end @@ -34,7 +37,12 @@ module OrbitModel module ClassMethods define_method(:can_display) do - where(class_variable_get(:@@can_display)) + final_query = class_variable_get(:@@can_display).inject('') do |result, query_hash| + result << "." if result.present? + result << "#{query_hash[:type]}(#{query_hash[:conditions]})" + result + end + eval(final_query) end unless method_defined? :can_display end diff --git a/lib/orbit_model/time_frame.rb b/lib/orbit_model/time_frame.rb index 7e87a3c1b..aa5f0256f 100644 --- a/lib/orbit_model/time_frame.rb +++ b/lib/orbit_model/time_frame.rb @@ -3,10 +3,17 @@ module OrbitModel module TimeFrame def self.included(base) + base.extend ClassMethods base.class_eval do field :postdate , :type => DateTime field :deadline , :type => DateTime before_save :check_deadline + query = {type: 'any_of', conditions: "{deadline: nil, :postdate.lte => Time.now} , {:deadline.gte => Time.now, :postdate.lte => Time.now}"} + if class_variable_defined?(:@@can_display) + class_variable_set(:@@can_display, (class_variable_get(:@@can_display) << query)) + else + class_variable_set(:@@can_display, [query]) + end send :include, InstanceMethods end end @@ -27,6 +34,19 @@ module OrbitModel end + module ClassMethods + + define_method(:can_display) do + final_query = class_variable_get(:@@can_display).inject('') do |result, query_hash| + result << "." if result.present? + result << "#{query_hash[:type]}(#{query_hash[:conditions]})" + result + end + eval(final_query) + end unless method_defined? :can_display + + end + end end \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb index 07bf4f032..c4ccb351a 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb @@ -43,15 +43,15 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController else date_now = Time.now if !params[:category_id].blank? && !params[:tag_id].blank? - @bulletins = Bulletin.available_for_lang(I18n.locale).can_display.where(:category_id => params[:category_id], :tagged_ids => params[:tag_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num) + @bulletins = Bulletin.available_for_lang(I18n.locale).can_display.where(:category_id => params[:category_id], :tagged_ids => params[:tag_id]).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num) @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil elsif !params[:category_id].blank? - @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.where(:category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num) + @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.where(:category_id => params[:category_id]).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num) @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil elsif !params[:tag_id].blank? - @bulletins = Bulletin.available_for_lang(I18n.locale).can_display.where(:tagged_ids => params[:tag_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num) + @bulletins = Bulletin.available_for_lang(I18n.locale).can_display.where(:tagged_ids => params[:tag_id]).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num) else - @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num) + @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.desc( :is_top, :postdate).page( params[:page_main]).per(@page_num) end delayed_impressionist(@tag) if @tag end diff --git a/vendor/built_in_modules/announcement/init.rb b/vendor/built_in_modules/announcement/init.rb index cb1b9fb63..c27d709ff 100644 --- a/vendor/built_in_modules/announcement/init.rb +++ b/vendor/built_in_modules/announcement/init.rb @@ -32,7 +32,7 @@ module Announcement widgets do default_widget do - query 'Bulletin.any_of( {deadline: nil,:postdate.lte => Time.now} , {:deadline.gte => Time.now,:postdate.lte => Time.now} )' + query 'Bulletin' enable ["typeA", "typeB_style3", "typeC"] image :image field :postdate