Skip to content
This repository was archived by the owner on Nov 30, 2017. It is now read-only.

Commit 27d1f09

Browse files
committed
Merge pull request #21 from AKarismatik/master
add segment and send campaign to segment
2 parents 16ec81e + 7d1ca06 commit 27d1f09

File tree

3 files changed

+130
-2
lines changed

3 files changed

+130
-2
lines changed

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ MZMailChimpBundle is licensed under the MIT License - see the `Resources/meta/LI
1616
5. `campaignCreate`
1717
6. `campaignSendTest`
1818
7. `campaignSendNow`
19+
8. `listStaticSegmentAdd`
20+
9. `listStaticSegmentMembersAdd`
21+
10. `listStaticSegments`
1922

2023
**MailChimp Export API Method Supported**
2124

@@ -256,3 +259,65 @@ mz_mail_chimp:
256259

257260
$ecommerce->getOrder($pageStart, $batchLimit, $dateSince) //return array
258261
```
262+
263+
**MailChimp API [create static segment](http://apidocs.mailchimp.com/api/2.0/lists/static-segment-add.php) in a controller**
264+
265+
``` php
266+
<?php
267+
268+
$mailChimp = $this->get('MailChimp');
269+
$list = $mailChimp->getList();
270+
$list->listStaticSegmentAdd('first_segment'); // return int segment id
271+
272+
```
273+
274+
**MailChimp API [segment member add](http://apidocs.mailchimp.com/api/2.0/lists/static-segment-members-add.php) in a controller**
275+
276+
``` php
277+
<?php
278+
279+
$mailChimp = $this->get('MailChimp');
280+
$list = $mailChimp->getList();
281+
$segmentId = $list->listStaticSegmentAdd('first_segment');
282+
$batch = array('test1@example.com',test2@example.com');
283+
$list->listStaticSegmentMembersAdd($segmentId, $batch);
284+
285+
```
286+
287+
**MailChimp API [list static segment](http://apidocs.mailchimp.com/api/2.0/lists/static-segments.php) in a controller**
288+
289+
``` php
290+
<?php
291+
292+
$mailChimp = $this->get('MailChimp');
293+
$list = $mailChimp->getList();
294+
$segments = $list->listStaticSegments();
295+
296+
```
297+
298+
**MailChimp API [send campaign to segment] in a controller**
299+
300+
``` php
301+
<?php
302+
303+
$mailChimp = $this->get('MailChimp');
304+
$campaign = $mailChimp->getCampaign();
305+
$list = $mailChimp->getList();
306+
$segmentId = $list->listStaticSegmentAdd('first_segment');
307+
$batch = array('test1@example.com',test2@example.com');
308+
$list->listStaticSegmentMembersAdd($segmentId, $batch);
309+
$conditions[] = array(
310+
'field' => 'static_segment',
311+
'op' => 'eq',
312+
'value' => $segmentId
313+
);
314+
315+
$segment_options = array(
316+
'match' => 'all',
317+
'conditions' => $conditions
318+
);
319+
$campaign->setSegmenOptions($segment_options);
320+
$campaignId = $campaign->create();
321+
$campaign->SendNow($campaignId);
322+
323+
```

Services/Methods/MCCampaign.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class MCCampaign extends HttpClient
4545
private $fbComments = true;
4646
private $timeWarp = false;
4747
private $ecomm360 = false;
48+
private $segmentOptions = array();
4849

4950
/**
5051
* The list identificator
@@ -285,6 +286,16 @@ public function setEcomm360($ecomm360)
285286
{
286287
$this->ecomm360 = $ecomm360;
287288
}
289+
290+
/**
291+
* Set mailchimp segmentOptions
292+
*
293+
* @param array segmentOptions
294+
*/
295+
public function setSegmenOptions(Array $segment_options)
296+
{
297+
$this->segmentOptions = $segment_options;
298+
}
288299

289300
/**
290301
* Create options
@@ -331,9 +342,13 @@ private function Content()
331342
*/
332343
public function Create()
333344
{
345+
if(empty($this->segmentOptions)){
346+
$payload = array('type' => $this->type, 'options' => $this->Options(),
347+
'content' => $this->Content());
348+
}else {
334349
$payload = array('type' => $this->type, 'options' => $this->Options(),
335-
'content' => $this->Content());
336-
350+
'content' => $this->Content(), 'segment_opts' => $this->segmentOptions);
351+
}
337352
$apiCall = 'campaignCreate';
338353
$data = $this->makeRequest($apiCall, $payload);
339354
$data = json_decode($data);

Services/Methods/MCList.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,52 @@ public function listInterestGroupingAdd($name, $type, $groups = array())
236236
$data = $this->makeRequest($apiCall, $payload);
237237
return json_decode($data);
238238
}
239+
240+
/**
241+
* create static segment
242+
* @param segment name
243+
* @return segment id
244+
*/
245+
public function listStaticSegmentAdd($name)
246+
{
247+
$payload = array(
248+
'id' => $this->listId,
249+
'name' => $name,
250+
);
251+
$apiCall = 'listStaticSegmentAdd';
252+
$data = $this->makeRequest($apiCall, $payload);
253+
return json_decode($data);
254+
}
255+
256+
/**
257+
* add emails to segment
258+
* @param int $seg_id
259+
* @param array $batch
260+
* @return mixed
261+
*/
262+
public function listStaticSegmentMembersAdd($seg_id, $batch = array())
263+
{
264+
$payload = array(
265+
'id' => $this->listId,
266+
'seg_id' => $seg_id,
267+
'batch' => $batch,
268+
);
269+
$apiCall = 'listStaticSegmentMembersAdd';
270+
$data = $this->makeRequest($apiCall, $payload);
271+
return json_decode($data);
272+
}
273+
274+
/**
275+
* get all segments
276+
* @return array
277+
*/
278+
public function listStaticSegments()
279+
{
280+
$payload = array(
281+
'id' => $this->listId,
282+
);
283+
$apiCall = 'listStaticSegments';
284+
$data = $this->makeRequest($apiCall, $payload);
285+
return json_decode($data);
286+
}
239287
}

0 commit comments

Comments
 (0)