Created
April 28, 2010 20:03
-
-
Save lorgio/382631 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def generate_search_criteria(params) | |
| #REFACTOR - Should be moved into the model and scoped | |
| conditions = [] | |
| collection = Collection.find(params[:collection]) | |
| conditions.push("buys.id IN (#{collection.buys.collect{|x| x.eql?(collection.buys.last) ? x.id : x.id.to_s + ','}.join})") | |
| conditions.push("(categories.parent_id =#{params[:category]})") unless params[:category].blank? | |
| conditions.push("(regions.id =#{params[:region]})") unless params[:region].blank? | |
| conditions.push("(sites.language_id =#{params[:language]})") unless params[:language].blank? | |
| unless params[:workflow_status].blank? | |
| case params[:workflow_status] | |
| when "unapproved" | |
| conditions.push("(translations.work_flow_status_id < 3 or translations.work_flow_status_id IS NULL)") | |
| when "approved" | |
| conditions.push("(translations.work_flow_status_id = 3)") | |
| end | |
| end | |
| StyleWrapper.find(:all,:include=>[:categories, {:translation_keys => :translations },{:buys => {:inventory_source => {:assortments => :sites}}}],:conditions => conditions.join(" AND "), :order=>"style_wrappers.style_id DESC") | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment