|
@@ -192,79 +192,6 @@ class History < ApplicationModel
|
|
|
}
|
|
|
end
|
|
|
|
|
|
- def self.log_view ( object, current_user )
|
|
|
- history_type = self.history_type_lookup( 'viewed' )
|
|
|
- history_object = self.history_object_lookup( object.class.name )
|
|
|
- History.create(
|
|
|
- :o_id => object.id,
|
|
|
- :history_type_id => history_type.id,
|
|
|
- :history_object_id => history_object.id,
|
|
|
- :created_by_id => current_user.id
|
|
|
- )
|
|
|
- end
|
|
|
-
|
|
|
- def self.recent_viewed( user, limit = 10 )
|
|
|
-# g = Group.where( :active => true ).joins(:users).where( 'users.id' => user.id )
|
|
|
- history_type = self.history_type_lookup( 'viewed' )
|
|
|
- history_object = self.history_object_lookup( 'Ticket' )
|
|
|
-
|
|
|
- stream = History.select("distinct(o_id), created_by_id, history_type_id, history_object_id, created_at").
|
|
|
- where( :history_object_id => history_object.id ).
|
|
|
- where( :history_type_id => history_type.id ).
|
|
|
- where( :created_by_id => user.id ).
|
|
|
- order('created_at DESC, id ASC').
|
|
|
- limit(limit)
|
|
|
- datas = []
|
|
|
- stream.each do |item|
|
|
|
- data = item.attributes
|
|
|
- data['history_object'] = self.history_object_lookup_id( data['history_object_id'] ).name
|
|
|
- data['history_type'] = self.history_type_lookup_id( data['history_type_id'] ).name
|
|
|
- datas.push data
|
|
|
-# item['history_attribute'] = item.history_attribute
|
|
|
- end
|
|
|
-# puts 'pppppppppp'
|
|
|
-# puts datas.inspect
|
|
|
- return datas
|
|
|
- end
|
|
|
-
|
|
|
- def self.recent_viewed_fulldata( user, limit = 10 )
|
|
|
- recent_viewed = History.recent_viewed( user, limit )
|
|
|
-
|
|
|
- # get related users
|
|
|
- users = {}
|
|
|
- tickets = []
|
|
|
- recent_viewed.each {|item|
|
|
|
-
|
|
|
- # load article ids
|
|
|
-# if item.history_object == 'Ticket'
|
|
|
- ticket = Ticket.find( item['o_id'] ).attributes
|
|
|
- tickets.push ticket
|
|
|
-# end
|
|
|
-# if item.history_object 'Ticket::Article'
|
|
|
-# tickets.push Ticket::Article.find(item.o_id)
|
|
|
-# end
|
|
|
-# if item.history_object 'User'
|
|
|
-# tickets.push User.find(item.o_id)
|
|
|
-# end
|
|
|
-
|
|
|
- # load users
|
|
|
- if !users[ ticket['owner_id'] ]
|
|
|
- users[ ticket['owner_id'] ] = User.user_data_full( ticket['owner_id'] )
|
|
|
- end
|
|
|
- if !users[ ticket['created_by_id'] ]
|
|
|
- users[ ticket['created_by_id'] ] = User.user_data_full( ticket['created_by_id'] )
|
|
|
- end
|
|
|
- if !users[ item['created_by_id'] ]
|
|
|
- users[ item['created_by_id'] ] = User.user_data_full( item['created_by_id'] )
|
|
|
- end
|
|
|
- }
|
|
|
- return {
|
|
|
- :recent_viewed => recent_viewed,
|
|
|
- :tickets => tickets,
|
|
|
- :users => users,
|
|
|
- }
|
|
|
- end
|
|
|
-
|
|
|
private
|
|
|
|
|
|
def self.history_type_lookup_id( id )
|