diff --git a/app/cells/content/articles_authors_list.html.erb b/app/cells/content/articles_authors_list.html.erb
new file mode 100644
index 0000000..2030f5c
--- /dev/null
+++ b/app/cells/content/articles_authors_list.html.erb
@@ -0,0 +1,6 @@
+
Authors
+
+ <% @authors.each do |author| %>
+ - <%= link_to "#{author.firstname} #{author.lastname} (#{author.articles.count})", "#{@url}?author=#{author.pretty_url}" %>
+ <% end %>
+
diff --git a/app/cells/content/articles_categories_list.html.erb b/app/cells/content/articles_categories_list.html.erb
index f2e7c7e..fb423a2 100644
--- a/app/cells/content/articles_categories_list.html.erb
+++ b/app/cells/content/articles_categories_list.html.erb
@@ -1,3 +1,4 @@
+Categories
<% @categories.each do |category| %>
- <%= link_to "#{category.name} (#{category.articles_count})", "#{@url}?category=#{category.pretty_url}" %>
diff --git a/app/cells/content_cell.rb b/app/cells/content_cell.rb
index 50ca76c..5b7cdfd 100644
--- a/app/cells/content_cell.rb
+++ b/app/cells/content_cell.rb
@@ -27,8 +27,19 @@ def articles_list(args)
@articles = @articles.where("categorizations.category_id IN (?)", args[:options][:categories]) if args[:options][:categories]
else
# show only current category
- @meta_title = I18n.t 'public.articles.category', :name => Category.find_by_pretty_url( params[:category] ).name
- @articles = @articles.joins(:categories).where( "categories.pretty_url = ?", params[:category] )
+ category = Category.find_by_pretty_url( params[:category] )
+ if category
+ @meta_title = I18n.t 'public.articles.category', :name => category.name
+ @articles = @articles.joins(:categories).where( "categories.pretty_url = ?", params[:category] )
+ end
+ end
+
+ unless params[:author].blank?
+ author = User.find_by_pretty_url( params[:author] )
+ if author
+ @meta_title = I18n.t 'public.articles.author', :name => "#{author.firstname} #{author.lastname}"
+ @articles = @articles.joins(:user).where( "users.pretty_url" => params[:author])
+ end
end
per_page = ( args[:options][:per_page].blank? )? 10 : args[:options][:per_page]
@@ -43,6 +54,12 @@ def articles_categories_list(args)
render
end
+ def articles_authors_list(args)
+ @authors = User.active_writers
+ @url = args[:options][:archive_url]
+ render
+ end
+
def twitter_stream(args)
render
end
diff --git a/app/cells/content_cell.yml b/app/cells/content_cell.yml
index 2c6896b..089deb9 100644
--- a/app/cells/content_cell.yml
+++ b/app/cells/content_cell.yml
@@ -29,6 +29,11 @@ cell:
desc: List all the categories with published articles
serialized_attributes:
archive_url: string
+ - name: Articles Authors
+ method: articles_authors_list
+ desc: List all the users with published articles
+ serialized_attributes:
+ archive_url: string
- name: Twitter stream
method: twitter_stream
desc: Stream of tweets from a twitter account
diff --git a/app/models/user.rb b/app/models/user.rb
index 166bedb..9dc0b61 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -5,7 +5,7 @@ class User < ActiveRecord::Base
# Setup accessible (or protected) attributes for your model
attr_accessible :firstname, :lastname, :email, :password, :password_confirmation, :remember_me, :lang, :pretty_url
-
+
has_many :grades
has_many :roles, :through => :grades
accepts_nested_attributes_for :grades
@@ -19,11 +19,13 @@ class User < ActiveRecord::Base
validates :lastname, :presence => true
validates :password, :presence => true, :length => { :minimum => 8 }
validates :password_confirmation, :presence => true, :length => { :minimum => 8 }
-
+
scope :admins, includes(:grades, :roles).where("roles.name = ?", "admin")
scope :writers, includes(:grades, :roles).where("roles.name = ?", "article_writer")
scope :premiums, includes(:grades, :roles).where("roles.name = ?", "premium_user")
+ scope :active_writers, joins(:articles).select('DISTINCT users.*')
+
# = CSV export =
comma do
id
diff --git a/config/locales/en.yml b/config/locales/en.yml
index a479785..0c6aea8 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -260,6 +260,7 @@ en:
article: Article
all_categories: "All categories"
category: "Articles in category %{name}"
+ author: "Articles by %{name}"
pages:
pages: Pages
page: Page
diff --git a/config/locales/it.yml b/config/locales/it.yml
index 50810d6..77dc136 100644
--- a/config/locales/it.yml
+++ b/config/locales/it.yml
@@ -253,6 +253,7 @@ it:
article: Articolo
all_categories: "Tutte le categorie"
category: "Articoli nella categoria %{name}"
+ author: "Articoli di %{name}"
pages:
pages: Pagine
page: Pagina