You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

project.rb 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # redMine - project management software
  2. # Copyright (C) 2006 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class Project < ActiveRecord::Base
  18. has_many :versions, :dependent => true, :order => "versions.effective_date DESC, versions.name DESC"
  19. has_many :members, :dependent => true
  20. has_many :users, :through => :members
  21. has_many :custom_values, :dependent => true, :as => :customized
  22. has_many :issues, :dependent => true, :order => "issues.created_on DESC", :include => :status
  23. has_many :documents, :dependent => true
  24. has_many :news, :dependent => true, :include => :author
  25. has_many :issue_categories, :dependent => true, :order => "issue_categories.name"
  26. has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => 'custom_fields_projects', :association_foreign_key => 'custom_field_id'
  27. acts_as_tree :order => "name", :counter_cache => true
  28. validates_presence_of :name, :description
  29. validates_uniqueness_of :name
  30. validates_associated :custom_values, :on => :update
  31. # returns 5 last created projects
  32. def self.latest
  33. find(:all, :limit => 5, :order => "created_on DESC")
  34. end
  35. # Returns an array of all custom fields enabled for project issues
  36. # (explictly associated custom fields and custom fields enabled for all projects)
  37. def custom_fields_for_issues(tracker)
  38. tracker.custom_fields.find(:all, :include => :projects,
  39. :conditions => ["is_for_all=? or project_id=?", true, self.id])
  40. #(CustomField.for_all + custom_fields).uniq
  41. end
  42. def all_custom_fields
  43. @all_custom_fields ||= IssueCustomField.find(:all, :include => :projects,
  44. :conditions => ["is_for_all=? or project_id=?", true, self.id])
  45. end
  46. protected
  47. def validate
  48. errors.add(parent_id, " must be a root project") if parent and parent.parent
  49. errors.add_to_base("A project with subprojects can't be a subproject") if parent and projects_count > 0
  50. end
  51. end