Class: Ixtlan::Models::Phrase

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/ixtlan/models/phrase.rb

Constant Summary collapse

LOCALE =
Object.full_const_get(Models::LOCALE)
TEXT =
Object.full_const_get(Models::TEXT)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all(args = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ixtlan/models/phrase.rb', line 40

def self.all(args = {})
  phrases = ::DataMapper::Collection.new(::DataMapper::Query.new(self.repository, Ixtlan::Models::Phrase), [])
  map = {}
  locale = args[:locale] || LOCALE.default
  TEXT.not_approved(args.dup).each do |text|
    phrase = Phrase.new(:code => text.code, :text => text.text, :current_text => text.text, :locale => locale, :updated_at => text.updated_at, :updated_by => text.updated_by)
    map[phrase.code] = phrase
  end
  TEXT.latest_approved(args.dup).each do |text|
    if (phrase = map[text.code])
      phrase.current_text = text.text
    else
      phrase = Phrase.new(:code => text.code, :text => text.text, :current_text => text.text, :locale => locale, :updated_at => text.updated_at, :updated_by => text.updated_by)
      map[phrase.code] = phrase
    end
  end
  case locale.code.size
  when 2
    params = args.dup
    params[:locale] = LOCALE.default
    Translation.map_for(params).each do |code, trans|
      ph = map[code]
      if(ph.nil?)
        map[code] = Phrase.new(:code => code, :text => trans.text, :current_text => trans.text, :locale => locale, :updated_at => trans.approved_at, :updated_by => trans.approved_by, :default_translation => trans)
      else
        ph.default_translation = trans
      end
    end
  when 5
    raise "not implemented yet"
  end
  map.values.each { |ph| phrases << ph}
  phrases
end

.default_storage_nameObject



7
8
9
# File 'lib/ixtlan/models/phrase.rb', line 7

def self.default_storage_name
  "Phrase"
end

Instance Method Details

#to_xObject



34
# File 'lib/ixtlan/models/phrase.rb', line 34

alias :to_x :to_xml_document

#to_xml_document(opts = {}, doc = nil) ⇒ Object



35
36
37
38
# File 'lib/ixtlan/models/phrase.rb', line 35

def to_xml_document(opts = {}, doc = nil)
  opts.merge!({:exclude => [:id, :parent_translation_id, :default_translation_id, :locale_id], :element_name => 'phrase', :methods => [:default_translation, :parent_translation, :locale]})
  to_x(opts, doc)
end