state.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. class Ticket::State < ApplicationModel
  3. belongs_to :state_type, :class_name => 'Ticket::StateType'
  4. validates :name, :presence => true
  5. =begin
  6. list tickets by customer
  7. states = Ticket::State.by_category('open') # open|closed
  8. returns:
  9. state objects
  10. =end
  11. def self.by_category(category)
  12. if category == 'open'
  13. return Ticket::State.where(
  14. :state_type_id => Ticket::StateType.where( :name => ['new', 'open', 'pending reminder', 'pending action'] )
  15. )
  16. elsif category == 'closed'
  17. return Ticket::State.where(
  18. :state_type_id => Ticket::StateType.where( :name => ['closed'] )
  19. )
  20. end
  21. raise "Unknown category '#{category}'"
  22. end
  23. =begin
  24. check if state is ignored for escalation
  25. state = Ticket::State.lookup( :name => 'state name' )
  26. result = state.ignore_escalation?
  27. returns:
  28. true/false
  29. =end
  30. def ignore_escalation?
  31. ignore_escalation = ['removed', 'closed', 'merged']
  32. return true if ignore_escalation.include?( self.name )
  33. return false
  34. end
  35. end