X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fmodels%2Fresource_picture.rb;h=42c8eb65b6c460006f4e6bdc621c1394c186a34c;hb=c5fdcefa82de4c0b3bf5a69b6ec120827542a875;hp=2ec068551569bd8ba691223634b6f7449f16e453;hpb=484dc90099faa5c61c4467583423349cd7df29fb;p=pettanr%2Fpettanr.git diff --git a/app/models/resource_picture.rb b/app/models/resource_picture.rb index 2ec06855..42c8eb65 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,62 @@ 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} + + scope :find_index, -> do + self.all + end + + scope :find_private, -> (operators) do + where(artist_id: operators.artist.id) + end + + scope :find_by_original_picture, -> (original_picture_id) do + find_index.where(original_picture_id: original_picture_id) + end + + scope :find_by_license_group, -> (license_group_id) do + find_index.where(license_group_id: license_group_id) + end + + scope :find_by_license, -> (license_id) do + find_index.where(license_id: license_id) + end + + scope :find_by_artist, -> (artist_id) do + find_index.where(artist_id: artist_id) + end + + scope :find_by_md5, -> (md5) do + find_index.where(md5: md5) + end + + 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 +116,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 +162,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 +225,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 +250,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_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