module FrontEndArrayParamsHelper

  #Deal with multi tags and cates that could be sat at both from setting or passed by views like tag cloud.
  #Take Tag as example: Those tags which be sat at setting will be pass as params 'tag_ext',and the rest will be pass as 'tag'
  #But when the showing process goes to fronend or default widget itself the controller will need to know what data it should use exactly.
  #That's why we need tags_and_cates

  def tags_and_cates(params)
    params["category_id"] = params["category_id"].collect{|t| t.gsub(/\"|\[|\]/,'').split(",").each(&:strip!)}.flatten if params["category_id"].is_a? Array
    params["tag_id"] = params["tag_id"].collect{|t| t.gsub(/\"|\[|\]/,'').split(",").each(&:strip!)}.flatten if params["tag_id"].is_a? Array

    params["category_id"] = [ params["base_category_id"],params["category_id"]].flatten.reject(&:nil?).reject(&:empty?)
    params.delete :base_category_id
    params["tag_id"] = [ params["base_tag_id"],params["tag_id"]].flatten.reject(&:nil?).reject(&:empty?)
    params.delete :base_tag_id

    return params
  end

end