X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fmodels%2Fground_picture.rb;h=4b4269ec7a398fffc4cab13cf0b8d8f8dbf54230;hb=9e6a7b976f22e15609976da5194ea6344e71ea4d;hp=4f0dc4a4ea31dd2e4f1a9695dd4dedfd58ad7638;hpb=f147e9e652978757d8a4ae58e11f2c81f69fac0e;p=pettanr%2Fpettanr.git diff --git a/app/models/ground_picture.rb b/app/models/ground_picture.rb index 4f0dc4a4..4b4269ec 100644 --- a/app/models/ground_picture.rb +++ b/app/models/ground_picture.rb @@ -1,4 +1,4 @@ -class GroundPicture < ActiveRecord::Base +class GroundPicture < Pettanr::Item include Element include ElementInspire belongs_to :panel @@ -14,13 +14,20 @@ class GroundPicture < ActiveRecord::Base @@repeat_texts = ['repeat', 'repeat-x', 'repeat-y', 'no-repeat'] - before_validation :valid_encode + def self.singular + 'GroundPicture' + end - def valid_encode - ['caption'].each do |a| - next if attributes[a] == nil - raise Pettanr::BadRequest unless attributes[a].valid_encoding? - end + def self.plural + 'GroundPictures' + end + + def self.owner_type + :author + end + + def self.valid_encode_columns + super.merge ['caption'] end def self.list_opt_for_panel @@ -83,6 +90,10 @@ class GroundPicture < ActiveRecord::Base {:src => self.picture.url, :width => tw, :height => th, :alt => self.caption} end + def symbol_option + self.tmb_opt_img_tag + end + def boost end @@ -151,6 +162,14 @@ class GroundPicture < ActiveRecord::Base Kaminari.paginate_array(Array.new(GroundPicture.where(self.himlist_where(au)).includes(GroundPicture.list_opt).count, nil)).page(page).per(page_size) end + def self.list_by_panel_where panel_id + ['ground_pictures.panel_id = ?', panel_id] + end + + def self.list_by_panel panel_id, roles, page = 1, page_size = self.default_page_size + self.where(self.list_by_panel_where(panel_id)).includes(self.list_opt).order('ground_pictures.updated_at desc').offset((page -1) * page_size).limit(page_size) + end + def self.list_opt {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} } end