def overwrite
end
- def own? ad
+ def own? roles
+ roles = [roles] unless roles.respond_to?(:each)
+ ad = SystemPicture.get_admin_from_roles roles
+ return false unless ad
true
end
{:src => self.url, :width => tw, :height => th}
end
+ def symbol_option
+ self.tmb_opt_img_tag
+ end
+
def self.default_page_size
25
end
page_size
end
+ def self.list_where
+ nil
+ end
+
def self.list page = 1, page_size = self.default_page_size
- opt = {}
- opt.merge!(self.list_opt)
- opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
- opt.merge!({:order => 'system_pictures.updated_at desc'})
- SystemPicture.find(:all, opt)
+ SystemPicture.where(self.list_where()).includes(SystemPicture.list_opt).order('system_pictures.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(SystemPicture.where(self.list_where()).count, nil)).page(page).per(page_size)
end
def self.list_opt
res = false
SystemPicture.transaction do
if res = self.save
- if res = PictureIO.system_picture_io.put(imager.binary, self.filename)
- res = true
- else
- self.errors.add :base, 'system picture io does not work'
+ begin
+ res = PictureIO.system_picture_io.put(imager.binary, self.filename)
+ rescue PictureIO::Error
+ res = false
+ self.errors.add :base, I18n.t('picture_io.error')
raise ActiveRecord::Rollback
end
end