# Campaign Model

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

# Attributes

Attribute Data Type Comment
id Integer
parent_id Integer
type String
title String
available_urls Text
slug String
status String
template_id Integer
email_subject String
email_pre_header String
email_body Text
recipients_count Integer
delay Integer
utm_status Boolean
utm_source String
utm_medium String
utm_campaign String
utm_term String
utm_content String
design_template String
scheduled_at Date Time
last_activity Date Time
settings Text
created_by Integer
created_at Date Time
updated_at Date Time

# Usage

Please check Model Basic for Common methods.

# Accessing Attributes


$campaign = FluentCrm\App\Models\Campaign::find(1);

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

# Scopes

This model has the following scopes that you can use

# ofType($status)

Filter campaign by status

  • Parameters
    • $status - string

# Usage:

// Get all which has published, draft and archived status
$campaigns = FluentCrm\App\Models\Campaign::ofType('published')->get();
1
2

# archived()

Filter campaign by status

# Usage:

// Get all campaign which has archived status
$campaigns = FluentCrm\App\Models\Campaign::archived()->get();
1
2

# Relations

This model has the following relationships that you can use

# template

Access the associated template of a model

  • return FluentCrm\App\Models\Template Model Collection

# Example:

// Accessing Template
$campaignTemplate = $campaign->template;

// For Filtering by template relationship

// Get Campaigns which has post_status: publish
$campaigns = FluentCrm\App\Models\Campaign::whereHas('template', function($query) {
    $query->where('post_status', 'publish');
})->get();

// Get Campaigns which does not have post_status: publish
$campaigns = FluentCrm\App\Models\Campaign::whereDoesntHave('template', function($query) {
    $query->where('post_status', 'publish');
})->get();

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

# emails

Access all the associated emails of a model

  • return FluentCrm\App\Models\CampaignEmail Model Collections

# Example:

// Accessing CampaignEmails
$campaignEmails = $campaign->emails;

// For Filtering by tags relationship

// Get Campaigns which has email ids: 1/2/3
$campaigns = FluentCrm\App\Models\Campaign::whereHas('emails', funtion($query) {
    $query->whereIn('id', [1,2,3]);
})->get();

// Get Campaigns which does not have email ids: 1/2/3
$campaigns = FluentCrm\App\Models\Campaign::whereDoesntHave('emails', funtion($query) {
    $query->whereIn('id', [1,2,3]);
})->get();
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# campaign_emails

Access all the associated campaign emails which has email_type 'campaign' of a model

  • return FluentCrm\App\Models\CampaignEmail Model Collections

# Example:

// Accessing All the emails which has email_type 'campaign' of campaign
$campaignEmails = $campaign->campaign_emails;
1
2

# subjects

Access all the associated subjects of a Campaign model

  • return FluentCrm\App\Models\Subject Model Collections

# Example:

// Accessing All the Subjects of campaign
$campaignSubjects = $campaign->subjects;
1
2

# Methods

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

# subscribeBySegment($settings, $limit, $offset)

Subscribe contacts to a campaign

  • Parameters
    • $settings array
    • $limit boolean|int Default: false
    • $offset int Default: 0
  • Returns array

# Usage

$response = $campaign->subscribeBySegment($settings, 10, 2);
1

# getSubscribersModel($settings)

Get Contact's model by campaign settings

  • Parameters
    • $settings array
  • Returns array

# Usage

$contactModel = $campaign->getSubscribersModel($settings);
1

# getSubscriberIdsBySegmentSettings($settings, $limit, $offset)

Get contact's ids by campaign settings

  • Parameters
    • $settings array
    • $limit boolean|int Default: false
    • $offset int Default: 0
  • Returns array

# Usage

$subscriberIds = $campaign->getSubscriberIdsBySegmentSettings($settings, 10, 2);
1

# getSubscriberIdsCountBySegmentSettings($settings, $status)

Get Unsubscribe reason if contact unsubscribe and provide feedback

  • Parameters
    • $settings array
    • $status string Default: subscribed
  • Returns int

# Usage

