summaryrefslogtreecommitdiffstats
path: root/app/models/issue_status.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-04-04 17:26:05 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-04-04 17:26:05 +0000
commite227b92972522ad24818d2e69877dbdb84f40884 (patch)
treeb967430882d75dfee1c429e50f1ae396c4948190 /app/models/issue_status.rb
parenta9a082f05cc3bec335bb6886a5e6f79d1c5f6f95 (diff)
downloadredmine-e227b92972522ad24818d2e69877dbdb84f40884.tar.gz
redmine-e227b92972522ad24818d2e69877dbdb84f40884.zip
Various code cleaning, mainly on User, Permission and IssueStatus models.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@414 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/issue_status.rb')
-rw-r--r--app/models/issue_status.rb17
1 files changed, 12 insertions, 5 deletions
diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb
index fd6194c9a..337aa5894 100644
--- a/app/models/issue_status.rb
+++ b/app/models/issue_status.rb
@@ -36,12 +36,19 @@ class IssueStatus < ActiveRecord::Base
end
# Returns an array of all statuses the given role can switch to
+ # Uses association cache when called more than one time
def new_statuses_allowed_to(role, tracker)
- statuses = []
- for workflow in self.workflows
- statuses << workflow.new_status if workflow.role_id == role.id and workflow.tracker_id == tracker.id
- end unless role.nil? or tracker.nil?
- statuses
+ new_statuses = [self] + workflows.select {|w| w.role_id == role.id && w.tracker_id == tracker.id}.collect{|w| w.new_status}
+ new_statuses.sort{|x, y| x.position <=> y.position }
+ end
+
+ # Same thing as above but uses a database query
+ # More efficient than the previous method if called just once
+ def find_new_statuses_allowed_to(role, tracker)
+ new_statuses = [self] + workflows.find(:all,
+ :include => :new_status,
+ :conditions => ["role_id=? and tracker_id=?", role.id, tracker.id]).collect{ |w| w.new_status }
+ new_statuses.sort{|x, y| x.position <=> y.position }
end
private