module JamRuby
  class Language < ActiveRecord::Base
    include HtmlSanitize
    html_sanitize strict: [:name, :description]
    has_many :teachers, :class_name => "JamRuby::Teacher", :through => :teachers_languages
    has_many :teachers_languages, class_name: "JamRuby::TeacherLanguage"

    def self.english_sort
      languages = Language.order(:description)
      languages.sort_by { |l| [ l.id == 'EN' ? 0 : 1, l.description]  }
    end
  end
end
