state.rb 1.1 KB

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