OSDN Git Service

fix play leaf
[pettanr/pettanr.git] / app / models / comic.rb
index b4b502d..9821ae2 100644 (file)
@@ -1,9 +1,79 @@
-class Comic < ActiveRecord::Base
-  has_many :panels, :dependent => :destroy
-
-  def own? author
-    return false unless author
-    self.author_id == author.id
+#コミック
+class Comic < Peta::Binder
+  load_manifest
+  has_many :comic_stories
+  belongs_to :author
+  
+  validates :title, :presence => true, :length => {:maximum => 100}
+  validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
+  validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
+  
+  def self.visible_count_options
+    {:conditions => 'visible > 0'}
+  end
+  
+  def supply_default
+    self.visible = 0 if self.visible.blank?
+  end
+  
+  def overwrite operators
+    return false unless operators.author
+    self.author_id = operators.author.id
+  end
+  
+  def visible? operators
+    case super
+    when nil # super return
+      return true
+    when false
+      return false
+    else
+      self.visible > 0
+    end
+  end
+  
+  def symbol_filename
+  end
+  
+  def self.public_list_where
+    'comics.visible > 0'
+  end
+  
+  def self.list_order
+    'comics.updated_at desc'
+  end
+  
+  def self.list_opt
+    {:comic_stories => {:story => {}}, :author => {} }
+  end
+  
+  def self.list_json_opt
+    {:include => {:comic_stories => {:include => {:story => {}}}, :author => {}}}
+  end
+  
+  def self.show_opt
+    {:include => {:comic_stories => {:story => {}}, :author => {}}}
+  end
+  
+  def self.show_json_opt
+    {:include => {:comic_stories => {:include => {:story => {}}}, :author => {}}}
+  end
+  
+  def tag_attributes column = nil, opt = {}
+    {
+    }
+  end
+  
+  def scenario
+    panels.map {|panel|
+      panel.scenario
+    }.join
+  end
+  
+  def plain_scenario
+    panels.map {|panel|
+      panel.plain_scenario
+    }.join
   end
   
 end