annotate .svn/pristine/05/053c71b830593b5a759e13f9676269b7c9bf4645.svn-base @ 1477:f2ad2199b49a bibplugin_integration

Close obsolete branch bibplugin_integration
author Chris Cannam
date Fri, 30 Nov 2012 14:41:31 +0000
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 class IssueCategory < ActiveRecord::Base
Chris@909 19 belongs_to :project
Chris@909 20 belongs_to :assigned_to, :class_name => 'Principal', :foreign_key => 'assigned_to_id'
Chris@909 21 has_many :issues, :foreign_key => 'category_id', :dependent => :nullify
Chris@909 22
Chris@909 23 validates_presence_of :name
Chris@909 24 validates_uniqueness_of :name, :scope => [:project_id]
Chris@909 25 validates_length_of :name, :maximum => 30
Chris@909 26
Chris@909 27 attr_protected :project_id
Chris@909 28
Chris@909 29 named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
Chris@909 30
Chris@909 31 alias :destroy_without_reassign :destroy
Chris@909 32
Chris@909 33 # Destroy the category
Chris@909 34 # If a category is specified, issues are reassigned to this category
Chris@909 35 def destroy(reassign_to = nil)
Chris@909 36 if reassign_to && reassign_to.is_a?(IssueCategory) && reassign_to.project == self.project
Chris@909 37 Issue.update_all("category_id = #{reassign_to.id}", "category_id = #{id}")
Chris@909 38 end
Chris@909 39 destroy_without_reassign
Chris@909 40 end
Chris@909 41
Chris@909 42 def <=>(category)
Chris@909 43 name <=> category.name
Chris@909 44 end
Chris@909 45
Chris@909 46 def to_s; name end
Chris@909 47 end