Class: Tr8n::LanguageUser
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Tr8n::LanguageUser
- Defined in:
- app/models/tr8n/language_user.rb
Overview
– Copyright © 2010-2012 Michael Berkovich, tr8n.net
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++
– Tr8n::LanguageUser Schema Information
Table name: tr8n_language_users
id INTEGER not null, primary key
language_id integer not null
user_id integer not null
translator_id integer
manager boolean
created_at datetime
updated_at datetime
Indexes
index_tr8n_language_users_on_updated_at (updated_at)
index_tr8n_language_users_on_created_at (created_at)
index_tr8n_language_users_on_language_id_and_translator_id (language_id, translator_id)
index_tr8n_language_users_on_language_id_and_user_id (language_id, user_id)
index_tr8n_language_users_on_user_id (user_id)
++
Class Method Summary collapse
- .check_default_language_for(user) ⇒ Object
- .create_or_touch(user, language) ⇒ Object
-
.find_or_create(user, language) ⇒ Object
this object can belong to both the user and the translator users may choose to switch to a language without becoming translators once user becomes a translator, this record will be associated with both for ease of use when users get promoted, they are automatically get associated with a language and marked as translators.
- .languages_for(user) ⇒ Object
Instance Method Summary collapse
Class Method Details
.check_default_language_for(user) ⇒ Object
66 67 68 |
# File 'app/models/tr8n/language_user.rb', line 66 def self.check_default_language_for(user) find_or_create(user, Tr8n::Config.default_language) end |
.create_or_touch(user, language) ⇒ Object
76 77 78 79 80 81 |
# File 'app/models/tr8n/language_user.rb', line 76 def self.create_or_touch(user, language) return unless user.id lu = Tr8n::LanguageUser.find_or_create(user, language) lu.update_attributes(:updated_at => Time.now) lu end |
.find_or_create(user, language) ⇒ Object
this object can belong to both the user and the translator users may choose to switch to a language without becoming translators once user becomes a translator, this record will be associated with both for ease of use when users get promoted, they are automatically get associated with a language and marked as translators
61 62 63 64 |
# File 'app/models/tr8n/language_user.rb', line 61 def self.find_or_create(user, language) lu = where("user_id = ? and language_id = ?", user.id, language.id).first lu || create(:user_id => user.id, :language_id => language.id) end |
.languages_for(user) ⇒ Object
70 71 72 73 74 |
# File 'app/models/tr8n/language_user.rb', line 70 def self.languages_for(user) return [] unless user.id check_default_language_for(user) where("user_id = ?", user.id).order("updated_at desc") end |
Instance Method Details
#translator? ⇒ Boolean
83 84 85 |
# File 'app/models/tr8n/language_user.rb', line 83 def translator? translator != nil end |