OSDN Git Service

merge
[pettanr/pettanr.git] / app / models / ground_picture.rb
index b1f13f0..bd1d16d 100644 (file)
@@ -11,6 +11,26 @@ class GroundPicture < Peta::Element
   validates :z, :presence => true, :numericality => {:greater_than => 0}
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   
+  scope :with_panel, -> do
+    includes(:panel)
+  end
+  
+  scope :find_index, -> do
+    with_panel.where(Panel.arel_table[:publish].gt 0).references(:panel)
+  end
+  
+  scope :find_private, -> (operators) do 
+    with_panel.where(Panel.arel_table[:author_id].eq operators.author.id).references(:panel)
+  end
+  
+  scope :find_by_panel, -> (panel_id) do 
+    find_index.where(panel_id: panel_id).references(:panel)
+  end
+  
+  scope :find_by_author, -> (author_id) do 
+    find_index.where(Panel.arel_table[:author_id].eq author_id).references(:panel)
+  end
+  
   @@repeat_texts = ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']
   
   def self.pickup_item_name
@@ -61,7 +81,7 @@ class GroundPicture < Peta::Element
       'position' => 'absolute', 'top' => '0px', 'left' => '0px', 'z-index' => self.z, 
       'background-image' => "url(#{self.picture.url})", 
       'background-repeat' => self.repeat_text, 
-      'background-position' => "#{self.x}px #{self.attr_y}px"
+      'background-position' => "#{self.x}px #{self.y}px"
     }
     self.merge_opacity(r, opacity) if spot and spot != self
     r