-
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
10 changed files
with
366 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
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
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
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,25 @@ | ||
<?php | ||
|
||
use PrestaShop\Module\PsEventbus\Config\Config; | ||
use PrestaShop\Module\PsEventbus\Controller\AbstractApiController; | ||
use PrestaShop\Module\PsEventbus\Provider\LanguageDataProvider; | ||
|
||
class ps_EventbusApiLanguagesModuleFrontController extends AbstractApiController | ||
{ | ||
public $type = Config::COLLECTION_LANGUAGES; | ||
|
||
/** | ||
* @return void | ||
* | ||
* @throws PrestaShopException | ||
*/ | ||
public function postProcess() | ||
{ | ||
/** @var LanguageDataProvider $languageDataProvider */ | ||
$languageDataProvider = $this->module->getService(LanguageDataProvider::class); | ||
|
||
$response = $this->handleDataSync($languageDataProvider); | ||
|
||
$this->exitWithResponse($response); | ||
} | ||
} |
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
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
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,54 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\PsEventbus\Decorator; | ||
|
||
use PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository; | ||
use PrestaShop\Module\PsEventbus\Repository\ShopRepository; | ||
|
||
class LanguageDecorator | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $timezone; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $createdAt; | ||
|
||
public function __construct( | ||
ConfigurationRepository $configurationRepository, | ||
ShopRepository $shopRepository | ||
) { | ||
$this->timezone = (string) $configurationRepository->get('PS_TIMEZONE'); | ||
$this->createdAt = $shopRepository->getCreatedAt(); | ||
} | ||
|
||
/** | ||
* @param array $languages | ||
* | ||
* @return void | ||
*/ | ||
public function decorateLanguages(array &$languages) | ||
{ | ||
foreach ($languages as &$language) { | ||
$this->castPropertyValues($language); | ||
} | ||
} | ||
|
||
/** | ||
* @param array $language | ||
* | ||
* @return void | ||
*/ | ||
private function castPropertyValues(array &$language) | ||
{ | ||
$language['id_lang'] = (int) $language['id_lang']; | ||
$language['active'] = (bool) $language['active']; | ||
$language['is_rtl'] = (bool) $language['is_rtl']; | ||
$language['id_shop'] = (int) $language['id_shop']; | ||
$language['created_at'] = (new \DateTime($this->createdAt, new \DateTimeZone($this->timezone)))->format('Y-m-d\TH:i:sO'); | ||
$language['updated_at'] = (new \DateTime($this->createdAt, new \DateTimeZone($this->timezone)))->format('Y-m-d\TH:i:sO'); | ||
} | ||
} |
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,91 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\PsEventbus\Provider; | ||
|
||
use PrestaShop\Module\PsEventbus\Config\Config; | ||
use PrestaShop\Module\PsEventbus\Decorator\LanguageDecorator; | ||
use PrestaShop\Module\PsEventbus\Repository\LanguageRepository; | ||
|
||
class LanguageDataProvider implements PaginatedApiDataProviderInterface | ||
{ | ||
/** | ||
* @var LanguageRepository | ||
*/ | ||
private $languageRepository; | ||
|
||
/** | ||
* @var LanguageDecorator | ||
*/ | ||
private $languageDecorator; | ||
|
||
public function __construct(LanguageRepository $languageRepository, LanguageDecorator $languageDecorator) | ||
{ | ||
$this->languageRepository = $languageRepository; | ||
$this->languageDecorator = $languageDecorator; | ||
} | ||
|
||
/** | ||
* @param int $offset | ||
* @param int $limit | ||
* @param string $langIso | ||
* | ||
* @return array | ||
* | ||
* @throws \PrestaShopDatabaseException | ||
*/ | ||
public function getFormattedData($offset, $limit, $langIso) | ||
{ | ||
$languages = $this->languageRepository->getLanguagesSync($offset, $limit, $langIso); | ||
|
||
if (!is_array($languages)) { | ||
return []; | ||
} | ||
$this->languageDecorator->decorateLanguages($languages); | ||
|
||
return array_map(function ($language) { | ||
return [ | ||
'id' => $language['id_lang'], | ||
'collection' => Config::COLLECTION_LANGUAGES, | ||
'properties' => $language, | ||
]; | ||
}, $languages); | ||
} | ||
|
||
/** | ||
* @param int $offset | ||
* @param string $langIso | ||
* | ||
* @return int | ||
*/ | ||
public function getRemainingObjectsCount($offset, $langIso) | ||
{ | ||
return (int) $this->languageRepository->getRemainingLanguagesCount($offset, $langIso); | ||
} | ||
|
||
/** | ||
* @param int $limit | ||
* @param string $langIso | ||
* @param array $objectIds | ||
* | ||
* @return array | ||
* | ||
* @throws \PrestaShopDatabaseException | ||
*/ | ||
public function getFormattedDataIncremental($limit, $langIso, $objectIds) | ||
{ | ||
$languages = $this->languageRepository->getLanguagesIncremental($limit, $langIso, $objectIds); | ||
|
||
if (!is_array($languages)) { | ||
return []; | ||
} | ||
$this->languageDecorator->decorateLanguages($languages); | ||
|
||
return array_map(function ($language) { | ||
return [ | ||
'id' => $language['id_lang'], | ||
'collection' => Config::COLLECTION_LANGUAGES, | ||
'properties' => $language, | ||
]; | ||
}, $languages); | ||
} | ||
} |
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
Oops, something went wrong.