diff options
author | Eric Davis <edavis@littlestreamsoftware.com> | 2010-09-14 19:02:25 +0000 |
---|---|---|
committer | Eric Davis <edavis@littlestreamsoftware.com> | 2010-09-14 19:02:25 +0000 |
commit | cdfc57d5442f72d62437f52af480049c943ecbf8 (patch) | |
tree | 576cbf92e5bdeec589544476cc83de216adda120 /app/models | |
parent | 8900797adaf29adc447925b800d5457ca941795f (diff) | |
download | redmine-cdfc57d5442f72d62437f52af480049c943ecbf8.tar.gz redmine-cdfc57d5442f72d62437f52af480049c943ecbf8.zip |
Change the TimelogController's to/from dates based on the project time entries
Instead of looking for the earliest and latest time entry system wide for the
dates in the form, now TimelogController will only look at the time entries
for the current project (and parent/sub projects).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4087 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/project.rb | 9 | ||||
-rw-r--r-- | app/models/time_entry.rb | 16 |
2 files changed, 21 insertions, 4 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 40898a34e..4b0236b37 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -493,6 +493,15 @@ class Project < ActiveRecord::Base enabled_modules.clear end end + + # Returns an array of projects that are in this project's hierarchy + # + # Example: parents, children, siblings + def hierarchy + parents = project.self_and_ancestors || [] + descendants = project.descendants || [] + project_hierarchy = parents | descendants # Set union + end # Returns an auto-generated project identifier based on the last identifier used def self.next_identifier diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index 56801a4ca..9bf970891 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -82,11 +82,19 @@ class TimeEntry < ActiveRecord::Base end end - def self.earilest_date_for_project - TimeEntry.minimum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) + def self.earilest_date_for_project(project=nil) + finder_conditions = ARCondition.new(Project.allowed_to_condition(User.current, :view_time_entries)) + if project + finder_conditions << ["project_id IN (?)", project.hierarchy.collect(&:id)] + end + TimeEntry.minimum(:spent_on, :include => :project, :conditions => finder_conditions.conditions) end - def self.latest_date_for_project - TimeEntry.maximum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) + def self.latest_date_for_project(project=nil) + finder_conditions = ARCondition.new(Project.allowed_to_condition(User.current, :view_time_entries)) + if project + finder_conditions << ["project_id IN (?)", project.hierarchy.collect(&:id)] + end + TimeEntry.maximum(:spent_on, :include => :project, :conditions => finder_conditions.conditions) end end |