OSDN Git Service

v07
[pettanr/pettanr.git] / app / models / original_picture_license.rb
1 class OriginalPictureLicense < Peta::Item
2   load_manifest
3   belongs_to :original_picture
4   belongs_to :license_group
5   belongs_to :license
6   
7   validates :original_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
8   validates :license_group_id, :presence => true, :numericality => true, :existence => {:both => false}
9   validates :license_id, :presence => true, :numericality => true, :existence => {:both => false}
10   validates :license_group_module_name, :presence => true, :length => {:maximum => 50}
11   validates :license_settings, :boost => {:boost_name => :license}
12   
13   def supply_default oid
14     self.original_picture_id = oid
15     self.license_group_id = nil
16     self.license_id = nil
17   end
18   
19   def self.build_resource_picture opl, original_picture, params
20     my_model_class = ResourcePicture
21     
22     attr = params.merge(
23       :license_group_id => opl.license_group_id,
24       :system_picture_id => opl.license.system_picture_id,
25       :license_group_module_name => opl.license_group.module_name,
26       :license_group_settings => opl.license.license_group_settings,
27       :credit_picture_settings => opl.license.credit_picture_settings
28     )
29     attr.delete :id
30     resource_picture = my_model_class.new 
31     resource_picture.attributes = attr
32     resource_picture.overwrite original_picture
33     resource_picture.boosts 'post'
34     resource_picture
35   end
36   
37 end