Adds named scopes for projects index.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8082 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2011-12-04 22:31:02 +00:00
parent f52410be19
commit ff0f141126
4 changed files with 25 additions and 9 deletions
+9
View File
@@ -83,8 +83,17 @@ class Project < ActiveRecord::Base
named_scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } }
named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
named_scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
named_scope :all_public, { :conditions => { :is_public => true } }
named_scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }}
named_scope :like, lambda {|arg|
if arg.blank?
{}
else
pattern = "%#{arg.to_s.strip.downcase}%"
{:conditions => ["LOWER(identifier) LIKE :p OR LOWER(name) LIKE :p", {:p => pattern}]}
end
}
def initialize(attributes = nil)
super