Class | OpenWFE::Extras::Field |
In: |
lib/openwfe/extras/participants/activeparticipants.rb
|
Parent: | ActiveRecord::Base |
FIELDS_TO_SEARCH | = | %w{ svalue fkey yvalue } | The search operates on the content of these columns |
A quick method for doing
f = Field.new f.key = key f.value = value
One can then quickly add fields to an [active] workitem via :
wi.fields << Field.new_field("toto", "b")
This method does not save the new Field.
# File lib/openwfe/extras/participants/activeparticipants.rb, line 470 470: def self.new_field (key, value) 471: 472: f = Field.new 473: f.fkey = key 474: f.vclass = value.class.to_s 475: f.value = value 476: f 477: end
Will return all the fields that contain the given text.
Looks in svalue and fkey. Looks as well in yvalue if it contains a string.
This method is used by Workitem.search()
# File lib/openwfe/extras/participants/activeparticipants.rb, line 503 503: def self.search (text, storename_list=nil) 504: 505: cs = build_search_conditions(text) 506: 507: if storename_list 508: 509: cs[0] = "(#{cs[0]}) AND workitems.store_name IN (?)" 510: cs << storename_list 511: end 512: 513: find :all, :conditions => cs, :include => :workitem 514: end
Builds the condition array for a pseudo text search
# File lib/openwfe/extras/participants/activeparticipants.rb, line 526 526: def self.build_search_conditions (text) 527: 528: has_percent = (text.index("%") != nil) 529: 530: conds = [] 531: 532: conds << FIELDS_TO_SEARCH.collect { |key| 533: 534: count = has_percent ? 1 : 4 535: 536: s = ([ "#{key} LIKE ?" ] * count).join(" OR ") 537: 538: s = "(vclass = ? AND (#{s}))" if key == 'yvalue' 539: 540: s 541: }.join(" OR ") 542: 543: FIELDS_TO_SEARCH.each do |key| 544: 545: conds << 'String' if key == 'yvalue' 546: 547: conds << text 548: 549: unless has_percent 550: conds << "% #{text} %" 551: conds << "% #{text}" 552: conds << "#{text} %" 553: end 554: end 555: 556: conds 557: end