Class: StatisticsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/statistics_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_navable, #current_navable=, #current_user, #point_navigation_to, #redirect_www_subdomain, #set_locale

Instance Method Details

#indexObject



5
6
7
8
9
10
11
# File 'app/controllers/statistics_controller.rb', line 5

def index
  authorize! :index, :statistics
  
  @list_presets = [
    'corporation_joining_statistics', 'aktivitates_join_and_persist_statistics'
  ]
end

#showObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/statistics_controller.rb', line 13

def show
  authorize! :read, :statistics
  
  @list_preset = params[:list] || raise('no list preset given. use parameter "list".')
  
  case @list_preset
  when 'corporation_joining_statistics'
    @list_export = ListExport.new(Group.corporations_parent, 'join_statistics')
  when 'aktivitates_join_and_persist_statistics'
    @list_export = ListExport.new(Group.alle_aktiven, 'join_and_persist_statistics')
  else
    raise "statistics preset unknown: #{@list_preset}."
  end

  respond_to do |format|
    format.html  # render view
    format.csv do
      authorize! :export, :statistics
      
      bom = "\xEF\xBB\xBF".force_encoding('utf-8') # UTF-8
      send_data (bom + @list_export.to_csv), filename: ("#{t @list_preset} #{Time.zone.now}".parameterize + ".csv")
    end
  end
end