assets.rb 942 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. module Ticket::Assets
  3. =begin
  4. get all assets / related models for this ticket
  5. ticket = Ticket.find(123)
  6. result = ticket.assets( assets_if_exists )
  7. returns
  8. result = {
  9. :users => {
  10. 123 => user_model_123,
  11. 1234 => user_model_1234,
  12. }
  13. :tickets => [ ticket_model1 ]
  14. }
  15. =end
  16. def assets (data)
  17. if !data[ Ticket.to_app_model ]
  18. data[ Ticket.to_app_model ] = {}
  19. end
  20. if !data[ Ticket.to_app_model ][ self.id ]
  21. data[ Ticket.to_app_model ][ self.id ] = self.attributes_with_associations
  22. end
  23. ['created_by_id', 'updated_by_id', 'owner_id', 'customer_id'].each {|item|
  24. if self[ item ]
  25. if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ]
  26. user = User.lookup( :id => self[ item ] )
  27. data = user.assets( data )
  28. end
  29. end
  30. }
  31. data
  32. end
  33. end