@@ -309,51 +309,8 class Query < ActiveRecord::Base | |||||
309 | v.push(User.current.logged? ? User.current.id.to_s : "0") if v.delete("me") |
|
309 | v.push(User.current.logged? ? User.current.id.to_s : "0") if v.delete("me") | |
310 | end |
|
310 | end | |
311 |
|
311 | |||
312 | case operator_for field |
|
312 | sql = sql + sql_for_field(field, v, db_table, db_field, is_custom_filter) | |
313 |
|
|
313 | ||
314 | sql = sql + "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")" |
|
|||
315 | when "!" |
|
|||
316 | sql = sql + "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))" |
|
|||
317 | when "!*" |
|
|||
318 | sql = sql + "#{db_table}.#{db_field} IS NULL" |
|
|||
319 | sql << " OR #{db_table}.#{db_field} = ''" if is_custom_filter |
|
|||
320 | when "*" |
|
|||
321 | sql = sql + "#{db_table}.#{db_field} IS NOT NULL" |
|
|||
322 | sql << " AND #{db_table}.#{db_field} <> ''" if is_custom_filter |
|
|||
323 | when ">=" |
|
|||
324 | sql = sql + "#{db_table}.#{db_field} >= #{v.first.to_i}" |
|
|||
325 | when "<=" |
|
|||
326 | sql = sql + "#{db_table}.#{db_field} <= #{v.first.to_i}" |
|
|||
327 | when "o" |
|
|||
328 | sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id" |
|
|||
329 | when "c" |
|
|||
330 | sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id" |
|
|||
331 | when ">t-" |
|
|||
332 | sql = sql + date_range_clause(db_table, db_field, - v.first.to_i, 0) |
|
|||
333 | when "<t-" |
|
|||
334 | sql = sql + date_range_clause(db_table, db_field, nil, - v.first.to_i) |
|
|||
335 | when "t-" |
|
|||
336 | sql = sql + date_range_clause(db_table, db_field, - v.first.to_i, - v.first.to_i) |
|
|||
337 | when ">t+" |
|
|||
338 | sql = sql + date_range_clause(db_table, db_field, v.first.to_i, nil) |
|
|||
339 | when "<t+" |
|
|||
340 | sql = sql + date_range_clause(db_table, db_field, 0, v.first.to_i) |
|
|||
341 | when "t+" |
|
|||
342 | sql = sql + date_range_clause(db_table, db_field, v.first.to_i, v.first.to_i) |
|
|||
343 | when "t" |
|
|||
344 | sql = sql + date_range_clause(db_table, db_field, 0, 0) |
|
|||
345 | when "w" |
|
|||
346 | from = l(:general_first_day_of_week) == '7' ? |
|
|||
347 | # week starts on sunday |
|
|||
348 | ((Date.today.cwday == 7) ? Time.now.at_beginning_of_day : Time.now.at_beginning_of_week - 1.day) : |
|
|||
349 | # week starts on monday (Rails default) |
|
|||
350 | Time.now.at_beginning_of_week |
|
|||
351 | sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(from + 7.days)] |
|
|||
352 | when "~" |
|
|||
353 | sql = sql + "#{db_table}.#{db_field} LIKE '%#{connection.quote_string(v.first)}%'" |
|
|||
354 | when "!~" |
|
|||
355 | sql = sql + "#{db_table}.#{db_field} NOT LIKE '%#{connection.quote_string(v.first)}%'" |
|
|||
356 | end |
|
|||
357 | sql << ')' |
|
314 | sql << ')' | |
358 | filters_clauses << sql |
|
315 | filters_clauses << sql | |
359 | end if filters and valid? |
|
316 | end if filters and valid? | |
@@ -363,6 +320,58 class Query < ActiveRecord::Base | |||||
363 |
|
320 | |||
364 | private |
|
321 | private | |
365 |
|
322 | |||
|
323 | # Helper method to generate the WHERE sql for a +field+ with a value (+v+) | |||
|
324 | def sql_for_field(field, v, db_table, db_field, is_custom_filter) | |||
|
325 | sql = '' | |||
|
326 | case operator_for field | |||
|
327 | when "=" | |||
|
328 | return "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")" | |||
|
329 | when "!" | |||
|
330 | return "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))" | |||
|
331 | when "!*" | |||
|
332 | sql = "#{db_table}.#{db_field} IS NULL" | |||
|
333 | sql << " OR #{db_table}.#{db_field} = ''" if is_custom_filter | |||
|
334 | return sql | |||
|
335 | when "*" | |||
|
336 | sql = "#{db_table}.#{db_field} IS NOT NULL" | |||
|
337 | sql << " AND #{db_table}.#{db_field} <> ''" if is_custom_filter | |||
|
338 | return sql | |||
|
339 | when ">=" | |||
|
340 | return "#{db_table}.#{db_field} >= #{v.first.to_i}" | |||
|
341 | when "<=" | |||
|
342 | return "#{db_table}.#{db_field} <= #{v.first.to_i}" | |||
|
343 | when "o" | |||
|
344 | return "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id" | |||
|
345 | when "c" | |||
|
346 | return "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id" | |||
|
347 | when ">t-" | |||
|
348 | return date_range_clause(db_table, db_field, - v.first.to_i, 0) | |||
|
349 | when "<t-" | |||
|
350 | return date_range_clause(db_table, db_field, nil, - v.first.to_i) | |||
|
351 | when "t-" | |||
|
352 | return date_range_clause(db_table, db_field, - v.first.to_i, - v.first.to_i) | |||
|
353 | when ">t+" | |||
|
354 | return date_range_clause(db_table, db_field, v.first.to_i, nil) | |||
|
355 | when "<t+" | |||
|
356 | return date_range_clause(db_table, db_field, 0, v.first.to_i) | |||
|
357 | when "t+" | |||
|
358 | return date_range_clause(db_table, db_field, v.first.to_i, v.first.to_i) | |||
|
359 | when "t" | |||
|
360 | return date_range_clause(db_table, db_field, 0, 0) | |||
|
361 | when "w" | |||
|
362 | from = l(:general_first_day_of_week) == '7' ? | |||
|
363 | # week starts on sunday | |||
|
364 | ((Date.today.cwday == 7) ? Time.now.at_beginning_of_day : Time.now.at_beginning_of_week - 1.day) : | |||
|
365 | # week starts on monday (Rails default) | |||
|
366 | Time.now.at_beginning_of_week | |||
|
367 | return "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(from + 7.days)] | |||
|
368 | when "~" | |||
|
369 | return "#{db_table}.#{db_field} LIKE '%#{connection.quote_string(v.first)}%'" | |||
|
370 | when "!~" | |||
|
371 | return "#{db_table}.#{db_field} NOT LIKE '%#{connection.quote_string(v.first)}%'" | |||
|
372 | end | |||
|
373 | end | |||
|
374 | ||||
366 | def add_custom_fields_filters(custom_fields) |
|
375 | def add_custom_fields_filters(custom_fields) | |
367 | @available_filters ||= {} |
|
376 | @available_filters ||= {} | |
368 |
|
377 |
General Comments 0
You need to be logged in to leave comments.
Login now