-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\PsEventbus\Provider; | ||
|
||
use PrestaShop\Module\PsEventbus\Config\Config; | ||
use PrestaShop\Module\PsEventbus\Decorator\CustomerDecorator; | ||
use PrestaShop\Module\PsEventbus\Repository\CustomerRepository; | ||
|
||
class CustomerDataProvider implements PaginatedApiDataProviderInterface | ||
{ | ||
/** | ||
* @var CustomerRepository | ||
*/ | ||
private $customerRepository; | ||
/** | ||
* @var CustomerDecorator | ||
*/ | ||
private $customerDecorator; | ||
|
||
public function __construct(CustomerRepository $customerRepository, CustomerDecorator $customerDecorator) | ||
{ | ||
$this->customerRepository = $customerRepository; | ||
$this->customerDecorator = $customerDecorator; | ||
} | ||
|
||
/** | ||
* @param int $offset | ||
* @param int $limit | ||
* @param string $langIso | ||
* | ||
* @return array<mixed> | ||
* | ||
* @@throws \PrestaShopDatabaseException | ||
*/ | ||
public function getFormattedData($offset, $limit, $langIso) | ||
{ | ||
$customers = $this->customerRepository->getCustomers($offset, $limit); | ||
|
||
if (!is_array($customers)) { | ||
return []; | ||
} | ||
|
||
$this->customerDecorator->decorateCustomers($customers); | ||
|
||
return array_map(function ($customer) { | ||
return [ | ||
'id' => "{$customer['id_customer']}", | ||
'collection' => Config::COLLECTION_CUSTOMERS, | ||
'properties' => $customer, | ||
]; | ||
}, $customers); | ||
} | ||
|
||
/** | ||
* @param int $offset | ||
* @param string $langIso | ||
* | ||
* @return int | ||
*/ | ||
public function getRemainingObjectsCount($offset, $langIso) | ||
{ | ||
return (int) $this->customerRepository->getRemainingCustomersCount($offset); | ||
} | ||
|
||
/** | ||
* @param int $limit | ||
* @param string $langIso | ||
* @param array<mixed> $objectIds | ||
* | ||
* @return array<mixed> | ||
* | ||
* @@throws \PrestaShopDatabaseException | ||
*/ | ||
public function getFormattedDataIncremental($limit, $langIso, $objectIds) | ||
{ | ||
$customers = $this->customerRepository->getCustomersIncremental($limit, $objectIds); | ||
|
||
if (!is_array($customers)) { | ||
return []; | ||
} | ||
|
||
$this->customerDecorator->decorateCustomers($customers); | ||
|
||
return array_map(function ($customer) { | ||
return [ | ||
'id' => "{$customer['id_customer']}", | ||
'collection' => Config::COLLECTION_CUSTOMERS, | ||
'properties' => $customer, | ||
]; | ||
}, $customers); | ||
} | ||
|
||
/** | ||
* @param int $offset | ||
* @param int $limit | ||
* @param string $langIso | ||
* | ||
* @return array<mixed> | ||
* | ||
* @@throws \PrestaShopDatabaseException | ||
*/ | ||
public function getQueryForDebug($offset, $limit, $langIso) | ||
{ | ||
return $this->customerRepository->getQueryForDebug($offset, $limit); | ||
} | ||
} |