@@ -1182,58 +1182,61 class Issue < ActiveRecord::Base | |||||
1182 | end |
|
1182 | end | |
1183 | end |
|
1183 | end | |
1184 |
|
1184 | |||
1185 | # Extracted from the ReportsController. |
|
|||
1186 | def self.by_tracker(project) |
|
1185 | def self.by_tracker(project) | |
1187 | count_and_group_by(:project => project, |
|
1186 | count_and_group_by(:project => project, :association => :tracker) | |
1188 | :field => 'tracker_id', |
|
|||
1189 | :joins => Tracker.table_name) |
|
|||
1190 | end |
|
1187 | end | |
1191 |
|
1188 | |||
1192 | def self.by_version(project) |
|
1189 | def self.by_version(project) | |
1193 | count_and_group_by(:project => project, |
|
1190 | count_and_group_by(:project => project, :association => :fixed_version) | |
1194 | :field => 'fixed_version_id', |
|
|||
1195 | :joins => Version.table_name) |
|
|||
1196 | end |
|
1191 | end | |
1197 |
|
1192 | |||
1198 | def self.by_priority(project) |
|
1193 | def self.by_priority(project) | |
1199 | count_and_group_by(:project => project, |
|
1194 | count_and_group_by(:project => project, :association => :priority) | |
1200 | :field => 'priority_id', |
|
|||
1201 | :joins => IssuePriority.table_name) |
|
|||
1202 | end |
|
1195 | end | |
1203 |
|
1196 | |||
1204 | def self.by_category(project) |
|
1197 | def self.by_category(project) | |
1205 | count_and_group_by(:project => project, |
|
1198 | count_and_group_by(:project => project, :association => :category) | |
1206 | :field => 'category_id', |
|
|||
1207 | :joins => IssueCategory.table_name) |
|
|||
1208 | end |
|
1199 | end | |
1209 |
|
1200 | |||
1210 | def self.by_assigned_to(project) |
|
1201 | def self.by_assigned_to(project) | |
1211 | count_and_group_by(:project => project, |
|
1202 | count_and_group_by(:project => project, :association => :assigned_to) | |
1212 | :field => 'assigned_to_id', |
|
|||
1213 | :joins => User.table_name) |
|
|||
1214 | end |
|
1203 | end | |
1215 |
|
1204 | |||
1216 | def self.by_author(project) |
|
1205 | def self.by_author(project) | |
1217 | count_and_group_by(:project => project, |
|
1206 | count_and_group_by(:project => project, :association => :author) | |
1218 | :field => 'author_id', |
|
|||
1219 | :joins => User.table_name) |
|
|||
1220 | end |
|
1207 | end | |
1221 |
|
1208 | |||
1222 | def self.by_subproject(project) |
|
1209 | def self.by_subproject(project) | |
1223 | ActiveRecord::Base.connection.select_all("select s.id as status_id, |
|
1210 | r = count_and_group_by(:project => project, :with_subprojects => true, :association => :project) | |
1224 | s.is_closed as closed, |
|
1211 | r.reject {|r| r["project_id"] == project.id.to_s} | |
1225 | #{Issue.table_name}.project_id as project_id, |
|
1212 | end | |
1226 | count(#{Issue.table_name}.id) as total |
|
1213 | ||
1227 | from |
|
1214 | # Query generator for selecting groups of issue counts for a project | |
1228 | #{Issue.table_name}, #{Project.table_name}, #{IssueStatus.table_name} s |
|
1215 | # based on specific criteria | |
1229 | where |
|
1216 | # | |
1230 | #{Issue.table_name}.status_id=s.id |
|
1217 | # Options | |
1231 | and #{Issue.table_name}.project_id = #{Project.table_name}.id |
|
1218 | # * project - Project to search in. | |
1232 | and #{visible_condition(User.current, :project => project, :with_subprojects => true)} |
|
1219 | # * with_subprojects - Includes subprojects issues if set to true. | |
1233 | and #{Issue.table_name}.project_id <> #{project.id} |
|
1220 | # * association - Symbol. Association for grouping. | |
1234 | group by s.id, s.is_closed, #{Issue.table_name}.project_id") if project.descendants.active.any? |
|
1221 | def self.count_and_group_by(options) | |
1235 | end |
|
1222 | assoc = reflect_on_association(options[:association]) | |
1236 | # End ReportsController extraction |
|
1223 | select_field = assoc.foreign_key | |
|
1224 | ||||
|
1225 | Issue. | |||
|
1226 | visible(User.current, :project => options[:project], :with_subprojects => options[:with_subprojects]). | |||
|
1227 | joins(:status). | |||
|
1228 | group(:status_id, :is_closed, select_field). | |||
|
1229 | count. | |||
|
1230 | map do |columns, total| | |||
|
1231 | status_id, is_closed, field_value = columns | |||
|
1232 | { | |||
|
1233 | "status_id" => status_id.to_s, | |||
|
1234 | "closed" => is_closed.to_s, | |||
|
1235 | select_field => field_value.to_s, | |||
|
1236 | "total" => total.to_s | |||
|
1237 | } | |||
|
1238 | end | |||
|
1239 | end | |||
1237 |
|
1240 | |||
1238 | # Returns a scope of projects that user can assign the issue to |
|
1241 | # Returns a scope of projects that user can assign the issue to | |
1239 | def allowed_target_projects(user=User.current) |
|
1242 | def allowed_target_projects(user=User.current) | |
@@ -1565,32 +1568,4 class Issue < ActiveRecord::Base | |||||
1565 | @assigned_to_was = nil |
|
1568 | @assigned_to_was = nil | |
1566 | @previous_assigned_to_id = nil |
|
1569 | @previous_assigned_to_id = nil | |
1567 | end |
|
1570 | end | |
1568 |
|
||||
1569 | # Query generator for selecting groups of issue counts for a project |
|
|||
1570 | # based on specific criteria |
|
|||
1571 | # |
|
|||
1572 | # Options |
|
|||
1573 | # * project - Project to search in. |
|
|||
1574 | # * field - String. Issue field to key off of in the grouping. |
|
|||
1575 | # * joins - String. The table name to join against. |
|
|||
1576 | def self.count_and_group_by(options) |
|
|||
1577 | project = options.delete(:project) |
|
|||
1578 | select_field = options.delete(:field) |
|
|||
1579 | joins = options.delete(:joins) |
|
|||
1580 |
|
||||
1581 | where = "#{Issue.table_name}.#{select_field}=j.id" |
|
|||
1582 |
|
||||
1583 | ActiveRecord::Base.connection.select_all("select s.id as status_id, |
|
|||
1584 | s.is_closed as closed, |
|
|||
1585 | j.id as #{select_field}, |
|
|||
1586 | count(#{Issue.table_name}.id) as total |
|
|||
1587 | from |
|
|||
1588 | #{Issue.table_name}, #{Project.table_name}, #{IssueStatus.table_name} s, #{joins} j |
|
|||
1589 | where |
|
|||
1590 | #{Issue.table_name}.status_id=s.id |
|
|||
1591 | and #{where} |
|
|||
1592 | and #{Issue.table_name}.project_id=#{Project.table_name}.id |
|
|||
1593 | and #{visible_condition(User.current, :project => project)} |
|
|||
1594 | group by s.id, s.is_closed, j.id") |
|
|||
1595 | end |
|
|||
1596 | end |
|
1571 | end |
General Comments 0
You need to be logged in to leave comments.
Login now