belongs_to :original_picture_license_group
has_one :resource_picture
has_many :pictures
+ 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 :artist_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :md5, :presence => true, :length => {:minimum => 32, :maximum => 32}
+ scope :find_index, -> (operators) do
+ where(artist_id: operators.artist.id)
+ end
+
def supply_default
self.artist_id = nil
end
self.tmb_opt_img_tag
end
+ def filer_caption
+ self.revision
+ end
+
def revision
head = self.history.first
head ? head.revision : 'unpublished'
end
def history
- Picture.find(:all, {:conditions => ['pictures.original_picture_id = ?', self.id], :order => 'pictures.revision desc'} )
+ Picture.where(original_picture_id: self.id).order(revision: :desc)
end
def self.show_opt
end
def self.export(dt = nil)
- opt = {}
- cond = if dt
- ['artists.author_id is not null and original_pictures.updated_at >= ?', dt]
- else
- 'artists.author_id is not null'
- end
- opt.merge!({:conditions => cond})
- opt.merge!({:include => {:resource_picture => {}, :artist => {}}, :order => 'original_pictures.id'})
- OriginalPicture.find(:all, opt)
+ original_pictures = OriginalPicture.includes(:resource_picture, :artist).where('artists.author_id is not null')
+ original_pictures = original_pictures.where(['original_pictures.updated_at >= ?', dt]) if dt
+ original_pictures.order('original_pictures.id').references(:artist)
end
def list_as_json_with_resource_picture
self.pictures.each do |picture|
res = picture.unpublish
raise ActiveRecord::Rollback unless res
+ if picture.resource_picture_picture
+ picture.resource_picture_picture.original_picture_id = nil
+ picture.resource_picture_picture.resource_picture_id = nil
+ raise ActiveRecord::Rollback unless picture.resource_picture_picture.save
+ end
end
res = self.destroy
raise ActiveRecord::Rollback unless res
end
def self.publish oid, lsname, attr
- l = License.find_by_name lsname
+ l = License.find_by(name: lsname)
op = OriginalPicture.find oid
lg = l.license_group
attr[:license_id] = l.id