annotate app/models/tracker.rb @ 1181:27b6f53331d5 bug_320

Close obsolete branch bug_320
author Chris Cannam
date Wed, 09 Nov 2011 14:19:49 +0000
parents 0c939c159af4
children cbb26bc654de
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 class Tracker < ActiveRecord::Base
Chris@0 19 before_destroy :check_integrity
Chris@0 20 has_many :issues
Chris@0 21 has_many :workflows, :dependent => :delete_all do
Chris@0 22 def copy(source_tracker)
Chris@0 23 Workflow.copy(source_tracker, nil, proxy_owner, nil)
Chris@0 24 end
Chris@0 25 end
Chris@0 26
Chris@0 27 has_and_belongs_to_many :projects
Chris@0 28 has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :association_foreign_key => 'custom_field_id'
Chris@0 29 acts_as_list
Chris@0 30
Chris@0 31 validates_presence_of :name
Chris@0 32 validates_uniqueness_of :name
Chris@0 33 validates_length_of :name, :maximum => 30
Chris@0 34
Chris@507 35 named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
Chris@507 36
Chris@0 37 def to_s; name end
Chris@0 38
Chris@0 39 def <=>(tracker)
Chris@0 40 name <=> tracker.name
Chris@0 41 end
Chris@0 42
Chris@0 43 def self.all
Chris@0 44 find(:all, :order => 'position')
Chris@0 45 end
Chris@0 46
Chris@0 47 # Returns an array of IssueStatus that are used
Chris@0 48 # in the tracker's workflows
Chris@0 49 def issue_statuses
Chris@0 50 if @issue_statuses
Chris@0 51 return @issue_statuses
Chris@0 52 elsif new_record?
Chris@0 53 return []
Chris@0 54 end
Chris@0 55
Chris@0 56 ids = Workflow.
Chris@0 57 connection.select_rows("SELECT DISTINCT old_status_id, new_status_id FROM #{Workflow.table_name} WHERE tracker_id = #{id}").
Chris@0 58 flatten.
Chris@0 59 uniq
Chris@0 60
Chris@0 61 @issue_statuses = IssueStatus.find_all_by_id(ids).sort
Chris@0 62 end
Chris@0 63
Chris@0 64 private
Chris@0 65 def check_integrity
Chris@0 66 raise "Can't delete tracker" if Issue.find(:first, :conditions => ["tracker_id=?", self.id])
Chris@0 67 end
Chris@0 68 end