Class: Campaign

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/entities/campaign.rb

Overview

Schema Information

Table name: campaigns

id                  :integer         not null, primary key
user_id             :integer
assigned_to         :integer
name                :string(64)      default(""), not null
access              :string(8)       default("Public")
status              :string(64)
budget              :decimal(12, 2)
target_leads        :integer
target_conversion   :float
target_revenue      :decimal(12, 2)
leads_count         :integer
opportunities_count :integer
revenue             :decimal(12, 2)
starts_on           :date
ends_on             :date
objectives          :text
deleted_at          :datetime
created_at          :datetime
updated_at          :datetime
background_info     :string(255)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.outlineObject



81
# File 'app/models/entities/campaign.rb', line 81

def self.outline  ; "long" ; end

.per_pageObject

Default values provided through class methods.




80
# File 'app/models/entities/campaign.rb', line 80

def self.per_page ; 20     ; end

Instance Method Details

#attach!(attachment) ⇒ Object

Attach given attachment to the campaign if it hasn’t been attached already.




85
86
87
88
89
90
91
92
93
94
95
# File 'app/models/entities/campaign.rb', line 85

def attach!(attachment)
  unless self.send("#{attachment.class.name.downcase}_ids").include?(attachment.id)
    if attachment.is_a?(Task)
      self.send(attachment.class.name.tableize) << attachment
    else # Leads, Opportunities
      attachment.update_attribute(:campaign, self)
      attachment.send("increment_#{attachment.class.name.tableize}_count")
      [ attachment ]
    end
  end
end

#discard!(attachment) ⇒ Object

Discard given attachment from the campaign.




99
100
101
102
103
104
105
106
# File 'app/models/entities/campaign.rb', line 99

def discard!(attachment)
  if attachment.is_a?(Task)
    attachment.update_attribute(:asset, nil)
  else # Leads, Opportunities
    attachment.send("decrement_#{attachment.class.name.tableize}_count")
    attachment.update_attribute(:campaign, nil)
  end
end