assets.rb 972 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. module ApplicationModel::Assets
  3. =begin
  4. get all assets / related models for this user
  5. user = User.find(123)
  6. result = user.assets( assets_if_exists )
  7. returns
  8. result = {
  9. :User => {
  10. 123 => user_model_123,
  11. 1234 => user_model_1234,
  12. }
  13. }
  14. =end
  15. def assets (data = {})
  16. if !data[ self.class.to_app_model ]
  17. data[ self.class.to_app_model ] = {}
  18. end
  19. if !data[ self.class.to_app_model ][ self.id ]
  20. data[ self.class.to_app_model ][ self.id ] = self.attributes_with_associations
  21. end
  22. return data if !self['created_by_id'] && !self['updated_by_id']
  23. ['created_by_id', 'updated_by_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