summaryrefslogtreecommitdiff
path: root/app/controllers/search_controller.rb
blob: af35ddbaba597f3e90924e567ec985fa5e038c6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class SearchController < ApplicationController

	def go
		@games = Game.all
		@query = params[:query]
		@gametype = params[:game_type]

		if ( @gametype.nil? and (@query.nil? or @query.empty?)) then 
			return 
		end

		tour_filters = []
		user_filters = []
		unless @query.empty?
			tour_filters.push(["name LIKE ?", "%#{@query}%"])
			user_filters.push(["name LIKE ?", "%#{@query}%"])
		end
		unless @gametype.nil? or @gametype.empty?
			tour_filters.push(["game_id = ?", @gametype])
		end

		if tour_filters.empty?
			@tournamets = []
		else
			@tournaments = Tournament
			tour_filters.each do |filter|
				@tournaments = @tournaments.where(*filter)
			end
		end

		if user_filters.empty?
			@players = []
		else
			@players = User
			user_filters.each do |filter|
				@players = @players.where(*filter)
			end
		end
	end

end