Class: Wice::FilterConditionsGeneratorInteger

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:



773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
# File 'lib/wice_grid.rb', line 773

def  generate_conditions(table_alias, opts)   #:nodoc:
  unless opts.kind_of? Hash
    Wice.log "invalid parameters for the grid integer filter - must be a hash"
    return false
  end
  conditions = [[]]
  if opts[:fr]
    if opts[:fr] =~ /\d/
      conditions[0] << " #{@column.alias_or_table_name(table_alias)}.#{@column.name} >= ? "
      conditions << opts[:fr]
    else
      opts.delete(:fr)
    end
  end

  if opts[:to]
    if opts[:to] =~ /\d/
      conditions[0] << " #{@column.alias_or_table_name(table_alias)}.#{@column.name} <= ? "
      conditions << opts[:to]
    else
      opts.delete(:to)
    end
  end

  if conditions.size == 1
    Wice.log "invalid parameters for the grid integer filter - either range limits are not supplied or they are not numeric"
    return false
  end

  conditions[0] = conditions[0].join(' and ')

  return conditions
end