Class: Wice::Columns::ConditionsGeneratorColumnString

Inherits:
ConditionsGeneratorColumn show all
Defined in:
lib/wice/columns/column_string.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from ConditionsGeneratorColumn

#initialize

Constructor Details

This class inherits a constructor from Wice::Columns::ConditionsGeneratorColumn

Instance Method Details

#generate_conditions(table_alias, opts) ⇒ Object

:nodoc:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/wice/columns/column_string.rb', line 63

def generate_conditions(table_alias, opts)   #:nodoc:
  if opts.is_a? String
    string_fragment = opts
    negation = ''
  elsif (opts.is_a? Hash) && opts.key?(:v)
    string_fragment = opts[:v]
    negation = opts[:n] == '1' ? 'NOT' : ''
  else
    Wice.log "invalid parameters for the grid string filter - must be a string: #{opts.inspect} or a Hash with keys :v and :n"
    return false
  end
  if string_fragment.empty?
    return false
  end

  string_matching_operator = ::Wice.get_string_matching_operators(@column_wrapper.model)

  comparator = if string_matching_operator == 'CI_LIKE'
    " #{negation}  UPPER(#{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name}) LIKE  UPPER(?)"
  else
    " #{negation}  #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} #{string_matching_operator} ?"
  end

  [ comparator, '%' + string_fragment + '%' ]

end