From cdfc57d5442f72d62437f52af480049c943ecbf8 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Tue, 14 Sep 2010 19:02:25 +0000 Subject: 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 --- app/models/project.rb | 9 +++++++++ app/models/time_entry.rb | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'app/models') 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 -- cgit v1.2.3