Class: MailManager::MailingList
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MailManager::MailingList
- Includes:
- Deleteable, StatusHistory
- Defined in:
- app/models/mail_manager/mailing_list.rb
Class Method Summary collapse
-
.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.
Instance Method Summary collapse
-
#active? ⇒ Boolean
whether or not the mailing list has been soft deleted.
-
#inactive? ⇒ Boolean
whether or not the mailing list has been soft deleted.
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
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
52 53 54 |
# File 'app/models/mail_manager/mailing_list.rb', line 52 def inactive? !active? end |