\r
@reviews = []\r
unless params.blank?\r
- @reviews = Review.find :all, :conditions => ['status=?', @statuses]\r
+ findReviewsForUserQuery\r
end\r
end\r
\r
private\r
\r
def init_params\r
- users = User.find :all\r
@user_names = [["Any", ""]]\r
- users.each do |user|\r
+ default_user = [""]\r
+ if current_user \r
+ @user_names << ["Me", current_user.id]\r
+ default_user = [current_user.id]\r
+ end\r
+ User.find( :all ).each do |user|\r
@user_names << [user.name, user.id.to_s]\r
end\r
- @review_authors = filter_any(params[:review_authors]) || [""]\r
- @comment_authors = filter_any(params[:comment_authors]) || [""]\r
+ @review_authors = filter_any(params[:review_authors]) || default_user\r
+ @comment_authors = filter_any(params[:comment_authors]) || default_user\r
@severities = filter_any(params[:severities]) || [""]\r
@statuses = filter_any(params[:statuses]) || ["open"]\r
end\r
\r
def filter_any(array)\r
- if array && array.size>1 && array.include?('')\r
- array=[''] #keep only 'any'\r
+ if array && array.size>1 && array.include?("")\r
+ array=[""]\r
end\r
array\r
end\r
\r
+ def findReviewsForUserQuery\r
+ @conditions=""\r
+ @values=[]\r
+ @need_and = false;\r
+ @need_or = false;\r
+ add_sql_query_param "status", @statuses\r
+ add_sql_query_param "severity", @severities\r
+ add_sql_query_param "user_id", @review_authors\r
+ \r
+ @reviews = Review.find :all, :conditions => [@conditions] + @values\r
+ end\r
+ \r
+ def add_sql_query_param ( field, search_params )\r
+ unless search_params == [""]\r
+ @conditions += " AND" if @need_and\r
+ @conditions += "("\r
+ search_params.each do |search_param|\r
+ @conditions += " OR" if @need_or\r
+ @conditions += " " + field + "=?"\r
+ @values << search_param\r
+ @need_or = true\r
+ end\r
+ @conditions += ")"\r
+ @need_or = false;\r
+ @need_and = true;\r
+ end\r
+ end\r
+ \r
def findReviewsForRuleFailure ( rule_failure_id )\r
return Review.find :all, :conditions => ['rule_failure_id=?', rule_failure_id]\r
end\r