OSDN Git Service

t#31079:approve_list added provider_status
[pettanr/pettanr.git] / app / models / license.rb
index 9505026..ab72aab 100644 (file)
@@ -9,6 +9,15 @@ class License < ActiveRecord::Base
   validates :url, :presence => true, :length => {:maximum => 200}, :uniqueness => true, :url => {:message => I18n.t('errors.messages.url')} #{:allow_blank => true}
   validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
   
+  before_validation :valid_encode
+  
+  def valid_encode
+    ['name', 'caption', 'url', 'settings', 'credit_pictures'].each do |a|
+      next if attributes[a] == nil
+      raise Pettanr::BadRequest unless attributes[a].valid_encoding?
+    end
+  end
+  
   def supply_default
   end
   
@@ -46,6 +55,10 @@ class License < ActiveRecord::Base
     {:include => {:license_group => {}}}
   end
   
+  def self.list_by_name name
+    License.find :all, :conditions => ['licenses.name = ?', name], :order => 'licenses.updated_at desc'
+  end
+  
   def self.store name, attr
     r = License.replace_system_picture attr
     attr['credit_pictures'] = attr['credit_pictures'].to_json
@@ -79,4 +92,11 @@ class License < ActiveRecord::Base
     @credit_pictures_attr
   end
   
+  def self.export(dt = nil)
+    opt = {}
+    opt.merge!({:conditions => ['updated_at >= ?', dt]}) if dt
+#    opt.merge!({:order => 'name'})
+    License.find(:all, opt)
+  end
+  
 end