Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tractorcow/silverstripe-campaignmonitor
Simple implementation of the campaign monitor API within Silverstripe
https://github.com/tractorcow/silverstripe-campaignmonitor
Last synced: 3 months ago
JSON representation
Simple implementation of the campaign monitor API within Silverstripe
- Host: GitHub
- URL: https://github.com/tractorcow/silverstripe-campaignmonitor
- Owner: tractorcow
- Created: 2012-09-19T02:00:58.000Z (over 12 years ago)
- Default Branch: 3.0
- Last Pushed: 2019-07-12T01:58:01.000Z (over 5 years ago)
- Last Synced: 2024-09-23T20:05:46.296Z (4 months ago)
- Language: PHP
- Size: 36.1 KB
- Stars: 6
- Watchers: 2
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Campaign monitor wrapper module for Silverstripe
Simple implementation of the campaign monitor API within Silverstripe
## Credits and Authors
* Damian Mooyman -
## License
* TODO
## Requirements
* SilverStripe 3.0
* PHP 5.3
* Campaign Monitor PHP library 2.5.2 (not 3 or above! Yet! It'll break your code and make your clients grumpy).## Installation instructions
```bash
composer require tractorcow/silverstripe-campaignmonitor:"3.0.*@dev"
```## Examples
### Using the API to set a destination list (SiteConfig extension)
Given a hard coded API key, allow the user to select a client from their account,
and subsequently a list.```php
function updateCMSFields(FieldList $fields) {
// Load base object
$resources = new CMResources("my api key");// Get clients under our account
$clients = $resources->Clients()->map();
$fields->addFieldToTab(
'Root.CampaignMonitor',
new DropdownField('Client', 'Client', $clients)
);// check if client is available to select
if($this->owner->Client && ($client = $resources->getClient($this->owner->Client))) {
$lists = $client->Lists()->map();
$fields->addFieldToTab(
'Root.CampaignMonitor',
new DropdownField('DefaultList', 'Default List', $lists)
);
}
}```
### Saving a subscriber
Handling subscription details from a form submission
```php
public function subscribe($data, $form) {
$listID = SiteConfig::current_site_config()->DefaultList;
$resources = new CMResources("my api key");
if($resources && $listID && $list = $resources->getList($listID)) {
$this->addUserToList($data, $list);
Director::redirect($this->Link('thanks'));
}
// Error handling here
}protected function addUserToList($data, $list) {
if(empty($list)) return;
// Create subscriber
$fields = array(
'EmailAddress' => $data['Email'],
'Name' => $data['FirstName'],
'CustomFields' => array(
'LastName' => $data['LastName'],
'Company' => $data['Company'],
'Phone' => $data['Phone'],
'Mobile' => $data['Mobile']
),
'Resubscribe' => true,
'RestartSubscriptionBasedAutoresponders' => true
);
$subscriber = new CMSubscriber(null, $fields, $list);
$subscriber->Save();
}```