# Campaign Model

DB Table Name {wp_db_prefix}_fc_campaign_emails
Schema Check Schema
Source File fluent-crm/app/Models/CampaignEmail.php
Name Space FluentCrm\App\Models
Class FluentCrm\App\Models\CampaignEmail

# Attributes

Attribute Data Type Comment
id Integer
campaign_id Integer
email_type String
subscriber_id Integer
email_subject_id Integer
email_address String
email_subject String
email_body Text
email_headers Text
is_open Boolean
is_parsed Boolean
click_counter Integer
status String
note Integer
scheduled_at Date Time
email_hash String
created_at Date Time
updated_at Date Time

# Usage

Please check Model Basic for Common methods.

# Accessing Attributes


$campaignEmail = FluentCrm\App\Models\CampaignEmail::find(1);

$campaignEmail->id; // returns id
$campaignEmail->email; // returns email
.......
1
2
3
4
5
6

# Relations

This model has the following relationships that you can use

# campaign

Access the associated campaign of a model

  • return FluentCrm\App\Models\Campaign Model Collection

# Example:

// Accessing Template
$campaign = $campaignEmail->campaign;

// For Filtering by template relationship

// Get CampaignEmails which has type: funnel_email_campaign
$campaignEmails = FluentCrm\App\Models\CampaignEmail::whereHas('campaign', function($query) {
    $query->where('type', 'funnel_email_campaign');
})->get();

// Get CampaignEmails which does not have type: funnel_email_campaign
$campaignEmails = FluentCrm\App\Models\CampaignEmail::whereDoesntHave('campaign', function($query) {
    $query->where('type', 'funnel_email_campaign');
})->get();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# subscriber

Access all the associated subscriber of a model

  • return FluentCrm\App\Models\Subscriber Model Collections

# Example:

// Accessing Subscriber
$subscriber = $campaignEmail->subscriber;

// For Filtering by tags relationship

// Get CampaignEmails which has first_name Demo
$campaignEmails = FluentCrm\App\Models\CampaignEmail::whereHas('subscriber', function($query) {
    $query->where('first_name', 'Demo');
})->get();

// Get CampaignEmails which does not have first_name Demo
$campaignEmails = FluentCrm\App\Models\CampaignEmail::whereDoesntHave('subscriber', function($query) {
    $query->where('first_name', 'Demo');
})->get();
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# subject

Access all the associated subject of a model

  • return FluentCrm\App\Models\Subject Model Collections

# Example:

// Access all the associated subject of a model
$subject = $campaignEmail->subject;
1
2

# Methods

Along with Global Model methods, this model has few helper methods.

# markAs($status)

Update campaign email status

  • Parameters
    • $status string
  • Returns FluentCrm\App\Models\CampaignEmail

# Usage

$campaignEmail = $campaignEmail->markAs('sent');
1

# markAsSent()

Update campaign email status to 'sent'

  • Parameters
    • none
  • Returns FluentCrm\App\Models\CampaignEmail

# Usage

$campaignEmail = $campaignEmail->markAsSent();
1

# markAsFailed()

Update campaign email status to 'failed'

  • Parameters
    • none
  • Returns FluentCrm\App\Models\CampaignEmail

# Usage

$campaignEmail = $campaignEmail->markAsFailed();
1

# data()

Get data for the email to be sent

  • Parameters
    • none
  • Returns array

# Usage

$emailData = $campaignEmail->data();
1

# previewData()

Preview data for the email to be sent

  • Parameters
    • none
  • Returns array

# Usage

$emailData = $campaignEmail->previewData();
1

# getEmailSubject()

Get the subject of email

  • Parameters
    • none
  • Returns string

# Usage

$subject = $campaignEmail->getEmailSubject();
1

# getEmailBody()

Get the email body (actual html code) of email

  • Parameters
    • none
  • Returns text

# Usage

$emailBody = $campaignEmail->getEmailBody();
1

# getCampaignUrls()

Get the urls which are shared in an email model

  • Parameters
    • none
  • Returns array list of urls

# Usage

$urls = $campaignEmail->getCampaignUrls();
1

# getClicks()

Get the click counts of an email

  • Parameters
    • none
  • Returns array

# Usage

$totalClicks = $campaignEmail->getClicks();
1

# getSubjectCount($campaignId)

Get the total subject of a campaign of email

  • Parameters
    • $campaignId int
  • Returns object

# Usage

$result = $campaignEmail->getSubjectCount(1);
1

# getOpenCount()

Get the open count of an email

  • Parameters
    • none
  • Returns int

# Usage

$openCount = $campaignEmail->getOpenCount();
1