trabajo-afectivo/app/controllers/search_controller.rb

77 lines
1.6 KiB
Ruby
Raw Normal View History

# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
2013-05-21 22:30:09 +00:00
class SearchController < ApplicationController
before_filter :authentication_check
# GET /api/v1/search
2013-05-21 22:30:09 +00:00
def search
2013-05-21 22:30:09 +00:00
# build result list
tickets = Ticket.search(
:limit => params[:limit],
:query => params[:term],
:current_user => current_user,
)
assets = {}
2013-05-21 22:30:09 +00:00
ticket_result = []
tickets.each do |ticket|
assets = ticket.assets(assets)
2013-05-21 22:30:09 +00:00
ticket_result.push ticket.id
end
# do query
users = User.search(
2013-05-22 01:40:24 +00:00
:query => params[:term],
:limit => params[:limit],
2013-05-21 22:30:09 +00:00
:current_user => current_user,
)
user_result = []
users.each do |user|
user_result.push user.id
assets = user.assets(assets)
2013-05-21 22:30:09 +00:00
end
organizations = Organization.search(
2013-05-22 01:40:24 +00:00
:query => params[:term],
:limit => params[:limit],
2013-05-21 22:30:09 +00:00
:current_user => current_user,
)
2013-05-22 01:40:24 +00:00
2013-05-21 22:30:09 +00:00
organization_result = []
organizations.each do |organization|
organization_result.push organization.id
assets = organization.assets(assets)
2013-05-21 22:30:09 +00:00
end
result = []
if ticket_result[0]
data = {
:name => 'Ticket',
:ids => ticket_result,
}
result.push data
end
if user_result[0]
data = {
:name => 'User',
:ids => user_result,
}
result.push data
end
if organization_result[0]
data = {
:name => 'Organization',
:ids => organization_result,
}
result.push data
end
# return result
render :json => {
:load => assets,
2013-05-21 22:30:09 +00:00
:result => result,
}
end
end