Class: AlchemyCrm::Mailing
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AlchemyCrm::Mailing
- Defined in:
- app/models/alchemy_crm/mailing.rb
Constant Summary collapse
- MAILING_PAGE_LAYOUT_PREFIX =
"newsletter_layout_"
Class Method Summary collapse
-
.copy(id) ⇒ Object
Makes a copy of another mailing.
Instance Method Summary collapse
-
#additional_emails ⇒ Object
Return a list of email addresses from additional_email_addresses field.
-
#contacts ⇒ Object
Returns all contacts found via newsletter contacts and additional email addresses.
- #contacts_count ⇒ Object
-
#contacts_from_additional_email_addresses ⇒ Object
Returns a list of contacts found or initialized by email address from additional_email_addresses field.
- #contacts_not_having_email_yet ⇒ Object
-
#emails ⇒ Object
Returns a list of all email addresses for contacts that have not got any email yet.
-
#newsletter_contacts ⇒ Object
Returns all contacts found via newsletter.
- #next_pending_delivery ⇒ Object
Class Method Details
.copy(id) ⇒ Object
Makes a copy of another mailing.
56 57 58 59 60 61 |
# File 'app/models/alchemy_crm/mailing.rb', line 56 def self.copy(id) source = self.find(id) new(source.attributes.merge( "name" => "#{source.name} (#{::I18n.t(:copy, :scope => :alchemy_crm, :default => 'Copy')})" ).except("id", "updated_at", "created_at", "sha1", "salt", "page_id")) end |
Instance Method Details
#additional_emails ⇒ Object
Return a list of email addresses from additional_email_addresses field.
45 46 47 48 |
# File 'app/models/alchemy_crm/mailing.rb', line 45 def additional_emails return [] if additional_email_addresses.blank? additional_email_addresses.gsub(/\s/,'').split(',').uniq end |
#contacts ⇒ Object
Returns all contacts found via newsletter contacts and additional email addresses.
25 26 27 |
# File 'app/models/alchemy_crm/mailing.rb', line 25 def contacts ( + contacts_from_additional_email_addresses).uniq end |
#contacts_count ⇒ Object
29 30 31 32 |
# File 'app/models/alchemy_crm/mailing.rb', line 29 def contacts_count return 0 if contacts.blank? contacts.count end |
#contacts_from_additional_email_addresses ⇒ Object
Returns a list of contacts found or initialized by email address from additional_email_addresses field.
51 52 53 |
# File 'app/models/alchemy_crm/mailing.rb', line 51 def contacts_from_additional_email_addresses additional_emails.collect{ |email| Contact.find_or_initialize_by_email(:email => email) } end |
#contacts_not_having_email_yet ⇒ Object
34 35 36 37 |
# File 'app/models/alchemy_crm/mailing.rb', line 34 def contacts_not_having_email_yet return contacts if recipients.empty? contacts.select { |c| !recipients.collect(&:email).include?(c.email) } end |
#emails ⇒ Object
Returns a list of all email addresses for contacts that have not got any email yet.
40 41 42 |
# File 'app/models/alchemy_crm/mailing.rb', line 40 def emails contacts_not_having_email_yet.collect(&:email) end |
#newsletter_contacts ⇒ Object
Returns all contacts found via newsletter.
19 20 21 22 |
# File 'app/models/alchemy_crm/mailing.rb', line 19 def return [] if .blank? .contacts end |
#next_pending_delivery ⇒ Object
63 64 65 |
# File 'app/models/alchemy_crm/mailing.rb', line 63 def next_pending_delivery deliveries.pending.first end |