end
def search_reviews
- conditions=['review_type<>:not_type']
- values={:not_type => Review::TYPE_FALSE_POSITIVE}
-
- unless @statuses == [""]
- conditions << "status in (:statuses)"
- values[:statuses]=@statuses
+ options = {}
+ unless @statuses == ['']
+ options['statuses']=@statuses.join(',')
end
- unless @projects == [""]
- conditions << "project_id in (:projects)"
- values[:projects]=@projects
+ unless @projects == ['']
+ options['projects']=@projects.join(',')
end
- unless @severities == [""]
- conditions << "severity in (:severities)"
- values[:severities]=@severities
+ unless @severities == ['']
+ options['severities']=@severities.join(',')
end
- unless @authors == [""]
- conditions << "user_id in (:authors)"
- values[:authors]=@authors.map{|s| s.to_i}
+ unless @authors == ['']
+ options['authors']=@authors.map{|s| s.to_i}.join(',')
end
- unless @assignees == [""]
- conditions << "assignee_id in (:assignees)"
- values[:assignees]=@assignees.map{|s| s.to_i}
+ unless @assignees == ['']
+ options['assignees']=@assignees.map{|s| s.to_i}.join(',')
end
- unless @id == ""
+ unless @id == ''
if is_number? @id
- conditions << "id = :id"
- values[:id] = @id
+ options['id'] = @id
else
- conditions << "id = :id"
- values[:id] = -1
+ options['id'] = -1
end
end
-
- @reviews = Review.find( :all, :order => "created_at DESC", :conditions => [ conditions.join(" AND "), values] ).uniq
+
+ @reviews = Review.search(options)
end
def is_number?(s)
review_type = options['review_type']
if review_type
- conditions << "review_type=:type"
+ conditions << 'review_type=:type'
values[:type] = review_type.upcase
else
conditions=['review_type<>:not_type']
end
ids=options['ids'].split(',') if options['ids']
- if options[:id]
- conditions << "id=:id"
- values[:id]=options[:id].to_i
+ if options['id']
+ conditions << 'id=:id'
+ values[:id]=options['id'].to_i
elsif ids && ids.size>0 && !ids[0].blank?
- conditions << "id in (:ids)"
+ conditions << 'id in (:ids)'
values[:ids]=ids.map{|id| id.to_i}
end
projects=options['projects'].split(',') if options['projects']
if projects && projects.size>0 && !projects[0].blank?
- conditions << "project_id in (:projects)"
+ conditions << 'project_id in (:projects)'
projectIds = []
projects.each do |project|
foundProject = Project.by_key(project)
resources=options['resources'].split(',') if options['resources']
if resources && resources.size>0 && !resources[0].blank?
- conditions << "resource_id in (:resources)"
+ conditions << 'resource_id in (:resources)'
resourceIds = []
resources.each do |resource|
foundResource = Project.by_key(resource)
statuses=options['statuses'].split(',') if options['statuses']
if statuses && statuses.size>0 && !statuses[0].blank?
- conditions << "status in (:statuses)"
+ conditions << 'status in (:statuses)'
values[:statuses]=statuses
end
-
+
severities=options['severities'].split(',') if options['severities']
if severities && severities.size>0 && !severities[0].blank?
- conditions << "severity in (:severities)"
+ conditions << 'severity in (:severities)'
values[:severities]=severities
end
authors=options['authors'].split(',') if options['authors']
if authors && authors.size>0 && !authors[0].blank?
- conditions << "user_id in (:authors)"
+ conditions << 'user_id in (:authors)'
unless is_number?(authors[0])
authors=User.logins_to_ids(authors)
end
assignees=options['assignees'].split(',') if options['assignees']
if assignees && assignees.size>0 && !assignees[0].blank?
- conditions << "assignee_id in (:assignees)"
+ conditions << 'assignee_id in (:assignees)'
unless is_number?(assignees[0])
assignees=User.logins_to_ids(assignees)
end
values[:assignees]=assignees
end
- Review.find(:all, :include => [ 'review_comments' ], :order => "created_at DESC", :conditions => [conditions.join(" AND "), values], :limit => 200)
+ Review.find(:all, :include => [ 'review_comments' ], :order => 'created_at DESC', :conditions => [conditions.join(' AND '), values], :limit => 200)
end
private