Class: Wice::Columns::ConditionsGeneratorColumnCustomDropdown

Inherits:
ConditionsGeneratorColumn show all
Defined in:
lib/wice/columns/column_custom_dropdown.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:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/wice/columns/column_custom_dropdown.rb', line 80

def generate_conditions(table_alias, opts)   #:nodoc:
  if opts.empty? || (opts.is_a?(Array) && opts.size == 1 && opts[0].blank?)
    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_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.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_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.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_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} is " + opts
    else
      [" #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} = ?", opts]
    end
  end
end