app/controllers/employees_controller.rb
# Filters the employees displayed on the index page based on paramaters provided
Filters the employees displayed on the index page based on paramaters provided
Filters the employees displayed on the index page based on paramaters provided
def filter_employees(search)
      return Employee.where(true) if search.blank?
      @group = search[:group]
      @service = search[:service]
      @name = search[:name]
      @active = search[:active]
      search_array = []
      if @name.blank?
        search_string = "true"
      else
        array_of_strings_to_search_for = @name.split(" ")
        search_array << ("last_name LIKE '%#{array_of_strings_to_search_for[0]}%'")
        search_array << ("first_name LIKE '%#{array_of_strings_to_search_for[0]}%'")
        if array_of_strings_to_search_for.length > 1
          search_array << ("last_name LIKE '%#{array_of_strings_to_search_for[1]}%'")
          search_array << ("first_name LIKE '%#{array_of_strings_to_search_for[1]}%'")
        end
        search_string = search_array.join(" OR ")
      end
      @employees = Employee.where(search_string)
      @employees = @employees.where("employees.active = " + @active) unless @active.blank?
      @employees = @employees.joins(:groups).where("groups.id" => @group).uniq unless @group.blank?
      @employees = @employees.joins(:services).where("services.id" => @service).uniq unless @service.blank?
      return @employees
    end
def filter_employees ( search ) return Employee . where ( true ) if search . blank? @group = search [ :group ] @service = search [ :service ] @name = search [ :name ] @active = search [ :active ] search_array = [ ] if @name . blank? search_string = "true" else array_of_strings_to_search_for = @name . split ( " " ) search_array << ( "last_name LIKE '%#{array_of_strings_to_search_for[0]}%'" ) search_array << ( "first_name LIKE '%#{array_of_strings_to_search_for[0]}%'" ) if array_of_strings_to_search_for . length > 1 search_array << ( "last_name LIKE '%#{array_of_strings_to_search_for[1]}%'" ) search_array << ( "first_name LIKE '%#{array_of_strings_to_search_for[1]}%'" ) end search_string = search_array . join ( " OR " ) end @employees = Employee . where ( search_string ) @employees = @employees . where ( "employees.active = " + @active ) unless @active . blank? @employees = @employees . joins ( :groups ) . where ( "groups.id" => @group ) . uniq unless @group . blank? @employees = @employees . joins ( :services ) . where ( "services.id" => @service ) . uniq unless @service . blank? return @employees end
Filters the employees displayed on the index page based on paramaters provided
Filters the employees displayed on the index page based on paramaters provided
# Seperates '@name' into the first and last names, in array form. It does not assume that # the first name is entered first; therefore, each string is treated as potentially being  # either the first or last name. # Searches for the first name (the first index) # Searches for the last name if present (the second index)
search