Commit 1b279971afe4a74edf521c4470a719b4d4e23e21
1 parent
75619850
Exists in
master
and in
29 other branches
relevant_content: refactoring most accessed from article
Showing
1 changed file
with
8 additions
and
19 deletions
Show diff stats
plugins/relevant_content/lib/ext/article.rb
| @@ -5,24 +5,13 @@ class Article | @@ -5,24 +5,13 @@ class Article | ||
| 5 | named_scope :relevant_content, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'Blog' and articles.type != 'RssFeed') OR articles.type is NULL"] | 5 | named_scope :relevant_content, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'Blog' and articles.type != 'RssFeed') OR articles.type is NULL"] |
| 6 | 6 | ||
| 7 | def self.most_accessed(owner, limit = nil) | 7 | def self.most_accessed(owner, limit = nil) |
| 8 | - if owner.kind_of?(Environment) | ||
| 9 | - result = Article.relevant_content.find( | ||
| 10 | - :all, | ||
| 11 | - :order => 'hits desc', | ||
| 12 | - :limit => limit, | ||
| 13 | - :conditions => ["hits > 0"] | ||
| 14 | - ) | ||
| 15 | - result.paginate({:page => 1, :per_page => limit}) | ||
| 16 | - else | ||
| 17 | - #Owner is a profile | ||
| 18 | - result = Article.relevant_content.find( | ||
| 19 | - :all, | ||
| 20 | - :order => 'hits desc', | ||
| 21 | - :limit => limit, | ||
| 22 | - :conditions => ["profile_id = ? and hits > 0", owner.id] | ||
| 23 | - ) | ||
| 24 | - result.paginate({:page => 1, :per_page => limit}) | ||
| 25 | - end | 8 | + conditions = owner.kind_of?(Environment) ? ["hits > 0"] : ["profile_id = ? and hits > 0", owner.id] |
| 9 | + result = Article.relevant_content.find( | ||
| 10 | + :all, | ||
| 11 | + :order => 'hits desc', | ||
| 12 | + :limit => limit, | ||
| 13 | + :conditions => conditions) | ||
| 14 | + result.paginate({:page => 1, :per_page => limit}) | ||
| 26 | end | 15 | end |
| 27 | 16 | ||
| 28 | def self.most_commented_relevant_content(owner, limit) | 17 | def self.most_commented_relevant_content(owner, limit) |
| @@ -191,4 +180,4 @@ class Article | @@ -191,4 +180,4 @@ class Article | ||
| 191 | 180 | ||
| 192 | 181 | ||
| 193 | 182 | ||
| 194 | -end | ||
| 195 | \ No newline at end of file | 183 | \ No newline at end of file |
| 184 | +end |