summaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/project.rb9
-rw-r--r--app/models/time_entry.rb16
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