OSDN Git Service

work
[pettanr/pettanr.git] / app / models / speech.rb
index 3622ff9..82e99c4 100644 (file)
@@ -1,4 +1,4 @@
-class Speech < ActiveRecord::Base
+class Speech < Pettanr::Content
   include ElementPart
   belongs_to :speech_balloon
   belongs_to :writing_format
@@ -17,13 +17,12 @@ class Speech < ActiveRecord::Base
   
   @@text_align_texts = ['left', 'left', 'right', 'center']
   
-  before_validation :valid_encode
+  def owner_model
+    self.speech_balloon.panel
+  end
   
-  def valid_encode
-    ['content', 'quotes', 'settings'].each do |a|
-      next if attributes[a] == nil
-      raise Pettanr::BadRequest unless attributes[a].valid_encoding?
-    end
+  def self.valid_encode_columns
+    super + ['content', 'quotes', 'settings']
   end
   
   def self.colum_structures
@@ -41,14 +40,13 @@ class Speech < ActiveRecord::Base
     self.height = 100
   end
   
-  def visible? roles
-    if MagicNumber['run_mode'] == 0
-      return false unless guest_role_check(roles)
-    else
-      return false unless reader_role_check(roles)
-    end
-    return true if self.speech_balloon.panel.own?(roles)
-    self.speech_balloon.panel.visible? roles
+  def visible? operators
+    return false unless super
+    self.owner_model.visible? operators
+  end
+  
+  def symbol_option
+    self.get_parent.speech_balloon_template.symbol_option
   end
   
   def get_parent
@@ -63,51 +61,22 @@ class Speech < ActiveRecord::Base
     @@text_align_texts[self.text_align]
   end
   
-  def self.default_page_size
-    25
+  def self.list_where
+    'panels.publish > 0'
   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.list page = 1, page_size = self.default_page_size
-    opt = {}
-    opt.merge!(Speech.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => 'panels.publish > 0', :order => 'speeches.updated_at desc'})
-    Speech.find(:all, opt)
+  def self.list_order
+    'speeches.updated_at desc'
   end
   
   def self.list_opt
-    {:include => {:speech_balloon => {:panel => {:author => {}}, :balloon => {}, :speech_balloon_template => {}} }}
+    {:speech_balloon => {:panel => {:author => {}}, :balloon => {}, :speech_balloon_template => {}} }
   end
   
   def self.list_json_opt
     {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech_balloon_template => {} }}}}
   end
   
-  def self.show cid, au
-    opt = {}
-    opt.merge!(Speech.show_opt)
-    res = Speech.find(cid, opt)
-    raise ActiveRecord::Forbidden unless res.visible?(au)
-    res
-  end
-  
   def self.show_opt
     {:include => {:speech_balloon => {:panel => {:author => {}}, :balloon => {}, :speech_balloon_template => {} }}}
   end