daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def user_search(options)
  2.  
  3.     @results = {}
  4.     options[:models].each do |model|
  5.       if model.respond_to?(:find_with_ferret) && options[:user].has_permission?("view_display_#{model.to_s.downcase}_pages")
  6.         model_name = model.to_s.pluralize.downcase
  7.         (options[:order_by] and options[:order_by] != "") ?  @order_by = options[:order_by] + " " + options[:order] : @order_by = model_name + ".updated_at"
  8.         if options[:search_only_in_tags]
  9.           @results[model_name.to_sym] = records_for_user(model, options[:user], options[:domains]).find_tagged_with(options[:keywords], :page => options[:page], :per_page => options[:per_page])
  10.         else
  11.           @results[model_name.to_sym] = records_for_user(model, options[:user],
  12.             options[:domains]).find_with_ferret_paginator("#{options[:keywords]}*",
  13.             {:page => options[:page], :per_page => options[:per_page] },
  14.             {:select => "#{model_name}.id", :include => [:domains, :ratings, :tags, :rating, :country], :order => @order_by } )
  15.           @results[model_name.to_sym].concat(records_for_user(model,
  16.             options[:user], options[:domains]).find(:all,
  17.             :conditions => "#{model_name}.id = #{options[:keywords].to_i}")) if options[:keywords].to_i > 0
  18.           @results[model_name.to_sym].concat(records_for_user(model,
  19.             options[:user], options[:domains]).find(:all,
  20.             :conditions => "#{model_name}.old_id = #{options[:keywords].to_i}")) if options[:keywords].to_i > 0 && model.respond_to?(:old_id)
  21.         end
  22.       end
  23.     end
  24.  
  25.     @results.each_pair do |key, value|
  26.       model = key.to_s.singularize.capitalize.constantize
  27.       value.concat(record_for_user(model, user, options[:domains]).find_tagged_with(options[:keywords])) if model.respond_to(:find_tagged_with)
  28.     end if options[:find_tagged_with]
  29.      
  30.     @results
  31.   end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top