Refactor ALC endpoint to follow DI

[MAILPOET-1637]
This commit is contained in:
Rostislav Wolny
2018-11-14 22:46:04 +01:00
parent e0863e4b7e
commit 38e9d806b8
3 changed files with 12 additions and 11 deletions

View File

@ -10,13 +10,14 @@ use MailPoet\WP\Posts as WPPosts;
if(!defined('ABSPATH')) exit;
class AutomatedLatestContent extends APIEndpoint {
/** @var \MailPoet\Newsletter\AutomatedLatestContent */
public $ALC;
public $permissions = array(
'global' => AccessControl::PERMISSION_MANAGE_EMAILS
);
function __construct() {
$this->ALC = new \MailPoet\Newsletter\AutomatedLatestContent();
function __construct(\MailPoet\Newsletter\AutomatedLatestContent $alc) {
$this->ALC = $alc;
}
function getPostTypes() {
@ -74,14 +75,12 @@ class AutomatedLatestContent extends APIEndpoint {
}
function getBulkTransformedPosts($data = array()) {
$alc = new \MailPoet\Newsletter\AutomatedLatestContent();
$used_posts = array();
$rendered_posts = array();
foreach($data['blocks'] as $block) {
$posts = $alc->getPosts($block, $used_posts);
$rendered_posts[] = $alc->transformPosts($block, $posts);
$posts = $this->ALC->getPosts($block, $used_posts);
$rendered_posts[] = $this->ALC->transformPosts($block, $posts);
foreach($posts as $post) {
$used_posts[] = $post->ID;
@ -90,4 +89,4 @@ class AutomatedLatestContent extends APIEndpoint {
return $this->successResponse($rendered_posts);
}
}
}