From 2d2e01115b9522f4b250820fa72428d50fd58abd Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Fri, 3 Aug 2012 01:44:06 +0800 Subject: [PATCH] Fix page: take category and tag at the same time With news and announcement views --- app/controllers/pages_controller.rb | 1 + .../front_end/bulletins_controller.rb | 8 ++++- .../front_end/news_bulletins_controller.rb | 29 +++++++++---------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 7a0ffa437..690d94a7f 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -64,6 +64,7 @@ class PagesController < ApplicationController module_app = ModuleApp.first(:conditions => {:key => params[:app_name]}) if !params[:category_id].blank? && !params[:tag_id].blank? @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => params[:tag_id]}) + @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id]}) unless @item elsif !params[:category_id].blank? @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id]}) elsif !params[:tag_id].blank? 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 d970ee1c4..93911aeba 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 @@ -18,7 +18,12 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.any_in(_id:search_result).page( params[:page_main]).per(15) else date_now = Time.now - if !params[:category_id].blank? + if !params[:category_id].blank? && !params[:tag_id].blank? + @tag = AnnouncementTag.find(params[:tag_id]) rescue nil + @tag = AnnouncementTag.where(key: params[:tag_id])[0] unless @tag + @bulletins = @tag.bulletins.available_for_lang(I18n.locale).can_display.where(:bulletin_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(15) + @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(:bulletin_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(15) @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil elsif !params[:tag_id].blank? @@ -28,6 +33,7 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController 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(15) end + impressionist(@tag) if @tag end end diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb index 142017b79..ed15065bf 100644 --- a/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb +++ b/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb @@ -16,25 +16,24 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController search_result = search.collect{|t| t["id"]} @news_bulletins = NewsBulletin.all.available_for_lang(I18n.locale).can_display.any_in(_id:search_result).page( params[:page_main]).per(10) else - date_now = Time.now - if !params[:tag_id].blank? - tmp = NewsTag.find(params[:tag_id]) rescue nil - tmp = NewsTag.where(key: params[:tag_id])[0] unless tmp - impressionist(@tag) - end - - if !params[:category_id].blank? - @news_bulletins = NewsBulletin.all.available_for_lang(I18n.locale).can_display.where(:news_bulletin_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(10) + date_now = Time.now + if !params[:category_id].blank? && !params[:tag_id].blank? + @tag = NewsTag.find(params[:tag_id]) rescue nil + @tag = NewsTag.where(key: params[:tag_id])[0] unless @tag + @news_bulletins = @tag.news_bulletins.available_for_lang(I18n.locale).can_display.where(:news_bulletin_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(15) + @current_category = NewsBulletinCategory.from_id(params[:category_id]) rescue nil + elsif !params[:category_id].blank? + @news_bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.where(:news_bulletin_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(15) + @current_category = NewsBulletinCategory.from_id(params[:category_id]) rescue nil elsif !params[:tag_id].blank? - @news_bulletins = tmp.news_bulletins.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(10) rescue nil + @tag = NewsTag.find(params[:tag_id]) rescue nil + @tag = NewsTag.where(key: params[:tag_id])[0] unless @tag + @news_bulletins = @tag.news_bulletins.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(15) else - @news_bulletins = NewsBulletin.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(10) + @news_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(15) end + impressionist(@tag) if @tag end - get_categorys - - @current_category = NewsBulletinCategory.from_id(params[:category_id]) rescue nil - end def show