OSDN Git Service

temp
[pettanr/pettanr.git] / app / models / original_picture.rb
index c141cc8..5b3b29d 100644 (file)
@@ -1,4 +1,4 @@
-class OriginalPicture < Pettanr::Item
+class OriginalPicture < Pettanr::Content
   belongs_to :artist
   belongs_to :original_picture_license_group
   has_one :resource_picture
@@ -11,16 +11,8 @@ class OriginalPicture < Pettanr::Item
   validates :artist_id, :presence => true, :numericality => true, :existence => {:both => false}
   validates :md5, :presence => true, :length => {:minimum => 32, :maximum => 32}
   
-  def self.singular
-    'OriginalPicture'
-  end
-  
-  def self.plural
-    'OriginalPictures'
-  end
-  
   def self.owner_type
-    :author
+    :artist
   end
   
   def supply_default
@@ -31,18 +23,10 @@ class OriginalPicture < Pettanr::Item
     self.artist_id = ar.id
   end
   
-  def own? roles
-    roles = [roles] unless roles.respond_to?(:each)
-    ar = OriginalPicture.get_artist_from_roles roles
-    return false unless ar
-    self.artist_id == ar.id
+  def visible? operators
+    return false unless super
+    false
   end
-  
-  def visible? roles
-    return true if self.admin_role_check roles
-    self.own?(roles)
-  end
-  
   def filename
     "#{self.id}.#{self.ext}"
   end
@@ -90,37 +74,8 @@ class OriginalPicture < Pettanr::Item
     self.published_at != nil
   end
   
-  def self.default_page_size
-    25
-  end
-  
-  def self.max_page_size
-    100
-  end
-  
-  def self.page prm = nil
-    page = prm.to_i
-    page = 1 if page < 1
-    page
-  end
-  
-  def self.page_size prm = self.default_page_size
-    page_size = prm.to_i
-    page_size = self.max_page_size if page_size > self.max_page_size
-    page_size = self.default_page_size if page_size < 1
-    page_size
-  end
-  
-  def self.mylist_where ar
-    ['original_pictures.artist_id = ?', ar.id]
-  end
-  
-  def self.mylist ar, page = 1, page_size = self.default_page_size
-    OriginalPicture.where(self.mylist_where(ar)).includes(OriginalPicture.list_opt).order('original_pictures.updated_at desc').offset((page -1) * page_size).limit(page_size)
-  end
-  
-  def self.mylist_paginate ar, page = 1, page_size = self.default_page_size
-    Kaminari.paginate_array(Array.new(OriginalPicture.where(self.mylist_where(ar)).count, nil)).page(page).per(page_size)
+  def self.list_order
+    'original_pictures.updated_at desc'
   end
   
   def self.list_opt
@@ -135,22 +90,6 @@ class OriginalPicture < Pettanr::Item
     Picture.find(:all, {:conditions => ['pictures.original_picture_id = ?', self.id], :order => 'pictures.revision desc'} )
   end
   
-  def self.show cid, roles
-    opt = {}
-    opt.merge!(self.show_opt)
-    res = OriginalPicture.find(cid, opt)
-    raise ActiveRecord::Forbidden unless res.visible?(roles)
-    res
-  end
-  
-  def self.edit cid, ar
-    opt = {}
-    opt.merge!(self.show_opt)
-    res = OriginalPicture.find(cid, opt)
-    raise ActiveRecord::Forbidden unless res.own?(ar)
-    res
-  end
-  
   def self.show_opt
     {:include => {:resource_picture => {}, :pictures => {}}}
   end