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.




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

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.




73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/entities/campaign.rb', line 73

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.




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

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