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
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
self.tmb_opt_img_tag
end
- def self.list_order
- 'resource_pictures.updated_at desc'
- end
-
- def self.list_where
- ''
- end
-
def self.list_opt
{:license => {}, :artist => {}, :picture => {} }
end
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
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')
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