Project

General

Profile

Feature #2848 » timelog_controller.rb.patch

Brad Beattie, 2009-02-26 19:34

View differences:

app/controllers/timelog_controller.rb (working copy)
31 31
  
32 32
  def report
33 33
    @available_criterias = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id",
34
                                          :order => "#{Project.table_name}.name",
34 35
                                          :klass => Project,
35 36
                                          :label => :label_project},
36 37
                             'version' => {:sql => "#{Issue.table_name}.fixed_version_id",
38
                                          :order => "#{Issue.table_name}.fixed_version_id",
37 39
                                          :klass => Version,
38 40
                                          :label => :label_version},
39 41
                             'category' => {:sql => "#{Issue.table_name}.category_id",
42
                                            :order => "#{Issue.table_name}.category_id",
40 43
                                            :klass => IssueCategory,
41 44
                                            :label => :field_category},
42 45
                             'member' => {:sql => "#{TimeEntry.table_name}.user_id",
46
                                         :order => "#{User.table_name}.firstname,#{User.table_name}.lastname",
43 47
                                         :klass => User,
44 48
                                         :label => :label_member},
45 49
                             'tracker' => {:sql => "#{Issue.table_name}.tracker_id",
50
                                          :order => "#{Issue.table_name}.tracker_id",
46 51
                                          :klass => Tracker,
47 52
                                          :label => :label_tracker},
48 53
                             'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
54
                                           :order => "#{TimeEntry.table_name}.activity_id",
49 55
                                           :klass => Enumeration,
50 56
                                           :label => :label_activity},
51 57
                             'issue' => {:sql => "#{TimeEntry.table_name}.issue_id",
58
                                         :order => "#{TimeEntry.table_name}.issue_id",
52 59
                                         :klass => Issue,
53 60
                                         :label => :label_issue}
54 61
                           }
......
80 87
    unless @criterias.empty?
81 88
      sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ')
82 89
      sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ')
90
      sql_order_by = @criterias.collect{|criteria| @available_criterias[criteria][:order]}.join(', ')
83 91
      
84 92
      sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours"
85 93
      sql << " FROM #{TimeEntry.table_name}"
86 94
      sql << " LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id"
87 95
      sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id"
96
      sql << " LEFT JOIN #{User.table_name} ON #{TimeEntry.table_name}.user_id = #{User.table_name}.id"
88 97
      sql << " WHERE"
89 98
      sql << " (%s) AND" % @project.project_condition(Setting.display_subprojects_issues?) if @project
90 99
      sql << " (%s) AND" % Project.allowed_to_condition(User.current, :view_time_entries)
91 100
      sql << " (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from.to_time), ActiveRecord::Base.connection.quoted_date(@to.to_time)]
92 101
      sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on"
102
      sql << " ORDER BY #{sql_order_by}"
93 103
      
94 104
      @hours = ActiveRecord::Base.connection.select_all(sql)
95 105
      
(1-1/5)