Sha256: 11e7991241caa9bda498a7446cffb44ee02de5a45594465ca75958d7faa5fbac

Contents?: true

Size: 1.75 KB

Versions: 22

Compression:

Stored size: 1.75 KB

Contents

class Gallery < AppModel2

  belongs_to :site
  validates :site, :presence => true

  belongs_to :user,         :optional => true
  belongs_to :user_profile, :optional => true, :class_name => 'IshModels::UserProfile'
  field :username, :type => String
  
  field :name, :type => String
  validates :name, :uniqueness => true # , :allow_nil => false

  field :galleryname, :type => String
  validates :galleryname, :uniqueness => true # , :allow_nil => false

  field :subhead, :type => String
  field :descr, :type => String
  field :lang, :type => String, :default => 'en'

  has_many :photos

  belongs_to :tag,   :optional => true
  belongs_to :city,  :optional => true
  belongs_to :venue, :optional => true

  has_many :newsitems

  set_callback(:create, :before) do |doc|
    if doc.user_profile && doc.user_profile.username
      doc.username = doc.user_profile.username
    end
    doc.galleryname = doc.id.to_s

    #
    # newsitems
    #
    if doc.is_public 
      # for the sites
      if doc.site
        sites = Site.where( :domain => doc.site.domain )
        sites.each do |site|
          n = Newsitem.new {}
          n.gallery = doc
          n.username = doc.username
          site.newsitems << n
          flag = site.save
          if !flag
            puts! site.errors
          end
        end
      end
      # for the city
      if doc.city
        n = Newsitem.new {}
        n.gallery = doc
        n.city = doc.city
        n.username = doc.username
        n.save
      end
    end

    #
    # cache
    #
    if doc.site
      doc.site.touch
    end
    if doc.city
      doc.city.touch
    end

  end

  # @deprecated, use Gallery::ACTIONS
  def self.actions
    [ 'show_mini', 'show_long', 'show' ]
  end
  ACTIONS = [ 'show_mini', 'show_long', 'show' ]

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
ish_models-0.0.33.31 lib/gallery.rb
ish_models-0.0.33.30 lib/gallery.rb
ish_models-0.0.33.29 lib/gallery.rb
ish_models-0.0.33.28 lib/gallery.rb
ish_models-0.0.33.27 lib/gallery.rb
ish_models-0.0.33.26 lib/gallery.rb
ish_models-0.0.33.25 lib/gallery.rb
ish_models-0.0.33.24 lib/gallery.rb
ish_models-0.0.33.23 lib/gallery.rb
ish_models-0.0.33.22 lib/gallery.rb
ish_models-0.0.33.21 lib/gallery.rb
ish_models-0.0.33.20 lib/gallery.rb
ish_models-0.0.33.19 lib/gallery.rb
ish_models-0.0.33.18 lib/gallery.rb
ish_models-0.0.33.17 lib/gallery.rb
ish_models-0.0.33.16 lib/gallery.rb
ish_models-0.0.33.15 lib/gallery.rb
ish_models-0.0.33.14 lib/gallery.rb
ish_models-0.0.33.13 lib/gallery.rb
ish_models-0.0.33.12 lib/gallery.rb