diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-11-28 10:08:29 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-11-28 10:08:29 +0000 |
commit | 915bbcfaff8a5db56bc60b90fb690b7f4be3b555 (patch) | |
tree | 9c784b5c3341edf416e83d1f919407e2aa53ad94 /app/models/query.rb | |
parent | 724141a39a2def885b3e195596424f21bb401c4d (diff) | |
download | redmine-915bbcfaff8a5db56bc60b90fb690b7f4be3b555.tar.gz redmine-915bbcfaff8a5db56bc60b90fb690b7f4be3b555.zip |
Move issues, journals, versions queries from IssuesController to Query model.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3103 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/query.rb')
-rw-r--r-- | app/models/query.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/app/models/query.rb b/app/models/query.rb index 816c5c5a0..d15f7c3c7 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -389,6 +389,55 @@ class Query < ActiveRecord::Base (filters_clauses << project_statement).join(' AND ') end + # Returns the issue count + def issue_count + Issue.count(:include => [:status, :project], :conditions => statement) + end + + # Returns the issue count by group or nil if query is not grouped + def issue_count_by_group + if grouped? + begin + # Rails will raise an (unexpected) RecordNotFound if there's only a nil group value + Issue.count(:group => group_by_statement, :include => [:status, :project], :conditions => statement) + rescue ActiveRecord::RecordNotFound + {nil => issue_count} + end + else + nil + end + end + + # Returns the issues + # Valid options are :order, :offset, :limit, :include, :conditions + def issues(options={}) + order_option = [group_by_sort_order, options[:order]].reject {|s| s.blank?}.join(',') + order_option = nil if order_option.blank? + + Issue.find :all, :include => ([:status, :project] + (options[:include] || [])).uniq, + :conditions => Query.merge_conditions(statement, options[:conditions]), + :order => order_option, + :limit => options[:limit], + :offset => options[:offset] + end + + # Returns the journals + # Valid options are :order, :offset, :limit + def journals(options={}) + Journal.find :all, :include => [:details, :user, {:issue => [:project, :author, :tracker, :status]}], + :conditions => statement, + :order => options[:order], + :limit => options[:limit], + :offset => options[:offset] + end + + # Returns the versions + # Valid options are :conditions + def versions(options={}) + Version.find :all, :include => :project, + :conditions => Query.merge_conditions(project_statement, options[:conditions]) + end + private # Helper method to generate the WHERE sql for a +field+, +operator+ and a +value+ |