summaryrefslogtreecommitdiffstats
path: root/app/helpers
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2018-08-05 12:30:40 +0000
committerGo MAEDA <maeda@farend.jp>2018-08-05 12:30:40 +0000
commit83939be2b52c07cbb0d4dc6f784b979c10cc4229 (patch)
tree281e118c9b751c54787b601b96663b4fc919bee6 /app/helpers
parenteee1c36b4b7f0cee23ebc5d3848fa2b606f603c8 (diff)
downloadredmine-83939be2b52c07cbb0d4dc6f784b979c10cc4229.tar.gz
redmine-83939be2b52c07cbb0d4dc6f784b979c10cc4229.zip
Export users list to CSV (#5957).
Contriubted by Mizuki ISHIKAWA and Yuki Kita. git-svn-id: http://svn.redmine.org/redmine/trunk@17463 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/users_helper.rb35
1 files changed, 31 insertions, 4 deletions
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index d7812867b..c0d954499 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -18,12 +18,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module UsersHelper
+ include ApplicationHelper
+
def users_status_options_for_select(selected)
user_count_by_status = User.group('status').count.to_hash
- options_for_select([[l(:label_all), ''],
- ["#{l(:status_active)} (#{user_count_by_status[1].to_i})", '1'],
- ["#{l(:status_registered)} (#{user_count_by_status[2].to_i})", '2'],
- ["#{l(:status_locked)} (#{user_count_by_status[3].to_i})", '3']], selected.to_s)
+ options_for_select([[l(:label_all), '']] + (User.valid_statuses.map {|c| ["#{l('status_' + User::LABEL_BY_STATUS[c])} (#{user_count_by_status[c].to_i})", c]}), selected.to_s)
end
def user_mail_notification_options(user)
@@ -61,4 +60,32 @@ module UsersHelper
end
tabs
end
+
+ def users_to_csv(users)
+ Redmine::Export::CSV.generate(:encoding => params[:encoding]) do |csv|
+ columns = [
+ 'login',
+ 'firstname',
+ 'lastname',
+ 'mail',
+ 'admin',
+ 'created_on',
+ 'last_login_on',
+ 'status'
+ ]
+
+ # csv header fields
+ csv << columns.map{|column| l('field_' + column)}
+ # csv lines
+ users.each do |user|
+ csv << columns.map do |column|
+ if column == 'status'
+ l(("status_#{User::LABEL_BY_STATUS[user.status]}"))
+ else
+ format_object(user.send(column), false)
+ end
+ end
+ end
+ end
+ end
end