Class: AlchemyCrm::Newsletter

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/alchemy_crm/newsletter.rb

Instance Method Summary collapse

Instance Method Details

#can_delete_mailings?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/alchemy_crm/newsletter.rb', line 39

def can_delete_mailings?
  raise "Cannot delete Newsletter because of referencing Mailings with IDs (#{mailings.collect(&:id).join(", ")})" if(mailings.length != 0)
end

#contactsObject



17
18
19
# File 'app/models/alchemy_crm/newsletter.rb', line 17

def contacts
  (verified_contact_group_contacts + verified_subscribers).uniq
end

#contacts_countObject



21
22
23
24
# File 'app/models/alchemy_crm/newsletter.rb', line 21

def contacts_count
  return 0 if contacts.blank?
  contacts.length
end

#humanized_nameObject



31
32
33
# File 'app/models/alchemy_crm/newsletter.rb', line 31

def humanized_name
  "#{name} (#{contacts_count})"
end

#layout_nameObject



43
44
45
# File 'app/models/alchemy_crm/newsletter.rb', line 43

def layout_name
  NewsletterLayout.display_name_for(layout)
end

#verified_contact_group_contactsObject

get all uniq contacts from my contact groups



27
28
29
# File 'app/models/alchemy_crm/newsletter.rb', line 27

def verified_contact_group_contacts
  contact_groups.collect { |contact_group| contact_group.contacts.available }.flatten.uniq
end

#verified_subscribersObject



35
36
37
# File 'app/models/alchemy_crm/newsletter.rb', line 35

def verified_subscribers
  subscribers.available.includes(:subscriptions).where(:alchemy_crm_subscriptions => {:verified => true, :wants => true})
end