2014-02-03 19:23:00 +00:00
|
|
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
2013-08-17 21:10:11 +00:00
|
|
|
|
|
|
|
module Ticket::ScreenOptions
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
list of active agents
|
|
|
|
|
|
|
|
result = Ticket::ScreenOptions.agents()
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = [user1, user2]
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.agents
|
2015-04-27 13:42:53 +00:00
|
|
|
User.where( active: true ).joins(:roles).where( 'roles.name' => 'Agent', 'roles.active' => true ).uniq()
|
2013-08-17 21:10:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
list attributes
|
|
|
|
|
|
|
|
result = Ticket::ScreenOptions.attributes_to_change(
|
|
|
|
:ticket_id => 123,
|
|
|
|
:article_id => 123,
|
|
|
|
|
|
|
|
:ticket => ticket_model,
|
|
|
|
)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = {
|
2015-01-24 12:51:04 +00:00
|
|
|
:type_id => type_ids,
|
|
|
|
:state_id => state_ids,
|
|
|
|
:priority_id => priority_ids,
|
|
|
|
:owner_id => owner_ids,
|
|
|
|
:group_id => group_ids,
|
|
|
|
:group_id__owner_id => groups_users,
|
2013-08-17 21:10:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.attributes_to_change(params)
|
|
|
|
if params[:ticket_id]
|
2014-09-15 09:06:13 +00:00
|
|
|
params[:ticket] = Ticket.find( params[:ticket_id] )
|
2013-08-17 21:10:11 +00:00
|
|
|
end
|
|
|
|
if params[:article_id]
|
2014-09-15 09:06:13 +00:00
|
|
|
params[:article] = Ticket::Article.find( params[:article_id] )
|
2013-08-17 21:10:11 +00:00
|
|
|
end
|
|
|
|
|
2014-09-09 23:42:20 +00:00
|
|
|
filter = {}
|
|
|
|
assets = {}
|
|
|
|
|
2013-08-17 21:10:11 +00:00
|
|
|
# get ticket states
|
2014-06-08 22:01:20 +00:00
|
|
|
state_ids = []
|
2013-08-17 21:10:11 +00:00
|
|
|
if params[:ticket]
|
2014-06-08 22:01:20 +00:00
|
|
|
state_type = params[:ticket].state.state_type
|
2013-08-17 21:10:11 +00:00
|
|
|
end
|
2014-06-08 22:01:20 +00:00
|
|
|
state_types = ['open', 'closed', 'pending action', 'pending reminder']
|
|
|
|
if state_type && !state_types.include?(state_type.name)
|
|
|
|
state_ids.push params[:ticket].state.id
|
2013-08-17 21:10:11 +00:00
|
|
|
end
|
2014-06-08 22:01:20 +00:00
|
|
|
state_types.each {|type|
|
2015-04-27 13:42:53 +00:00
|
|
|
state_type = Ticket::StateType.where( name: type ).first
|
2014-06-08 22:01:20 +00:00
|
|
|
if state_type
|
|
|
|
state_type.states.each {|state|
|
2014-09-09 23:42:20 +00:00
|
|
|
assets = state.assets(assets)
|
2014-06-08 22:01:20 +00:00
|
|
|
state_ids.push state.id
|
2013-08-17 21:10:11 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
}
|
2014-09-09 23:42:20 +00:00
|
|
|
filter[:state_id] = state_ids
|
2013-08-17 21:10:11 +00:00
|
|
|
|
|
|
|
# get priorities
|
2014-06-08 22:01:20 +00:00
|
|
|
priority_ids = []
|
2015-04-27 13:42:53 +00:00
|
|
|
Ticket::Priority.where( active: true ).each { |priority|
|
2014-09-09 23:42:20 +00:00
|
|
|
assets = priority.assets(assets)
|
2014-06-08 22:01:20 +00:00
|
|
|
priority_ids.push priority.id
|
2013-08-17 21:10:11 +00:00
|
|
|
}
|
2014-09-09 23:42:20 +00:00
|
|
|
filter[:priority_id] = priority_ids
|
|
|
|
|
2014-06-08 22:01:20 +00:00
|
|
|
type_ids = []
|
2013-08-17 21:10:11 +00:00
|
|
|
if params[:ticket]
|
2014-06-08 22:01:20 +00:00
|
|
|
types = ['note', 'phone']
|
2013-08-17 21:10:11 +00:00
|
|
|
if params[:ticket].group.email_address_id
|
2014-06-08 22:01:20 +00:00
|
|
|
types.push 'email'
|
2013-08-17 21:10:11 +00:00
|
|
|
end
|
2014-06-08 22:01:20 +00:00
|
|
|
types.each {|type_name|
|
2015-04-27 13:42:53 +00:00
|
|
|
type = Ticket::Article::Type.lookup( name: type_name )
|
2014-06-08 22:01:20 +00:00
|
|
|
if type
|
|
|
|
type_ids.push type.id
|
2013-08-17 21:10:11 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
2014-09-09 23:42:20 +00:00
|
|
|
filter[:type_id] = type_ids
|
|
|
|
|
|
|
|
# get group / user relations
|
|
|
|
agents = {}
|
|
|
|
Ticket::ScreenOptions.agents.each { |user|
|
|
|
|
agents[ user.id ] = 1
|
|
|
|
}
|
|
|
|
|
2015-04-27 13:42:53 +00:00
|
|
|
dependencies = { group_id: { '' => { owner_id: [] } } }
|
|
|
|
Group.where( active: true ).each { |group|
|
2014-09-09 23:42:20 +00:00
|
|
|
assets = group.assets(assets)
|
2015-04-27 13:42:53 +00:00
|
|
|
dependencies[:group_id][group.id] = { owner_id: [] }
|
2014-09-09 23:42:20 +00:00
|
|
|
group.users.each {|user|
|
|
|
|
next if !agents[ user.id ]
|
|
|
|
assets = user.assets(assets)
|
|
|
|
dependencies[:group_id][ group.id ][ :owner_id ].push user.id
|
|
|
|
}
|
|
|
|
}
|
2013-08-17 21:10:11 +00:00
|
|
|
|
2015-04-27 20:12:50 +00:00
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
assets: assets,
|
|
|
|
filter: filter,
|
|
|
|
dependencies: dependencies,
|
2013-08-17 21:10:11 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
list tickets by customer groupd in state categroie open and closed
|
|
|
|
|
|
|
|
result = Ticket::ScreenOptions.list_by_customer(
|
2015-01-24 12:51:04 +00:00
|
|
|
:customer_id => 123,
|
|
|
|
:limit => 15, # optional, default 15
|
2013-08-17 21:10:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = {
|
2015-02-07 22:43:27 +00:00
|
|
|
:ticket_ids_open => tickets_open,
|
|
|
|
:ticket_ids_closed => tickets_closed,
|
|
|
|
:assets => { ...list of assets... },
|
2013-08-17 21:10:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.list_by_customer(data)
|
|
|
|
|
|
|
|
# get closed/open states
|
2014-06-08 22:01:20 +00:00
|
|
|
state_list_open = Ticket::State.by_category( 'open' )
|
|
|
|
state_list_closed = Ticket::State.by_category( 'closed' )
|
2013-08-17 21:10:11 +00:00
|
|
|
|
|
|
|
# get tickets
|
|
|
|
tickets_open = Ticket.where(
|
2015-04-27 13:42:53 +00:00
|
|
|
customer_id: data[:customer_id],
|
|
|
|
state_id: state_list_open
|
2013-08-17 21:10:11 +00:00
|
|
|
).limit( data[:limit] || 15 ).order('created_at DESC')
|
2015-02-07 22:43:27 +00:00
|
|
|
assets = {}
|
|
|
|
ticket_ids_open = []
|
|
|
|
tickets_open.each {|ticket|
|
|
|
|
ticket_ids_open.push ticket.id
|
|
|
|
assets = ticket.assets(assets)
|
|
|
|
}
|
2013-08-17 21:10:11 +00:00
|
|
|
|
|
|
|
tickets_closed = Ticket.where(
|
2015-04-27 13:42:53 +00:00
|
|
|
customer_id: data[:customer_id],
|
|
|
|
state_id: state_list_closed
|
2013-08-17 21:10:11 +00:00
|
|
|
).limit( data[:limit] || 15 ).order('created_at DESC')
|
2015-02-07 22:43:27 +00:00
|
|
|
ticket_ids_closed = []
|
|
|
|
tickets_closed.each {|ticket|
|
|
|
|
ticket_ids_closed.push ticket.id
|
|
|
|
assets = ticket.assets(assets)
|
|
|
|
}
|
2013-08-17 21:10:11 +00:00
|
|
|
|
2015-04-27 20:12:50 +00:00
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
ticket_ids_open: ticket_ids_open,
|
|
|
|
ticket_ids_closed: ticket_ids_closed,
|
|
|
|
assets: assets,
|
2013-08-17 21:10:11 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|