OSDN Git Service

t#:
[pettanr/pettanr.git] / app / models / license.rb
index 9505026..e06e621 100644 (file)
@@ -1,7 +1,9 @@
 #
-class License < ActiveRecord::Base
+class License < Peta::Item
+  load_manifest
   belongs_to :license_group
   belongs_to :system_picture
+  has_many :resource_pictures
   
   validates :license_group_id, :presence => true, :numericality => true, :existence => {:both => false}
   validates :name, :presence => true, :length => {:maximum => 50}
@@ -15,29 +17,26 @@ class License < ActiveRecord::Base
   def overwrite
   end
   
-  def self.list
-    opt = {}
-    opt.merge!(License.list_opt)
-    opt.merge!({:order => 'name'})
-    License.find(:all, opt)
+  def caption_with_group
+    self.license_group.caption + '/' + self.caption
+  end
+  
+  def self.list_where
+    ''
+  end
+  
+  def self.list_order
+    'licenses.name'
   end
   
   def self.list_opt
-    {:include => {:license_group => {}}}
+    {:license_group => {}}
   end
   
   def self.list_json_opt
     {:include => {:license_group => {}}}
   end
   
-  def self.show rid
-    opt = {}
-    opt.merge!(License.show_opt)
-    res = License.find(rid, opt)
-#    raise ActiveRecord::Forbidden unless res.visible?(au)
-    res
-  end
-  
   def self.show_opt
     {:include => {:license_group => {}}}
   end
@@ -46,6 +45,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 +82,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