diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index adf5900..f7f0772 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -34,7 +34,7 @@ class SearchController < PublicController if !@empty_query full_text_search ['public:true'] elsif params[:filter] - @results[@asset] = @environment.articles.more_recent.paginate(paginate_options) + @results[@asset] = @environment.articles.public.send(@filter).paginate(paginate_options) end end @@ -228,7 +228,7 @@ class SearchController < PublicController def filter_description(asset, filter) { 'articles_more_recent' => _('More recent contents from network'), - 'articles_more_popular' => _('More popular contents from network'), + 'articles_more_popular' => _('More read contents from network'), 'people_more_recent' => _('More recent people from network'), 'people_more_active' => _('More active people from network'), 'people_more_popular' => _('More popular people from network'), diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ca3017b..999d19b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1093,7 +1093,7 @@ module ApplicationHelper def search_contents_menu links = [ {s_('contents|More Recent') => {:href => url_for({:controller => 'search', :action => 'contents', :filter => 'more_recent'})}}, - #{s_('contents|More Popular') => {:href => url_for({:controller => 'search', :action => 'contents', :filter => 'more_popular'})}} + {s_('contents|More Read') => {:href => url_for({:controller => 'search', :action => 'contents', :filter => 'more_popular'})}} ] if logged_in? links.push(_('New Content') => lightbox_options({:href => url_for({:controller => 'cms', :action => 'new', :profile => current_user.login, :cms => true})})) diff --git a/app/models/article.rb b/app/models/article.rb index 5ca4e23..75e7f60 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -139,6 +139,9 @@ class Article < ActiveRecord::Base {:conditions => [ 'parent_id is null and profile_id = ?', profile.id ]} } + named_scope :public, + :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true ] + named_scope :more_recent, :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND ((articles.type != ?) OR articles.type is NULL)", @@ -146,6 +149,14 @@ class Article < ActiveRecord::Base ], :order => 'articles.published_at desc, articles.id desc' + # retrives the most commented articles, sorted by the comment count (largest + # first) + def self.most_commented(limit) + paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit) + end + + named_scope :more_popular, :order => 'hits DESC' + # retrieves the latest +limit+ articles, sorted from the most recent to the # oldest. # @@ -178,12 +189,6 @@ class Article < ActiveRecord::Base end end - # retrives the most commented articles, sorted by the comment count (largest - # first) - def self.most_commented(limit) - paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit) - end - # produces the HTML code that is to be displayed as this article's contents. # # The implementation in this class just provides the +body+ attribute as the -- libgit2 0.21.2