X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fmodels%2Fresource_picture.rb;h=773c4c3258005881991b877789110a2faafa63ad;hb=467daaf74bbf62a7ad43d7af7fd6326bfacd9010;hp=bd97c7dc4b91481e42d4a7fbb75ef018a8c2c065;hpb=ac6610b290db53f3914b593963fef972eb4cfa82;p=pettanr%2Fpettanr.git diff --git a/app/models/resource_picture.rb b/app/models/resource_picture.rb index bd97c7dc..773c4c32 100644 --- a/app/models/resource_picture.rb +++ b/app/models/resource_picture.rb @@ -3,6 +3,7 @@ class ResourcePicture < Peta::Content load_manifest belongs_to :artist belongs_to :license + belongs_to :system_picture belongs_to :picture belongs_to :original_picture @@ -13,24 +14,29 @@ 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 :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 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 def visible? operators - return false unless super - true + # no super + # content model call to owner checker + self.user_visible? operators end def filename @@ -46,15 +52,15 @@ class ResourcePicture < Peta::Content end def url subdir = nil - '/resource_pictures/' + (subdir.to_s.empty? ? '' : subdir.to_s + '/' ) + filename + '/resource_pictures/' + filename + (subdir.to_s.empty? ? '' : '?subdir=' + subdir.to_s) end def to_gif? - self.ext == 'png' and self.flag_gif_convert >= 0 + self.ext == 'png' and self.license_extend.gif_convert >= 0 end def thumbnail(imager) - tw, th = ResourcePicture.fix_size_both(MagicNumber['thumbnail_width'], MagicNumber['thumbnail_height'], rimg.columns, rimg.rows) + tw, th = ResourcePicture.fix_size_both(Manifest.manifest.magic_numbers['thumbnail_width'], Manifest.manifest.magic_numbers['thumbnail_height'], rimg.columns, rimg.rows) ResourcePicture.resize(rimg.to_blob, tw, th).to_blob end @@ -67,6 +73,10 @@ class ResourcePicture < Peta::Content {:src => self.url('full'), :width => self.width, :height => self.height} end + def alt_name + self.license.license_group.caption.to_s + '[' + self.license.caption.to_s + ']' + end + def symbol_option self.tmb_opt_img_tag end @@ -99,6 +109,7 @@ class ResourcePicture < Peta::Content pc = Picture.new pc.supply_default pc.overwrite self + pc.boosts 'post' r = pc.store imager return pc if r self.errors.add :base, Picture.model_name.human + I18n.t('errors.not_create') @@ -147,7 +158,7 @@ class ResourcePicture < Peta::Content def store_picture(imager, fn) res = false - thumbnail_imager = self.flag_thumbnail >= 0 ? imager.to_thumbnail : imager + thumbnail_imager = self.license_extend.thumbnail >= 0 ? imager.to_thumbnail : imager return false unless thumbnail_imager begin PictureIO.resource_picture_io.put(thumbnail_imager.binary, fn) @@ -191,86 +202,11 @@ class ResourcePicture < Peta::Content end def credit_template - "#{self.classname.tableize}/attributes/credit" + "#{self.license_group_module_name.tableize}/attributes/credit" end def full_credit_template - "#{self.classname.tableize}/attributes/full_credit" - end - - def credit_data - begin - @credit_data = JSON.parse(self.credit) unless @credit_data - rescue - end - @credit_data - end - - def flags - begin - @flags = JSON.parse(self.settings) unless @flags - rescue - end - @flags - end - - def flags=(s) - @flags = s - end - - def flag_open - @flag_open = flags["open"] unless @flag_open - @flag_open - end - - def flag_commercial - @flag_commercial = flags["commercial"] unless @flag_commercial - @flag_commercial - end - - def flag_official - @flag_official = flags["official"] unless @flag_official - @flag_official - end - - def flag_attribution - @flag_attribution = flags["attribution"] unless @flag_attribution - @flag_attribution - end - - def flag_derive - @flag_derive = flags["derive"] unless @flag_derive - @flag_derive - end - - def flag_thumbnail - @flag_thumbnail = flags["thumbnail"] unless @flag_thumbnail - @flag_thumbnail - end - - def flag_gif_convert - @flag_gif_convert = flags["gif_convert"] unless @flag_gif_convert - @flag_gif_convert - end - - def flag_reverse - @flag_reverse = flags["reverse"] unless @flag_reverse - @flag_reverse - end - - def flag_resize - @flag_resize = flags["resize"] unless @flag_resize - @flag_resize - end - - def flag_sync_vh - @flag_sync_vh = flags["sync_vh"] unless @flag_sync_vh - @flag_sync_vh - end - - def flag_overlap - @flag_overlap = flags["overlap"] unless @flag_overlap - @flag_overlap + "#{self.license_group_module_name.tableize}/attributes/full_credit" end end