Skip to content

Commit c1f507b

Browse files
authored
Merge pull request #34 from dlubitz/feature/interest-categories
Feature: Add datasource for interest categories and interests
2 parents 820d139 + 32f0c1c commit c1f507b

4 files changed

Lines changed: 175 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Wwwision\Neos\MailChimp\DataSource;
4+
5+
use Neos\ContentRepository\Domain\Model\NodeInterface;
6+
use Neos\Neos\Service\DataSource\AbstractDataSource;
7+
use Wwwision\Neos\MailChimp\Domain\Service\MailChimpService;
8+
9+
class InterestCategoryDataSource extends AbstractDataSource
10+
{
11+
/**
12+
* @var string
13+
*/
14+
static protected $identifier = 'mailchimp-interest-category';
15+
16+
/**
17+
* @var MailChimpService
18+
*/
19+
protected $mailChimpService;
20+
21+
public function __construct(MailChimpService $mailChimpService)
22+
{
23+
$this->mailChimpService = $mailChimpService;
24+
}
25+
26+
/**
27+
* @inheritDoc
28+
*/
29+
public function getData(NodeInterface $node = null, array $arguments = [])
30+
{
31+
$listId = $arguments['listId'];
32+
33+
$response = $this->mailChimpService->getInterestCategoriesByList($listId);
34+
$interestCategories = $response['categories'] ?? [];
35+
36+
$data = [];
37+
foreach ($interestCategories as $interestCategory) {
38+
$data[] = [
39+
'value' => $interestCategory['id'],
40+
'label' => $interestCategory['title']
41+
];
42+
}
43+
return $data;
44+
}
45+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Wwwision\Neos\MailChimp\DataSource;
4+
5+
use Neos\ContentRepository\Domain\Model\NodeInterface;
6+
use Neos\Neos\Service\DataSource\AbstractDataSource;
7+
use Wwwision\Neos\MailChimp\Domain\Service\MailChimpService;
8+
use Wwwision\Neos\MailChimp\Exception\MailChimpException;
9+
10+
class InterestDataSource extends AbstractDataSource
11+
{
12+
/**
13+
* @var string
14+
*/
15+
static protected $identifier = 'mailchimp-interest';
16+
17+
/**
18+
* @var MailChimpService
19+
*/
20+
protected $mailChimpService;
21+
22+
public function __construct(MailChimpService $mailChimpService)
23+
{
24+
$this->mailChimpService = $mailChimpService;
25+
}
26+
27+
/**
28+
* @inheritDoc
29+
*/
30+
public function getData(NodeInterface $node = null, array $arguments = [])
31+
{
32+
$listId = $arguments['listId'];
33+
$categoryId = $arguments['categoryId'];
34+
35+
$response = $this->mailChimpService->getInterestByListAndCategory($listId, $categoryId);
36+
$interests = $response['interests'] ?? [];
37+
38+
$data = [];
39+
foreach ($interests as $interest) {
40+
$data[] = [
41+
'value' => $interest['id'],
42+
'label' => $interest['name']
43+
];
44+
}
45+
return $data;
46+
}
47+
}

Classes/Wwwision/Neos/MailChimp/Domain/Service/MailChimpService.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,24 @@ private function makeRequest(string $method, string $resource, array $arguments
234234
throw new MailChimpException($errorMessage, 1483533997);
235235
}
236236

237+
/**
238+
* @param string $listId
239+
* @return array
240+
* @throws HttpException | MailChimpException | ResourceNotFoundException
241+
*/
242+
public function getInterestCategoriesByList(string $listId): array
243+
{
244+
return $this->get("lists/$listId/interest-categories/");
245+
}
246+
247+
/**
248+
* @param string $listId
249+
* @param string $categoryId
250+
* @return array
251+
* @throws HttpException | MailChimpException | ResourceNotFoundException
252+
*/
253+
public function getInterestByListAndCategory(string $listId, string $categoryId): array
254+
{
255+
return $this->get("lists/$listId/interest-categories/$categoryId/interests");
256+
}
237257
}

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,69 @@ finishers:
142142

143143
The Form finisher can of course be used without Neos (i.e. for Newsletter-subscriptions within plain Flow applications).
144144

145+
DataSources
146+
-----------
147+
148+
### Interest Categories
149+
150+
Returns a list of all interest categories with ids and label in the subscription list.
151+
152+
DataSourceIdentifier: `mailchimp-interest-category`
153+
154+
dataSourceAdditionalData:
155+
* `listId` - (string) Id of subscription list
156+
157+
### Interests
158+
159+
Returns a list of all interests with ids and label of the given category in the subscription list.
160+
161+
DataSourceIdentifier: `mailchimp-interest`
162+
163+
dataSourceAdditionalData:
164+
* `listId` - (string) Id of subscription list
165+
* `categoryId` - (string) Id of interest category
166+
167+
### Example NodeType configuration
168+
```yaml
169+
...
170+
properties:
171+
subscriptionList:
172+
type: string
173+
defaultValue: ''
174+
ui:
175+
label: Subscription list id
176+
category:
177+
type: string
178+
defaultValue: ''
179+
ui:
180+
label: Category
181+
inspector:
182+
hidden: 'ClientEval:node.properties.subscriptionList != "" ? false : true'
183+
editor: Neos.Neos/Inspector/Editors/SelectBoxEditor
184+
editorOptions:
185+
allowEmpty: true
186+
dataSourceIdentifier: mailchimp-interest-category
187+
dataSourceAdditionalData:
188+
listId: ClientEval:node.properties.subscriptionList
189+
interestId:
190+
type: string
191+
defaultValue: ''
192+
ui:
193+
label: Interest
194+
inspector:
195+
group: categories
196+
hidden: 'ClientEval:node.properties.category != "" ? false : true'
197+
editor: Neos.Neos/Inspector/Editors/SelectBoxEditor
198+
editorOptions:
199+
allowEmpty: true
200+
dataSourceIdentifier: mailchimp-interest
201+
dataSourceAdditionalData:
202+
listId: ClientEval:node.properties.subscriptionList
203+
categoryId: ClientEval:node.properties.category
204+
```
205+
206+
207+
145208
Trivia
146209
------
147210

0 commit comments

Comments
 (0)