Class: MailManager::MailingList

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Deleteable, StatusHistory
Defined in:
app/models/mail_manager/mailing_list.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Deleteable

#delete, included, #is_deleted?, #undelete

Methods included from StatusHistory

#change_status, included, #set_default_status, #status, #status=, #status_changed_at=

Class Method Details

.active_email_addresses_contact_ids_subscription_ids_for_mailing_list_ids(mailing_list_ids) ⇒ Object

custom query to efficiently retrieve the active email addresses and contact ids and subscription ids for a given list of mailing lists



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/mail_manager/mailing_list.rb', line 30

def self.active_email_addresses_contact_ids_subscription_ids_for_mailing_list_ids(mailing_list_ids)
  results = MailManager::MailingList.connection.execute(
    %Q|select c.email_address as email_address, c.id as contact_id, 
    s.id as subscription_id from #{MailManager.table_prefix}contacts c 
    inner join #{MailManager.table_prefix}subscriptions s on c.id=s.contact_id 
    where s.status in ('active') and c.deleted_at is NULL and mailing_list_id in (#{
    mailing_list_ids.map(&:to_i).uniq.join(',')})|
  )
  results = results.map(&:values) if results.first.is_a?(Hash)
  results.inject(Hash.new){ |h,r|
    h.merge!(r[0].to_s.strip.downcase => {
      contact_id: r[1].to_i, subscription_id: r[2].to_i
    })
  }
end

Instance Method Details

#active?Boolean

whether or not the mailing list has been soft deleted

Returns:

  • (Boolean)


47
48
49
# File 'app/models/mail_manager/mailing_list.rb', line 47

def active?
  deleted_at.nil?
end

#inactive?Boolean

whether or not the mailing list has been soft deleted

Returns:

  • (Boolean)


52
53
54
# File 'app/models/mail_manager/mailing_list.rb', line 52

def inactive?
  !active?
end