OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / models / balloon.rb
index fbfc8bf..110a3aa 100644 (file)
@@ -53,6 +53,10 @@ class Balloon < ActiveRecord::Base
 self.system_picture_id = 1
   end
   
+  def symbol_option
+    self.get_parent.speech_balloon_template.symbol_option
+  end
+  
   def get_parent
     self.speech_balloon || @new_parent
   end
@@ -82,16 +86,20 @@ self.system_picture_id = 1
     page_size
   end
   
+  def self.list_where
+    'panels.publish > 0'
+  end
+  
   def self.list page = 1, page_size = self.default_page_size
-    opt = {}
-    opt.merge!(Balloon.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => 'panels.publish > 0', :order => 'balloons.updated_at desc'})
-    Balloon.find(:all, opt)
+    Balloon.where(self.list_where()).includes(Balloon.list_opt).order('balloons.updated_at desc').offset((page -1) * page_size).limit(page_size)
+  end
+  
+  def self.list_paginate page = 1, page_size = self.default_page_size
+    Kaminari.paginate_array(Array.new(Balloon.where(self.list_where()).includes(Balloon.list_opt).count, nil)).page(page).per(page_size)
   end
   
   def self.list_opt
-    {:include => {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}}
+    {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}
   end
   
   def self.list_json_opt