class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController # GET /bulletins # GET /bulletins.xml def index_bulletins_by_unit @item = Page.find(params[:page_id]) rescue nil @bulletins=Bulletin.all.available_for_lang(I18n.locale).can_display.where("cache_dept.#{I18n.locale.to_s.downcase}"=>params[:name]).page( params[:page_main]).per(15) render :index end def search_result if params[:search_query] == "" @bulletins = get_bulletins_for_index else key_string = params[:search_query] keywords = key_string.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/) regex = Regexp.union(keywords.map{|word| Regexp.new(".*"+word+".*", "i")}) query = ["title","subtitle","text"].map{|f| {f.to_sym => regex} } res = Bulletin.any_of(query) search_result = res.collect{|result| result.id} @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.any_in(_id:search_result).page( params[:page_main]).per(@page_num) end end def index @bulletins = get_bulletins_for_index end def get_bulletins_for_index @item = Page.find(params[:page_id]) rescue nil if @item if @item.frontend_data_count @page_num = @item.frontend_data_count else @page_num = 15 end @frontend_style = @item.frontend_style end 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.in => params[:category_id], :tagged_ids.in => params[:tag_id]).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num) # @bulletins = Bulletin.available_for_lang(I18n.locale).can_display.where(:category_id.in=>params[:category_id],:tagged_ids.in=>params[:tag_id]) @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.in => 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.in => 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.desc( :is_top, :postdate).page( params[:page_main]).per(@page_num) end # delayed_impressionist(@tag) if @tag @bulletins end def show @item = Page.find(params[:page_id]) rescue nil if params[:preview] == "true" preview_content else @bulletin = Bulletin.all.can_display.where(_id: params[:id]).first if @bulletin and !@bulletin.disable? if @bulletin.enabled_for_lang(I18n.locale.to_s) # delayed_impressionist(@bulletin) impressionist(@bulletin) else render :text => "