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
112
113
114
115
116
117
118
119
120
121
# 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.is_a?(Array) && opts.size == 1) ? opts[0] : opts

  column_name =
      "#{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name}"
  if opts.is_a?(Array)
    opts_with_special_values, normal_opts = opts.partition { |v| ::Wice::GridTools.special_value(v) }

    conditions_ar = if normal_opts.size > 0
      if @column_wrapper.array?
        [(["? = ANY(#{column_name})"] * normal_opts.size).join(' OR ')] + normal_opts
      else
        [" #{column_name} IN ( " + (['?'] * normal_opts.size).join(', ') + ' )'] + normal_opts
      end
    else
      []
    end

    if opts_with_special_values.size > 0
      special_conditions = opts_with_special_values.collect { |v| " #{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_name} is " + opts
    else
      if @column_wrapper.array?
        [" ? = ANY(#{column_name})", opts]
      else
        [" #{column_name} = ?", opts]
      end
    end
  end
end