assets.rb 966 B

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