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

View File

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

View File

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

View File

@ -116,7 +116,7 @@ class CustomField extends Model {
} }
if (!empty($value)) { 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( $data = array_map(
function($index, $date) use($validationRule, &$invalidRecords) { function($index, $date) use($validationRule, &$invalidRecords) {
if (empty($date)) return $date; if (empty($date)) return $date;
$date = Date::convertDateToDatetime($date, $validationRule); $date = (new Date())->convertDateToDatetime($date, $validationRule);
if (!$date) { if (!$date) {
$invalidRecords[] = $index; $invalidRecords[] = $index;
} }

View File

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