You are here

class CampaignMonitorCampaign in Campaign Monitor 8

Hierarchy

Expanded class hierarchy of CampaignMonitorCampaign

1 file declares its use of CampaignMonitorCampaign
CampaignMonitorCampaignSendForm.php in modules/campaignmonitor_campaign/src/Form/CampaignMonitorCampaignSendForm.php

File

modules/campaignmonitor_campaign/src/CampaignMonitorCampaign.php, line 10

Namespace

Drupal\campaignmonitor_campaign
View source
class CampaignMonitorCampaign extends CampaignMonitor {

  /**
   * Used to load the different library parts of the API.
   */
  const CampaignMonitorCAMPAIGN = 'csrest_campaigns.php';
  protected $campaignMonitor;

  /**
   *
   */
  public function __construct() {

    // // Get account information.
    $this->campaignMonitor = CampaignMonitor::GetConnector();
  }

  /**
   * Create API campaign object.
   *
   * @return mixed object CS_REST_Clients | FALSE
   *   The Campaign Monitor client object or FALSE on failure.
   */
  protected function createCampaignObj() {
    if ($this->campaignMonitor
      ->libraryLoad(self::CampaignMonitorCAMPAIGN)) {

      // See http://drupal.stackexchange.com/questions/142247/how-to-autoload-classes-from-a-3rd-party-php-library-in-drupal-8
      return new \CS_REST_Campaigns($this->campaignMonitor->client_id, $this->campaignMonitor->api_key);
    }
    $this->campaignMonitor
      ->addError(WATCHDOG_ERROR, t('Failed to locate the client library.'));
    return FALSE;
  }

