diff --git a/src/RESTApi/ActivitiesHandler.php b/src/RESTApi/ActivitiesHandler.php index 3a5ac05e..ac612912 100644 --- a/src/RESTApi/ActivitiesHandler.php +++ b/src/RESTApi/ActivitiesHandler.php @@ -15,6 +15,8 @@ namespace CustomerManagementFrameworkBundle\RESTApi; +use CustomerManagementFrameworkBundle\ActivityStore\ActivityStoreInterface; +use CustomerManagementFrameworkBundle\CustomerProvider\CustomerProviderInterface; use CustomerManagementFrameworkBundle\Filter\ExportActivitiesFilterParams; use CustomerManagementFrameworkBundle\Model\Activity\GenericActivity; use CustomerManagementFrameworkBundle\Model\ActivityInterface; @@ -24,6 +26,7 @@ use CustomerManagementFrameworkBundle\RESTApi\Traits\ResourceUrlGenerator; use CustomerManagementFrameworkBundle\RESTApi\Traits\ResponseGenerator; use CustomerManagementFrameworkBundle\Traits\LoggerAware; +use Knp\Component\Pager\PaginatorInterface; use Symfony\Component\HttpFoundation\Request; class ActivitiesHandler extends AbstractHandler implements CrudHandlerInterface @@ -32,6 +35,15 @@ class ActivitiesHandler extends AbstractHandler implements CrudHandlerInterface use ResponseGenerator; use ResourceUrlGenerator; + public function __construct( + PaginatorInterface $paginator, + protected ActivityStoreInterface $activityStore, + protected CustomerProviderInterface $customerProvider + ) + { + parent::__construct($paginator); + } + /** * GET /activities * @@ -48,7 +60,7 @@ public function listRecords(Request $request) $pageSize = intval($request->get('pageSize', 100)); $page = intval($request->get('page', 1)); - $paginator = \Pimcore::getContainer()->get('cmf.activity_store')->getActivitiesDataForWebservice( + $paginator = $this->activityStore->getActivitiesDataForWebservice( $pageSize, $page, $param @@ -121,7 +133,7 @@ public function createRecord(Request $request) if ($activity && $activity->cmfWebserviceUpdateAllowed()) { if (!$activity->getCustomer()) { - if (!$customer = \Pimcore::getContainer()->get('cmf.customer_provider')->getById( + if (!$customer = $this->customerProvider->getById( $data['customerId'] ) ) { @@ -135,8 +147,8 @@ public function createRecord(Request $request) $activity->save(); } - $entry = \Pimcore::getContainer()->get('cmf.activity_store')->insertActivityIntoStore($activity); - $entry = \Pimcore::getContainer()->get('cmf.activity_store')->getEntryById($entry->getId()); + $entry = $this->activityStore->insertActivityIntoStore($activity); + $entry = $this->activityStore->getEntryById($entry->getId()); } else { return $this->createErrorResponse( sprintf( @@ -182,7 +194,7 @@ public function updateRecord(Request $request) $activity->save(); } - \Pimcore::getContainer()->get('cmf.activity_store')->updateActivityInStore($activity, $entry); + $this->activityStore->updateActivityInStore($activity, $entry); $entry = $this->loadActivityStoreEntry($request->get('id')); } else { return $this->createErrorResponse( @@ -218,7 +230,7 @@ public function deleteRecord(Request $request) $activity->delete(); } - \Pimcore::getContainer()->get('cmf.activity_store')->deleteEntry($entry); + $this->activityStore->deleteEntry($entry); } else { return $this->createErrorResponse( sprintf( @@ -256,7 +268,7 @@ protected function loadActivityStoreEntry($id) $id = (int)$id; } - $entry = \Pimcore::getContainer()->get('cmf.activity_store')->getEntryById($id); + $entry = $this->activityStore->getEntryById($id); if (!$entry) { throw new ResourceNotFoundException(sprintf('Activity with ID %d was not found', $id)); } diff --git a/src/RESTApi/CustomersHandler.php b/src/RESTApi/CustomersHandler.php index 732f4f03..7ebd91f5 100644 --- a/src/RESTApi/CustomersHandler.php +++ b/src/RESTApi/CustomersHandler.php @@ -15,12 +15,14 @@ namespace CustomerManagementFrameworkBundle\RESTApi; +use CustomerManagementFrameworkBundle\ActivityStore\ActivityStoreInterface; use CustomerManagementFrameworkBundle\CustomerProvider\CustomerProviderInterface; use CustomerManagementFrameworkBundle\Filter\ExportCustomersFilterParams; use CustomerManagementFrameworkBundle\Model\CustomerInterface; use CustomerManagementFrameworkBundle\RESTApi\Exception\ResourceNotFoundException; use CustomerManagementFrameworkBundle\RESTApi\Traits\ResourceUrlGenerator; use CustomerManagementFrameworkBundle\RESTApi\Traits\ResponseGenerator; +use CustomerManagementFrameworkBundle\SegmentManager\SegmentManagerInterface; use CustomerManagementFrameworkBundle\Traits\LoggerAware; use Knp\Component\Pager\PaginatorInterface; use Pimcore\Model\DataObject\Customer; @@ -33,18 +35,17 @@ class CustomersHandler extends AbstractHandler implements CrudHandlerInterface use ResponseGenerator; use ResourceUrlGenerator; - /** - * @var CustomerProviderInterface - */ - protected $customerProvider; - /** * @param CustomerProviderInterface $customerProvider */ - public function __construct(PaginatorInterface $paginator, CustomerProviderInterface $customerProvider) + public function __construct( + PaginatorInterface $paginator, + protected CustomerProviderInterface $customerProvider, + protected SegmentManagerInterface $segmentManager, + protected ActivityStoreInterface $activityStore + ) { parent::__construct($paginator); - $this->customerProvider = $customerProvider; } /** @@ -60,12 +61,12 @@ public function listRecords(Request $request) if ($params->getSegments()) { /** @var Customer\Listing $customers */ - $customers = \Pimcore::getContainer()->get('cmf.segment_manager')->getCustomersBySegmentIds( + $customers = $this->segmentManager->getCustomersBySegmentIds( $params->getSegments() ); } else { /** @var Customer\Listing $customers */ - $customers = \Pimcore::getContainer()->get('cmf.customer_provider')->getList(); + $customers = $this->customerProvider->getList(); } $idField = Service::getVersionDependentDatabaseColumnName('id'); $modificationDateField = Service::getVersionDependentDatabaseColumnName('modificationDate'); @@ -244,7 +245,7 @@ protected function hydrateCustomer(CustomerInterface $customer, ExportCustomersF $data = $customer->cmfToArray(); if ($params->getIncludeActivities()) { - $data['activities'] = \Pimcore::getContainer()->get('cmf.activity_store')->getActivityDataForCustomer( + $data['activities'] = $this->activityStore->getActivityDataForCustomer( $customer ); } diff --git a/src/RESTApi/SegmentGroupsHandler.php b/src/RESTApi/SegmentGroupsHandler.php index c7513a58..0e90b482 100644 --- a/src/RESTApi/SegmentGroupsHandler.php +++ b/src/RESTApi/SegmentGroupsHandler.php @@ -18,8 +18,10 @@ use CustomerManagementFrameworkBundle\RESTApi\Exception\ResourceNotFoundException; use CustomerManagementFrameworkBundle\RESTApi\Traits\ResourceUrlGenerator; use CustomerManagementFrameworkBundle\RESTApi\Traits\ResponseGenerator; +use CustomerManagementFrameworkBundle\SegmentManager\SegmentManagerInterface; use CustomerManagementFrameworkBundle\Service\ObjectToArray; use CustomerManagementFrameworkBundle\Traits\LoggerAware; +use Knp\Component\Pager\PaginatorInterface; use Pimcore\Model\DataObject\CustomerSegmentGroup; use Pimcore\Model\DataObject\Service; use Symfony\Component\HttpFoundation\Request; @@ -30,6 +32,14 @@ class SegmentGroupsHandler extends AbstractHandler implements CrudHandlerInterfa use ResponseGenerator; use ResourceUrlGenerator; + public function __construct( + PaginatorInterface $paginator, + protected SegmentManagerInterface $segmentManager + ) + { + parent::__construct($paginator); + } + /** * GET /segment-groups * @@ -99,7 +109,7 @@ public function createRecord(Request $request) ); } - if ($data['reference'] && \Pimcore::getContainer()->get('cmf.segment_manager')->getSegmentGroupByReference( + if ($data['reference'] && $this->segmentManager->getSegmentGroupByReference( $data['reference'], (bool)$data['calculated'] ) @@ -116,7 +126,7 @@ public function createRecord(Request $request) ); } - $segmentGroup = \Pimcore::getContainer()->get('cmf.segment_manager')->createSegmentGroup( + $segmentGroup = $this->segmentManager->createSegmentGroup( $data['name'], $data['reference'], isset($data['calculated']) ? (bool)$data['calculated'] : false, @@ -152,7 +162,7 @@ public function updateRecord(Request $request) ); } - if (!$segmentGroup = \Pimcore::getContainer()->get('cmf.segment_manager')->getSegmentGroupById( + if (!$segmentGroup = $this->segmentManager->getSegmentGroupById( $request->get('id') ) ) { @@ -165,7 +175,7 @@ public function updateRecord(Request $request) ); } - \Pimcore::getContainer()->get('cmf.segment_manager')->updateSegmentGroup($segmentGroup, $data); + $this->segmentManager->updateSegmentGroup($segmentGroup, $data); $result = $this->hydrateSegmentGroup($segmentGroup); $result['success'] = true; diff --git a/src/RESTApi/SegmentsOfCustomerHandler.php b/src/RESTApi/SegmentsOfCustomerHandler.php index 543e6999..cc6d59e4 100644 --- a/src/RESTApi/SegmentsOfCustomerHandler.php +++ b/src/RESTApi/SegmentsOfCustomerHandler.php @@ -15,7 +15,10 @@ namespace CustomerManagementFrameworkBundle\RESTApi; +use CustomerManagementFrameworkBundle\CustomerProvider\CustomerProviderInterface; +use CustomerManagementFrameworkBundle\SegmentManager\SegmentManagerInterface; use CustomerManagementFrameworkBundle\Traits\LoggerAware; +use Knp\Component\Pager\PaginatorInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\RouteCollection; @@ -23,6 +26,15 @@ class SegmentsOfCustomerHandler extends AbstractHandler { use LoggerAware; + public function __construct( + PaginatorInterface $paginator, + protected CustomerProviderInterface $customerProvider, + protected SegmentManagerInterface $segmentManager + ) + { + parent::__construct($paginator); + } + protected function getRoutes() { $routes = new RouteCollection(); @@ -54,7 +66,7 @@ public function updateRecords(Request $request) ); } - if (!$customer = \Pimcore::getContainer()->get('cmf.customer_provider')->getById($data['customerId'])) { + if (!$customer = $this->customerProvider->getById($data['customerId'])) { return new Response( [ 'success' => false, @@ -67,7 +79,7 @@ public function updateRecords(Request $request) $addSegments = []; if (is_array($data['addSegments'])) { foreach ($data['addSegments'] as $segmentId) { - if ($segment = \Pimcore::getContainer()->get('cmf.segment_manager')->getSegmentById($segmentId)) { + if ($segment = $this->segmentManager->getSegmentById($segmentId)) { $addSegments[] = $segment; } } @@ -76,19 +88,19 @@ public function updateRecords(Request $request) $deleteSegments = []; if (is_array($data['removeSegments'])) { foreach ($data['removeSegments'] as $segmentId) { - if ($segment = \Pimcore::getContainer()->get('cmf.segment_manager')->getSegmentById($segmentId)) { + if ($segment = $this->segmentManager->getSegmentById($segmentId)) { $deleteSegments[] = $segment; } } } - \Pimcore::getContainer()->get('cmf.segment_manager')->mergeSegments( + $this->segmentManager->mergeSegments( $customer, $addSegments, $deleteSegments, 'REST update API: segments-of-customer action' ); - \Pimcore::getContainer()->get('cmf.segment_manager')->saveMergedSegments($customer); + $this->segmentManager->saveMergedSegments($customer); return new Response(['success' => true], Response::RESPONSE_CODE_OK); } diff --git a/src/View/Formatter/DefaultViewFormatter.php b/src/View/Formatter/DefaultViewFormatter.php index 70fab54c..09a9ab5f 100644 --- a/src/View/Formatter/DefaultViewFormatter.php +++ b/src/View/Formatter/DefaultViewFormatter.php @@ -17,24 +17,22 @@ use Carbon\Carbon; use CustomerManagementFrameworkBundle\Model\CustomerSegmentInterface; +use Pimcore\Localization\LocaleServiceInterface; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\DataObject\ClassDefinition\Data; use Symfony\Contracts\Translation\TranslatorInterface; class DefaultViewFormatter implements ViewFormatterInterface { - /** - * @var TranslatorInterface - */ - protected $translator; + protected $locale; - public function __construct(TranslatorInterface $translator) + public function __construct( + protected TranslatorInterface $translator, + protected LocaleServiceInterface $localeService + ) { - $this->translator = $translator; } - protected $locale; - /** * @param string $messageId * @param mixed $parameters @@ -189,7 +187,7 @@ protected function getLanguageFromLocale($locale) */ protected function applyLocale() { - $locale = $this->getLocale() ?: \Pimcore::getContainer()->get('pimcore.locale')->getLocale(); + $locale = $this->getLocale() ?: $this->localeService->getLocale(); $dateLocaleMap = [ 'de' => 'de_AT',