X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fmodels%2Fresource_picture.rb;h=e087b9955c89a1087a372d6f2c3b0488d61a6f2a;hb=674d4fb2e72c2e1653b13d026af884559fd9eb4e;hp=2ec068551569bd8ba691223634b6f7449f16e453;hpb=8b87bde4b61bea53c697047889941c4232b493de;p=pettanr%2Fpettanr.git diff --git a/app/models/resource_picture.rb b/app/models/resource_picture.rb index 2ec06855..e087b995 100644 --- a/app/models/resource_picture.rb +++ b/app/models/resource_picture.rb @@ -2,9 +2,12 @@ class ResourcePicture < Peta::Content load_manifest belongs_to :artist + belongs_to :license_group belongs_to :license + belongs_to :system_picture belongs_to :picture belongs_to :original_picture + has_many :resource_picture_pictures validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']} validates :width, :presence => true, :numericality => true, :natural_number => true @@ -13,17 +16,34 @@ class ResourcePicture < Peta::Content validates :md5, :presence => true, :length => {:minimum => 32, :maximum => 32} validates :artist_id, :presence => true, :numericality => true, :existence => {:both => false} validates :license_id, :presence => true, :numericality => true, :existence => {:both => false} + validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false} validates :original_picture_id, :presence => true, :numericality => true, :existence => {:both => false} - validates :artist_name, :presence => true - validates :license_group_classname, :presence => true, :length => {:maximum => 50} + validates :license_group_module_name, :presence => true, :length => {:maximum => 50} validates :picture_id, :presence => true, :numericality => true, :existence => {:both => false} + validates :license_settings, :boost => {:boost_name => :license} + validates :license_group_settings, :boost => {:boost_name => :license_group} + validates :credit_picture_settings, :boost => {:boost_name => :credit_picture} + + def self.pickup_item_name + Picture.item_name + end + + def self.pickup_column_name + self.pickup_item_name + '_id' + end + + def pickup_id + # get head picture + self.attributes[self.pickup_column_name] + end def supply_default end def overwrite op attr = {:width => op.width, :height => op.height, :ext => op.ext, :filesize => op.filesize, - :original_picture_id => op.id, :artist_id => op.artist_id, :md5 => op.md5 + :original_picture_id => op.id, :artist_id => op.artist_id, :md5 => op.md5, + :created_at => Time.now, :updated_at => Time.now } self.attributes = attr end @@ -68,16 +88,12 @@ class ResourcePicture < Peta::Content {:src => self.url('full'), :width => self.width, :height => self.height} end - def symbol_option - self.tmb_opt_img_tag - end - - def self.list_order - 'resource_pictures.updated_at desc' + def alt_name + self.license.license_group.caption.to_s + '[' + self.license.caption.to_s + ']' end - def self.list_where - '' + def symbol_option + self.tmb_opt_img_tag end def self.list_opt @@ -118,7 +134,17 @@ class ResourcePicture < Peta::Content pc = self.new_picture imager if pc self.picture_id = pc.id + resource_picture_picture = ResourcePicturePicture.new( + :original_picture_id => self.original_picture_id, + :resource_picture_id => self.id, + :picture_id => pc.id + ) + raise ActiveRecord::Rollback unless resource_picture_picture.save if res = self.save + self.original_picture.resource_picture_pictures.each do |resource_picture_picture| + resource_picture_picture.resource_picture_id = self.id + raise ActiveRecord::Rollback unless resource_picture_picture.save + end res = self.store_picture_with_gif(imager) end else @@ -171,6 +197,10 @@ class ResourcePicture < Peta::Content self.original_picture.published_at = nil self.original_picture.stopped_at = Time.now raise ActiveRecord::Rollback unless self.original_picture.save + self.original_picture.resource_picture_pictures.each do |resource_picture_picture| + resource_picture_picture.resource_picture_id = nil + raise ActiveRecord::Rollback unless resource_picture_picture.save + end begin PictureIO.resource_picture_io.delete(self.filename) if PictureIO.resource_picture_io.exist?(self.filename) PictureIO.resource_picture_io.delete(self.filename, 'full') if PictureIO.resource_picture_io.exist?(self.filename, 'full') @@ -192,12 +222,25 @@ class ResourcePicture < Peta::Content Base64.encode64(self.restore 'full') end + def new_template + "#{self.license_group_module_name.tableize}/attributes/new" + end + def credit_template - "#{self.license_group_classname.tableize}/attributes/credit" + "#{self.license_group_module_name.tableize}/attributes/credit" end def full_credit_template - "#{self.license_group_classname.tableize}/attributes/full_credit" + "#{self.license_group_module_name.tableize}/attributes/full_credit" + end + + def self.remake_all + ResourcePicture.find(:all).each do |resource_picture| + resource_picture.boosts 'post' + full = resource_picture.restore 'full' + imager = PettanImager.load full + resource_picture.store_picture_with_gif(imager) + end end end