Sha256: d3b795841d36b5c8a45b7a9eb6eaf84636ae58a056478d02529896e50aefff33

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

class Group < ActiveRecord::Base

  is_site_scoped if defined? ActiveRecord::SiteNotFound
  default_scope :order => 'name'

  belongs_to :created_by, :class_name => 'User'
  belongs_to :updated_by, :class_name => 'User'
  belongs_to :homepage, :class_name => 'Page'

  has_many :messages
  has_many :permissions
  has_many :pages, :through => :permissions
  has_many :memberships
  has_many :readers, :through => :memberships
  
  validates_presence_of :name
  validates_uniqueness_of :name
  
  named_scope :with_home_page, { :conditions => "homepage_id IS NOT NULL", :include => :homepage }
  named_scope :subscribable, { :conditions => "public = 1" }
  named_scope :unsubscribable, { :conditions => "public = 0" }
  
  def url
    homepage.url if homepage
  end
  
  def send_welcome_to(reader)
    if reader.activated?                                        # welcomes will be triggered again on activation
      message = messages.for_function('group_welcome').first    # only if a group_welcome message exists *belonging to this group*
      message.deliver_to(reader) if message                     # (the belonging also allows us to mention the group in the message)
    end
  end

  def permission_for(page)
    self.permissions.for(page).first
  end

  def membership_for(reader)
    self.memberships.for(reader).first
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
radiant-reader_group-extension-1.0.1 app/models/group.rb
radiant-reader_group-extension-1.0.0 app/models/group.rb
radiant-reader_group-extension-0.9.0 app/models/group.rb