Inject dateBlock to services which use it

[MAILPOET-2665]
This commit is contained in:
Rostislav Wolny
2020-01-30 11:01:28 +01:00
committed by Jack Kitterhing
parent 6827eb93e6
commit dc5a296133
6 changed files with 39 additions and 15 deletions

View File

@ -25,16 +25,21 @@ class FormEditor {
/** @var FormRenderer */
private $formRenderer;
/** @var Block\Date */
private $dateBlock;
public function __construct(
PageRenderer $pageRenderer,
CustomFieldsRepository $customFieldsRepository,
CustomFieldsResponseBuilder $customFieldsResponseBuilder,
FormRenderer $formRenderer
FormRenderer $formRenderer,
Block\Date $dateBlock
) {
$this->pageRenderer = $pageRenderer;
$this->customFieldsRepository = $customFieldsRepository;
$this->customFieldsResponseBuilder = $customFieldsResponseBuilder;
$this->formRenderer = $formRenderer;
$this->dateBlock = $dateBlock;
}
public function render() {
@ -45,7 +50,7 @@ class FormEditor {
}
$form['styles'] = $this->formRenderer->getStyles($form);
$customFields = $this->customFieldsRepository->findAll();
$dateTypes = Block\Date::getDateTypes();
$dateTypes = $this->dateBlock->getDateTypes();
$data = [
'form' => $form,
'form_exports' => [
@ -62,8 +67,8 @@ class FormEditor {
'value' => $value,
];
}, $dateTypes, array_keys($dateTypes)),
'date_formats' => Block\Date::getDateFormats(),
'month_names' => Block\Date::getMonthNames(),
'date_formats' => $this->dateBlock->getDateFormats(),
'month_names' => $this->dateBlock->getMonthNames(),
'sub_menu' => 'mailpoet-forms',
'custom_fields' => $this->customFieldsResponseBuilder->buildBatch($customFields),
];

View File

@ -27,11 +27,21 @@ class Subscribers {
/** @var WPFunctions */
private $wp;
public function __construct(PageRenderer $pageRenderer, PageLimit $listingPageLimit, SubscribersFeature $subscribersFeature, WPFunctions $wp) {
/** @var Block\Date */
private $dateBlock;
public function __construct(
PageRenderer $pageRenderer,
PageLimit $listingPageLimit,
SubscribersFeature $subscribersFeature,
WPFunctions $wp,
Block\Date $dateBlock
) {
$this->pageRenderer = $pageRenderer;
$this->listingPageLimit = $listingPageLimit;
$this->subscribersFeature = $subscribersFeature;
$this->wp = $wp;
$this->dateBlock = $dateBlock;
}
public function render() {
@ -59,8 +69,8 @@ class Subscribers {
return $field;
}, CustomField::findArray());
$data['date_formats'] = Block\Date::getDateFormats();
$data['month_names'] = Block\Date::getMonthNames();
$data['date_formats'] = $this->dateBlock->getDateFormats();
$data['month_names'] = $this->dateBlock->getMonthNames();
$data['premium_plugin_active'] = License::getLicense();
$data['mss_active'] = Bridge::isMPSendingServiceEnabled();

View File

@ -15,18 +15,22 @@ class SubscribersImport {
/** @var Installation */
private $installation;
public function __construct(PageRenderer $pageRenderer, Installation $installation) {
/** @var Block\Date */
private $dateBlock;
public function __construct(PageRenderer $pageRenderer, Installation $installation, Block\Date $dateBlock) {
$this->pageRenderer = $pageRenderer;
$this->installation = $installation;
$this->dateBlock = $dateBlock;
}
public function render() {
$import = new ImportExportFactory(ImportExportFactory::IMPORT_ACTION);
$data = $import->bootstrap();
$data = array_merge($data, [
'date_types' => Block\Date::getDateTypes(),
'date_formats' => Block\Date::getDateFormats(),
'month_names' => Block\Date::getMonthNames(),
'date_types' => $this->dateBlock->getDateTypes(),
'date_formats' => $this->dateBlock->getDateFormats(),
'month_names' => $this->dateBlock->getMonthNames(),
'sub_menu' => 'mailpoet-subscribers',
'role_based_emails' => json_encode(ModelValidator::ROLE_EMAILS),
]);

View File

@ -116,7 +116,7 @@ class CustomField extends Model {
}
if (!empty($value)) {
$value = Date::convertDateToDatetime($value, $dateFormat);
$value = (new Date())->convertDateToDatetime($value, $dateFormat);
}
}

View File

@ -162,7 +162,7 @@ class Import {
$data = array_map(
function($index, $date) use($validationRule, &$invalidRecords) {
if (empty($date)) return $date;
$date = Date::convertDateToDatetime($date, $validationRule);
$date = (new Date())->convertDateToDatetime($date, $validationRule);
if (!$date) {
$invalidRecords[] = $index;
}

View File

@ -58,6 +58,9 @@ class Pages {
/** @var FormRenderer */
private $formRenderer;
/** @var FormBlockDate */
private $dateBlock;
public function __construct(
NewSubscriberNotificationMailer $newSubscriberNotificationSender,
WPFunctions $wp,
@ -68,7 +71,8 @@ class Pages {
LinkTokens $linkTokens,
SubscriptionUrlFactory $subscriptionUrlFactory,
AssetsController $assetsController,
FormRenderer $formRenderer
FormRenderer $formRenderer,
FormBlockDate $dateBlock
) {
$this->wp = $wp;
$this->newSubscriberNotificationSender = $newSubscriberNotificationSender;
@ -80,6 +84,7 @@ class Pages {
$this->subscriptionUrlFactory = $subscriptionUrlFactory;
$this->assetsController = $assetsController;
$this->formRenderer = $formRenderer;
$this->dateBlock = $dateBlock;
}
public function init($action = false, $data = [], $initShortcodes = false, $initPageFilters = false) {
@ -322,7 +327,7 @@ class Pages {
$customField['params']['value'] = $subscriber->{$customField['id']};
if ($customField['type'] === 'date') {
$dateFormats = FormBlockDate::getDateFormats();
$dateFormats = $this->dateBlock->getDateFormats();
$customField['params']['date_format'] = array_shift(
$dateFormats[$customField['params']['date_type']]
);