$total = $campaign->getSubscriberIdsCountBySegmentSettings($settings, 'subscribed');
1

# getSubQueryForLisTorTagFilter($query, $ids, $table, $objectType)

Get the sub-query by list or tag filtering

  • Parameters
    • $query object
    • $ids array
    • $table string
    • $objectType string
  • Returns object

# Usage

$query = $campaign->getSubQueryForLisTorTagFilter($query, [1,2,3], 'tags', 'FluentCrm\App\Models\Tag');
1

# getSubscribeIdsByList($items, $status, $limit, $offset)

Get the contact list which has provided lists

  • Parameters
    • $items array
    • $status string Default: subscribed
    • $limit boolean|int Default: false
    • $offset int Default: 0
  • Returns boolean

# Usage

$isInTags = $campaign->getSubscribeIdsByList($items, 'subscribed', 20, 2);
1

# getSubscribeIdsByListCount($items, $status, $limit, $offset)

Get the contact list count which has provided lists

  • Parameters
    • $items array
    • $status string Default: subscribed
    • $limit boolean|int Default: false
    • $offset int Default: 0
  • Returns boolean

# Usage

$total = $campaign->getSubscribeIdsByListCount($items, 'subscribed', 20, 2);
1

# getSubscribeIdsByListModel($items, $status, $limit, $offset)

Get the contact list by list model

  • Parameters
    • $items array
    • $status string Default: subscribed
    • $limit boolean|int Default: false
    • $offset int Default: 0
  • Returns array

# Usage

$subscriberIds = $campaign->getSubscribeIdsByListModel($items, 'subscribed', 20, 2);
1

# subscribe($subscriberIds, $emailArgs, $isModel)

Subscribe contact to campaign

  • Parameters
    • $subscriberIds array
    • $emailArgs array extra campaign_email args
    • $isModel boolean if the $subscriberIds is collection or not
  • Returns array

# Usage

$updatedSubscriberIds = $campaign->subscribe([1,2,5], [], false);
1

# unsubscribe($subscriberIds)

Remove contacts from a Campaign

  • Parameters
    • $subscriberIds array
  • Returns boolean

# Usage

$result = $campaign->unsubscribe([1,2,3]);
1

# guessEmailSubject($listIds)

Guess the subject by probability formula

  • Parameters
    • $listIds array
  • Returns object or null

# Usage

$campaign->guessEmailSubject();
1

# getParsedText($text, $subscriber)

Parse shortcodes of contact's info

  • Parameters
    • $text string
    • $subscriber array
    • Returns string

# Usage

$campaign->getParsedText('{{contact.first_name}}', $subscriber);
1

# filterDuplicateSubscribers($subscriberIds, $subscribers)

Filter all duplicate subscribers

  • Parameters
    • $subscriberIds array
    • $subscribers array
  • Returns array

# Usage

$subscriberIds = $campaign->filterDuplicateSubscribers([1,2,3], $subscribers);
1

# archive()

Archive campaign

  • Parameters
    • none
  • Returns boolean

# Usage

$result = $campaign->archive();
1

# getUtmParams()

Get utm params [utm_source, utm_medium, utm_campaign, utm_term, utm_content]

  • Parameters
    • none
  • Returns array

# Usage

$utm = $campaign->getUtmParams();
1

# stats

Get Campaign's utm records

  • Parameters
    • none
  • Returns array

# Usage

$campaignStats = $campaign->stats();
1

# getEmailCount()

get email counts of campaign

  • Parameters
    • none
  • Returns int

# Usage

$total = $campaign->getEmailCount();
1

# maybeDeleteDuplicates()

to remove duplicate records of campaign

  • Parameters
    • none
  • Returns object FluentCrm\App\Models\Campaign

# Usage

$campaign = $campaign->maybeDeleteDuplicates();
1

# getHash()

Get campaign's hash

  • Parameters
    • none
  • Returns string

# Usage

$hash = $campaign->getHash();
1

# deleteCampaignData()

Delete campaign's data

  • Parameters
    • none
  • Returns object FluentCrm\App\Models\Campaign

# Usage

$campaign = $campaign->deleteCampaignData();
1