Class: Campaign

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

Overview

Copyright © 2008-2013 Michael Dvorkin and contributors.

Fat Free CRM is freely distributable under the terms of MIT license. See MIT-LICENSE file or www.opensource.org/licenses/mit-license.php


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

.per_pageObject

Default values provided through class methods.




72
73
74
# File 'app/models/entities/campaign.rb', line 72

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.




78
79
80
81
82
83
84
85
86
87
88
# File 'app/models/entities/campaign.rb', line 78

def attach!(attachment)
  unless send("#{attachment.class.name.downcase}_ids").include?(attachment.id)
    if attachment.is_a?(Task)
      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.




92
93
94
95
96
97
98
99
# File 'app/models/entities/campaign.rb', line 92

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