Sha256: f0d14282dacf7049475f48d429801b045fcb5ff5b991d6734aa97fab0dbaf4ee

Contents?: true

Size: 1.03 KB

Versions: 152

Compression:

Stored size: 1.03 KB

Contents

##
## Sends a campaign.
## _vp_ 2023-02-02
##
class WcoEmail::Campaign
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Paranoia
  store_in collection: 'ish_email_campaigns'

  field :slug
  validates_uniqueness_of :slug, allow_nil: true

  PAGE_PARAM_NAME = 'email_contexts_page'

  field :from_email
  validates_presence_of :from_email

  belongs_to :email_template
  def tmpl; email_template; end

  field :subject
  field :body

  field :sent_at, type: DateTime
  field :send_at, type: DateTime

  has_many :unsubscribes, class_name: 'WcoEmail::Unsubscribe', inverse_of: :campaign
  has_and_belongs_to_many :leads, class_name: 'Wco::Lead'

  ## For tracking
  attr_reader :tid

  def do_send
    leads.each do |lead|
      ctx = Ctx.create!({
        email_template: tmpl,
        from_email:     tmpl.from_email,
        lead_id:        lead.id,
        send_at:        Time.now,
        subject:        tmpl.subject,
      })
    end
  end

  def self.list
    [[nil,nil]] + all.map { |p| [ p.slug, p.id ] }
  end

end

Version data entries

152 entries across 152 versions & 1 rubygems

Version Path
wco_models-3.1.0.199 app/models/wco_email/campaign.rb
wco_models-3.1.0.198 app/models/wco_email/campaign.rb
wco_models-3.1.0.197 app/models/wco_email/campaign.rb
wco_models-3.1.0.196 app/models/wco_email/campaign.rb
wco_models-3.1.0.195 app/models/wco_email/campaign.rb
wco_models-3.1.0.194 app/models/wco_email/campaign.rb
wco_models-3.1.0.193 app/models/wco_email/campaign.rb
wco_models-3.1.0.192 app/models/wco_email/campaign.rb
wco_models-3.1.0.191 app/models/wco_email/campaign.rb
wco_models-3.1.0.190 app/models/wco_email/campaign.rb
wco_models-3.1.0.189 app/models/wco_email/campaign.rb
wco_models-3.1.0.188 app/models/wco_email/campaign.rb
wco_models-3.1.0.187 app/models/wco_email/campaign.rb
wco_models-3.1.0.184 app/models/wco_email/campaign.rb
wco_models-3.1.0.183 app/models/wco_email/campaign.rb
wco_models-3.1.0.182 app/models/wco_email/campaign.rb
wco_models-3.1.0.181 app/models/wco_email/campaign.rb
wco_models-3.1.0.180 app/models/wco_email/campaign.rb
wco_models-3.1.0.178 app/models/wco_email/campaign.rb
wco_models-3.1.0.177 app/models/wco_email/campaign.rb