summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-03-28 23:00:45 +0100
committerhukl <contact@smyck.org>2009-03-28 23:00:45 +0100
commitb03132fb4c6fa7a2f37005440ac42497d189a6eb (patch)
tree2ae8886f348d90ab42965b700b4cea41db73ea1a
parentce140a7fc8eb6bea5a567e7c6681087db0055fb4 (diff)
added class and instance methods to find untranslated pages and for detecting pages with outdated translations. not publicly exposed yet as I need to test it first. Also the interface itself needs a review after a good night sleep. Its looking good to me for now.
-rw-r--r--app/models/page.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/app/models/page.rb b/app/models/page.rb
index 0bebb84..107ceb9 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -66,6 +66,24 @@ class Page < ActiveRecord::Base
66 end 66 end
67 end 67 end
68 68
69 def self.untranslated(options = {:locale => :de})
70 PageTranslation.all.group_by(&:page_id).select do |k,v|
71 v.size == 1 && v.map{|x| x.locale}.include?(options[:locale])
72 end
73 end
74
75 def self.find_outdated_translations options = {}
76 defaults_options = {
77 :include => :globalize_translations
78 }
79
80 options.merge! defaults_options
81
82 Page.all(options).select do |page|
83 page.outdated_translations?
84 end
85 end
86
69 # Instance Methods 87 # Instance Methods
70 88
71 def public_template_path 89 def public_template_path
@@ -118,6 +136,26 @@ class Page < ActiveRecord::Base
118 published_at.nil? ? true : published_at < Time.now 136 published_at.nil? ? true : published_at < Time.now
119 end 137 end
120 138
139 def outdated_translations? options = {:locale => :en}
140 translations = self.globalize_translations
141 locales = translations.map {|l| l.locale}
142
143 default = *(translations.select {|x| x.locale == I18n.default_locale})
144 custom = *(translations.select {|x| x.locale == options[:locale]})
145
146 if translations.size > 1 && default && custom
147 time = default.updated_at - custom.updated_at
148 difference = (time/24/3600).to_i.abs
149 if 1 < difference
150 return true
151 else
152 return false
153 end
154 else
155 return false
156 end
157 end
158
121 private 159 private
122 160
123 def rewrite_links_in_body 161 def rewrite_links_in_body