OSDN Git Service

fix: any
[pettanr/pettanr.git] / app / models / panel_picture.rb
index e0da3dc..2406f77 100644 (file)
@@ -5,7 +5,8 @@ class PanelPicture < Peta::Element
   
   validates :panel_id, :numericality => {:allow_blank => true}
   validates :picture_id, :numericality => true, :existence => {:both => false}
   
   validates :panel_id, :numericality => {:allow_blank => true}
   validates :picture_id, :numericality => true, :existence => {:both => false}
-  validates :link, :length => {:maximum => 200}, :url => {:allow_blank => true, :message => I18n.t('errors.messages.url')}
+  validates :link, :length => {:maximum => 200}, :allow_blank => true
+  #validates :link, :length => {:maximum => 200}, :url => {:allow_blank => true, :message => I18n.t('errors.messages.url')}
   validates :x, :presence => true, :numericality => true
   validates :y, :presence => true, :numericality => true
   validates :width, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :sync_vh => true
   validates :x, :presence => true, :numericality => true
   validates :y, :presence => true, :numericality => true
   validates :width, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :sync_vh => true
@@ -13,6 +14,26 @@ class PanelPicture < Peta::Element
   validates :z, :presence => true, :numericality => {:greater_than => 0}
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   
   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
+  
   def self.pickup_item_name
     Picture.item_name
   end
   def self.pickup_item_name
     Picture.item_name
   end
@@ -26,7 +47,7 @@ class PanelPicture < Peta::Element
     self.attributes[self.pickup_column_name]
   end
   
     self.attributes[self.pickup_column_name]
   end
   
-  def attr_y
+  def y
     self.attributes['y']
   end
   
     self.attributes['y']
   end
   
@@ -67,7 +88,8 @@ class PanelPicture < Peta::Element
   end
   
   def filename
   end
   
   def filename
-    self.picture.filename + '?subdir=' + self.flip
+    q = self.flip.empty? ? '' : '?subdir=' + self.flip
+    self.picture.filename + q
   end
   
   def url
   end
   
   def url
@@ -75,7 +97,7 @@ class PanelPicture < Peta::Element
   end
   
   def opt_div_style
   end
   
   def opt_div_style
-    "top:#{self.attr_y}px; left:#{self.x}px; z-index:#{self.z}; position: absolute;"
+    "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; position: absolute;"
   end
   
   def opt_img_tag spot = nil, opacity = 20
   end
   
   def opt_img_tag spot = nil, opacity = 20
@@ -96,7 +118,7 @@ class PanelPicture < Peta::Element
     self.picture.symbol_option
   end
   
     self.picture.symbol_option
   end
   
-  def self.public_list_where
+  def self.public_list_where list
     'panels.publish > 0'
   end
   
     'panels.publish > 0'
   end
   
@@ -104,6 +126,14 @@ class PanelPicture < Peta::Element
     {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
   end
   
     {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
   end
   
+  def disp_link
+    if self.link =~ /\:\/\//
+      self.link
+    else
+      '/' + self.link.to_s
+    end
+  end
+  
   def scenario
     if caption.blank?
       ''
   def scenario
     if caption.blank?
       ''