From b03132fb4c6fa7a2f37005440ac42497d189a6eb Mon Sep 17 00:00:00 2001 From: hukl Date: Sat, 28 Mar 2009 23:00:45 +0100 Subject: 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. --- app/models/page.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) 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 end end + def self.untranslated(options = {:locale => :de}) + PageTranslation.all.group_by(&:page_id).select do |k,v| + v.size == 1 && v.map{|x| x.locale}.include?(options[:locale]) + end + end + + def self.find_outdated_translations options = {} + defaults_options = { + :include => :globalize_translations + } + + options.merge! defaults_options + + Page.all(options).select do |page| + page.outdated_translations? + end + end + # Instance Methods def public_template_path @@ -118,6 +136,26 @@ class Page < ActiveRecord::Base published_at.nil? ? true : published_at < Time.now end + def outdated_translations? options = {:locale => :en} + translations = self.globalize_translations + locales = translations.map {|l| l.locale} + + default = *(translations.select {|x| x.locale == I18n.default_locale}) + custom = *(translations.select {|x| x.locale == options[:locale]}) + + if translations.size > 1 && default && custom + time = default.updated_at - custom.updated_at + difference = (time/24/3600).to_i.abs + if 1 < difference + return true + else + return false + end + else + return false + end + end + private def rewrite_links_in_body -- cgit v1.3