last_contact.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
  2. class Observer::Ticket::LastContact < ActiveRecord::Observer
  3. observe 'ticket::_article'
  4. def after_create(record)
  5. # puts 'check last contact'
  6. # if article in internal
  7. return true if record.internal
  8. # if article is a message to customer
  9. return true if !Ticket::Article::Type.lookup( :id => record.ticket_article_type_id ).communication
  10. # if sender is not customer
  11. sender = Ticket::Article::Sender.lookup( :id => record.ticket_article_sender_id )
  12. if sender.name == 'Customer'
  13. # check if last communication is done by agent, else do not set last_contact_customer
  14. if record.ticket.last_contact_customer == nil ||
  15. record.ticket.last_contact_agent == nil ||
  16. record.ticket.last_contact_agent.to_i > record.ticket.last_contact_customer.to_i
  17. record.ticket.last_contact_customer = record.created_at
  18. # set last_contact
  19. record.ticket.last_contact = record.created_at
  20. # save ticket
  21. record.ticket.save
  22. end
  23. end
  24. # if sender is not agent
  25. if sender.name == 'Agent'
  26. # set last_contact_agent
  27. record.ticket.last_contact_agent = record.created_at
  28. # set last_contact
  29. record.ticket.last_contact = record.created_at
  30. # save ticket
  31. record.ticket.save
  32. end
  33. end
  34. end