Listing method update for Newsletters/Forms/Segments/Subscribers
- updated unit tests
This commit is contained in:
@@ -32,8 +32,8 @@ class Forms extends APIEndpoint {
|
||||
|
||||
$listing_data = $listing->get();
|
||||
|
||||
// fetch segments relations for each returned item
|
||||
foreach($listing_data['items'] as $key => $form) {
|
||||
$data = array();
|
||||
foreach($listing_data['items'] as $form) {
|
||||
$form = $form->asArray();
|
||||
|
||||
$form['signups'] = StatisticsForms::getTotalSignups($form['id']);
|
||||
@@ -43,10 +43,15 @@ class Forms extends APIEndpoint {
|
||||
? $form['settings']['segments']
|
||||
: array()
|
||||
);
|
||||
$listing_data['items'][$key] = $form;
|
||||
|
||||
$data[] = $form;
|
||||
}
|
||||
|
||||
return $listing_data;
|
||||
return $this->successResponse($data, array(
|
||||
'count' => $listing_data['count'],
|
||||
'filters' => $listing_data['filters'],
|
||||
'groups' => $listing_data['groups']
|
||||
));
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
@@ -285,15 +285,14 @@ class Newsletters extends APIEndpoint {
|
||||
}
|
||||
|
||||
function listing($data = array()) {
|
||||
|
||||
$listing = new Listing\Handler(
|
||||
'\MailPoet\Models\Newsletter',
|
||||
$data
|
||||
);
|
||||
$listing_data = $listing->get();
|
||||
$subscriber = Subscriber::getCurrentWPUser();
|
||||
|
||||
foreach($listing_data['items'] as $key => $newsletter) {
|
||||
$data = array();
|
||||
foreach($listing_data['items'] as $newsletter) {
|
||||
$queue = false;
|
||||
|
||||
if($newsletter->type === Newsletter::TYPE_STANDARD) {
|
||||
@@ -325,14 +324,18 @@ class Newsletters extends APIEndpoint {
|
||||
}
|
||||
|
||||
// get preview url
|
||||
$subscriber = Subscriber::getCurrentWPUser();
|
||||
$newsletter->preview_url = NewsletterUrl::getViewInBrowserUrl(
|
||||
$newsletter, $subscriber, $queue, $preview = true);
|
||||
|
||||
// convert object to array
|
||||
$listing_data['items'][$key] = $newsletter->asArray();
|
||||
$data[] = $newsletter->asArray();
|
||||
}
|
||||
|
||||
return $listing_data;
|
||||
return $this->successResponse($data, array(
|
||||
'count' => $listing_data['count'],
|
||||
'filters' => $listing_data['filters'],
|
||||
'groups' => $listing_data['groups']
|
||||
));
|
||||
}
|
||||
|
||||
function bulkAction($data = array()) {
|
||||
|
@@ -32,18 +32,22 @@ class Segments extends APIEndpoint {
|
||||
|
||||
$listing_data = $listing->get();
|
||||
|
||||
// fetch segments relations for each returned item
|
||||
foreach($listing_data['items'] as $key => $segment) {
|
||||
$data = array();
|
||||
foreach($listing_data['items'] as $segment) {
|
||||
$segment->subscribers_url = admin_url(
|
||||
'admin.php?page=mailpoet-subscribers#/filter[segment='.$segment->id.']'
|
||||
);
|
||||
|
||||
$listing_data['items'][$key] = $segment
|
||||
$data[] = $segment
|
||||
->withSubscribersCount()
|
||||
->asArray();
|
||||
}
|
||||
|
||||
return $listing_data;
|
||||
return $this->successResponse($data, array(
|
||||
'count' => $listing_data['count'],
|
||||
'filters' => $listing_data['filters'],
|
||||
'groups' => $listing_data['groups']
|
||||
));
|
||||
}
|
||||
|
||||
function save($data = array()) {
|
||||
|
@@ -41,14 +41,18 @@ class Subscribers extends APIEndpoint {
|
||||
|
||||
$listing_data = $listing->get();
|
||||
|
||||
// fetch segments relations for each returned item
|
||||
foreach($listing_data['items'] as $key => $subscriber) {
|
||||
$listing_data['items'][$key] = $subscriber
|
||||
$data = array();
|
||||
foreach($listing_data['items'] as $subscriber) {
|
||||
$data[] = $subscriber
|
||||
->withSubscriptions()
|
||||
->asArray();
|
||||
}
|
||||
|
||||
return $listing_data;
|
||||
return $this->successResponse($data, array(
|
||||
'count' => $listing_data['count'],
|
||||
'filters' => $listing_data['filters'],
|
||||
'groups' => $listing_data['groups']
|
||||
));
|
||||
}
|
||||
|
||||
function subscribe($data = array()) {
|
||||
|
Reference in New Issue
Block a user