assets.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. module Organization::Assets
  3. =begin
  4. get all assets / related models for this organization
  5. organization = Organization.find(123)
  6. result = organization.assets( assets_if_exists )
  7. returns
  8. result = {
  9. :organizations => {
  10. 123 => organization_model_123,
  11. 1234 => organization_model_1234,
  12. }
  13. }
  14. =end
  15. def assets (data)
  16. if !data[ Organization.to_app_model ]
  17. data[ Organization.to_app_model ] = {}
  18. end
  19. if !data[ User.to_app_model ]
  20. data[ User.to_app_model ] = {}
  21. end
  22. if !data[ Organization.to_app_model ][ self.id ]
  23. data[ Organization.to_app_model ][ self.id ] = self.attributes_with_associations
  24. if data[ Organization.to_app_model ][ self.id ]['member_ids']
  25. data[ Organization.to_app_model ][ self.id ]['member_ids'].each {|user_id|
  26. if !data[ User.to_app_model ][ user_id ]
  27. user = User.lookup( :id => user_id )
  28. data = user.assets( data )
  29. end
  30. }
  31. end
  32. end
  33. ['created_by_id', 'updated_by_id'].each {|item|
  34. if self[ item ]
  35. if !data[ User.to_app_model ][ self[ item ] ]
  36. user = User.lookup( :id => self[ item ] )
  37. data = user.assets( data )
  38. end
  39. end
  40. }
  41. data
  42. end
  43. end