Class: Wice::FilterConditionsGeneratorCustomFilter

Inherits:
FilterConditionsGenerator show all
Defined in:
lib/wice_grid.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from FilterConditionsGenerator

#initialize

Constructor Details

This class inherits a constructor from Wice::FilterConditionsGenerator

Instance Method Details

#generate_conditions(table_alias, opts) ⇒ Object

:nodoc:


677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
# File 'lib/wice_grid.rb', line 677

def generate_conditions(table_alias, opts)   #:nodoc:
  if opts.empty?
    Wice.log "empty parameters for the grid custom filter"
    return false
  end
  opts = (opts.kind_of?(Array) && opts.size == 1) ? opts[0] : opts

  if opts.kind_of?(Array)
    opts_with_special_values, normal_opts = opts.partition{|v| ::Wice::GridTools.special_value(v)}

    conditions_ar = if normal_opts.size > 0
      [" #{@column.alias_or_table_name(table_alias)}.#{@column.name} IN ( " + (['?'] * normal_opts.size).join(', ') + ' )'] + normal_opts
    else
      []
    end

    if opts_with_special_values.size > 0
      special_conditions = opts_with_special_values.collect{|v| " #{@column.alias_or_table_name(table_alias)}.#{@column.name} is " + v}.join(' or ')
      if conditions_ar.size > 0
        conditions_ar[0] = " (#{conditions_ar[0]} or #{special_conditions} ) "
      else
        conditions_ar = " ( #{special_conditions} ) "
      end
    end
    conditions_ar
  else
    if ::Wice::GridTools.special_value(opts)
      " #{@column.alias_or_table_name(table_alias)}.#{@column.name} is " + opts
    else
      [" #{@column.alias_or_table_name(table_alias)}.#{@column.name} = ?", opts]
    end
  end
end