OSDN Git Service

t#29316:up;add full credit
[pettanr/pettanr.git] / app / models / picture.rb
index 9701cf8..3ca0c1f 100644 (file)
@@ -21,11 +21,12 @@ class Picture < ActiveRecord::Base
   end
   
   def overwrite rp
-    attr = {:revision => self.new_revision,:width => rp.width, :height => rp.height, :ext => rp.ext, :filesize => rp.filesize, 
+    attr = {:width => rp.width, :height => rp.height, :ext => rp.ext, :filesize => rp.filesize, 
       :original_picture_id => rp.original_picture_id, :license_id => rp.license_id, :artist_id => rp.artist_id, 
       :md5 => rp.md5, :artist_name => rp.artist_name, :classname => rp.classname, :credit => rp.credit, :settings => rp.settings
     }
     self.attributes = attr
+    self.revision = self.new_revision   #Do not move to attr. new_revision reffernces self.original_picture_id
   end
   
   def own? author
@@ -52,6 +53,11 @@ class Picture < ActiveRecord::Base
     '/pictures/' + filename
   end
   
+  def opt_img_tag
+    tw, th = PettanImager.thumbnail_size(self.width, self.height)
+    {:src => self.url, :width => tw, :height => th}
+  end
+  
   def new_revision
     Picture.maximum(:revision, :conditions => ['original_picture_id = ?', self.original_picture_id]).to_i + 1
   end
@@ -69,6 +75,10 @@ class Picture < ActiveRecord::Base
     flag_reverse < 0 ? [''] : ['', 'v', 'h', 'vh']
   end
   
+  def self.find_by_md5 md5
+    r = Picture.find :all, :conditions => ['pictures.md5 = ?', md5], :order => 'pictures.updated_at desc'
+  end
+  
   def self.list_by_md5 md5, opid
     r = Picture.find :all, :conditions => ['pictures.md5 = ? and pictures.original_picture_id <> ?', md5, opid], :order => 'pictures.updated_at desc'
   end
@@ -118,6 +128,10 @@ class Picture < ActiveRecord::Base
     "#{self.classname.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