  /**
   * Create a new campaign at the Campaign Monitor servers. The side-effect is that
   * the local cache is cleared.
   *
   * @param array $data
   *   Has the following keys:
   *   'Subject' => 'Campaign Subject',
   *   'Name' => 'Campaign Name',
   *   'FromName' => 'Campaign From Name',
   *   'FromEmail' => 'Campaign From Email Address',
   *   'ReplyTo' => 'Campaign Reply To Email Address',
   *   'HtmlUrl' => 'Campaign HTML Import URL',
   *   # 'TextUrl' => 'Optional campaign text import URL',
   *   'ListIDs' => array('First List', 'Second List'),
   *   'SegmentIDs' => array('First Segment', 'Second Segment')
   *
   * @return bool
   *   TRUE on success, FALSE otherwise.
   */
  public function createCampaign($data) {
    if ($obj = $this
      ->createCampaignObj(NULL)) {
      $result = $obj
        ->create($this->campaignMonitor->client_id, $data);
      if ($result
        ->was_successful()) {

        // Clear the cache, so the list information can be retrieved again.
        $this->campaignMonitor
          ->clearCache();
        return $result
          ->was_successful();
      }
      else {
        $this->campaignMonitor
          ->addError(WATCHDOG_ERROR, $result->response->Message, $result->http_status_code);
        drupal_set_message(t('Error message: @message', [
          '@message' => $result->response->Message,
        ]));
        return FALSE;
      }
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CampaignMonitor::$apiKey protected property
CampaignMonitor::$campaigns protected property
CampaignMonitor::$clientId protected property
CampaignMonitor::$config protected property Config settings.
CampaignMonitor::$drafts protected property
CampaignMonitor::$errors protected property
CampaignMonitor::$instance protected static property Holds the object instance (part of the singleton pattern).
CampaignMonitor::$lists protected property These variables are used as static cache for the object.
CampaignMonitor::$listStats protected property
CampaignMonitor::$logErrors protected property
CampaignMonitor::$subscribers protected property
CampaignMonitor::addError protected function Add an error to the local stack and call watchdog, if logging is enabled.
CampaignMonitor::CAMPAIGNMONITORCLIENT constant Used to load the different library parts of the API.
CampaignMonitor::CAMPAIGNMONITORLIST constant
CampaignMonitor::CAMPAIGNMONITORSUBSCRIBERS constant
CampaignMonitor::clearCache public function Clears all the caches used by this wrapper object.
CampaignMonitor::createClientObj protected function Create API client object.
CampaignMonitor::createList public function Create a new list at the Campaign Monitor servers. The side-effect is that the local cache is cleared.
CampaignMonitor::createListObj protected function Create API list object.
CampaignMonitor::createSubscriberObj protected function Create API subscribers object.
CampaignMonitor::deleteList public function Delete a list from Campaign Monitor. This action can not be reverted. The list is also removed from the local cache.
CampaignMonitor::getCacheTimeout protected function Create a UNIX timestamp based on the cache timeout set in the administration interface.
CampaignMonitor::getCampaigns public function Get basic information about campaigns in the form of a keyed array. The information is stored locally in a temporary cache. The array is formatted like this:.
CampaignMonitor::getConnector public static function Implements a singleton pattern that returns an instance of this object. The function requires Campaign Monitor account keys to create the connection. These keys can be found at the Campaign Monitor homepage and should be entered in the administration…
CampaignMonitor::getCustomFields public function Fetch custom fields for a given list, then store this information locally in the list cache. The information is stored as a keyed array on the list array under the "CustomFields" key.
CampaignMonitor::getDrafts public function Get basic information about drafts in the form of a keyed array. The information is stored locally in a temporary cache. The array is formatted like this:.
CampaignMonitor::getErrors public function Returns the internal error array with the format below.
CampaignMonitor::getExtendedList public function Get all information available about a given list. This is done by calling getLists(), getListDetails() and getCustomFields(), hence building the local list cache.
CampaignMonitor::getLatestError public function Returns the latest error from the stack of possible errors encountered during communication with Campaign Monitor servers.
CampaignMonitor::getListDetails public function Gets list details from Campaign Monitor. This information is retrieved from the local cache and may be outdated. It fetches the unsubscribe link, confirmation success page and confirmed opt-in options.
CampaignMonitor::getLists public function Gets all lists from Campaign Monitor found under the client ID given during object creation. The list is returned as a keyed array and cached in the cache table, so it may not always return the newest information.
CampaignMonitor::getListStats public function Fetch stats about a given list, which includes number of subscribers and unsubscribers. This information is temporarily stored in the local cache. The default timeout is 360 seconds.
CampaignMonitor::getSubscriber public function Get values entered by the subscriber, when she/he subscribed to a given list.
CampaignMonitor::isSubscribed public function Check if a given user, identified by e-mail address, is subscribed to a given list.
CampaignMonitor::removeSubscriberFromCache public function Remove subscribers from local cache. This forces the data to be fetched from Campaign Monitor at the next request. This function should be used in connection with updating subscriber information.
CampaignMonitor::resetErrors public function Resets the internal error array to an empty array.
CampaignMonitor::subscribe public function Subscribe a user to a given list, with information entered. If the user is already subscribed to the list, her/his information will be updated with the new values.
CampaignMonitor::unsubscribe public function Unsubscribe a given user, identified by e-mail address, from a given list.
CampaignMonitor::updateList public function Update remote list information. The options array should have the fields "Title", "UnsubscribePage", "ConfirmedOptIn" and "ConfirmationSuccessPage". If you do not wish to set these use an empty string.
CampaignMonitor::updateSubscriberEmail public function Updates the subscriber e-mail address for a given list.
CampaignMonitorCampaign::$campaignMonitor protected property
CampaignMonitorCampaign::CampaignMonitorCAMPAIGN constant Used to load the different library parts of the API.
CampaignMonitorCampaign::createCampaign public function Create a new campaign at the Campaign Monitor servers. The side-effect is that the local cache is cleared.
CampaignMonitorCampaign::createCampaignObj protected function Create API campaign object.
CampaignMonitorCampaign::__construct public function Private class constructor, which prevents creation of this class directly. Use the static function CampaignMonitor::GetConnector(). Overrides CampaignMonitor::__construct