From efa9d6d7a074b1bc5d4fc906c7ae66032a109993 Mon Sep 17 00:00:00 2001 From: Eduarda Lentz Rodrigues da Silva <e.lentzrodriguesdasilva@techdivision.com> Date: Fri, 17 Jan 2025 16:16:33 +0100 Subject: [PATCH] ZERO-162 Created repo and updated other files with right information --- Api/CmsBlockRepositoryInterface.php | 14 ++++++++ Model/Query/GetCmsBlockByIdentifier.php | 28 ++++++++++++++++ Model/Repository/CmsBlockRepository.php | 43 +++++++++++++++++++++++++ etc/di.xml | 6 ++++ 4 files changed, 91 insertions(+) create mode 100644 Api/CmsBlockRepositoryInterface.php create mode 100644 Model/Query/GetCmsBlockByIdentifier.php create mode 100644 Model/Repository/CmsBlockRepository.php diff --git a/Api/CmsBlockRepositoryInterface.php b/Api/CmsBlockRepositoryInterface.php new file mode 100644 index 0000000..8e98934 --- /dev/null +++ b/Api/CmsBlockRepositoryInterface.php @@ -0,0 +1,14 @@ +<?php +declare(strict_types=1); +namespace Firegento\ContentProvisioning\Api; + +interface CmsBlockRepositoryInterface +{ + /** + * Get CMS Block data by its identifier. + * + * @param string $identifier + * @return array + */ + public function getByIdentifier(string $identifier): array; +} \ No newline at end of file diff --git a/Model/Query/GetCmsBlockByIdentifier.php b/Model/Query/GetCmsBlockByIdentifier.php new file mode 100644 index 0000000..e5cba17 --- /dev/null +++ b/Model/Query/GetCmsBlockByIdentifier.php @@ -0,0 +1,28 @@ +<?php +declare(strict_types=1); +namespace Firegento\ContentProvisioning\Model\Query; + +use Magento\Framework\App\State; +use Firegento\ContentProvisioning\Api\CmsBlockRepositoryInterface; + +class GetCmsBlockByIdentifier +{ + private $cmsBlockRepository; + + public function __construct( + CmsBlockRepositoryInterface $cmsBlockRepository + ) { + $this->cmsBlockRepository = $cmsBlockRepository; + } + + protected function execute(string $key) + { + $blockData = $this->cmsBlockRepository->getByIdentifier($key); + + if (empty($blockData)) { + throw new NotFoundException(__('Block with key %1 not found.', $key)); + } + + return $blockData; + } +} \ No newline at end of file diff --git a/Model/Repository/CmsBlockRepository.php b/Model/Repository/CmsBlockRepository.php new file mode 100644 index 0000000..fcd249d --- /dev/null +++ b/Model/Repository/CmsBlockRepository.php @@ -0,0 +1,43 @@ +<?php +declare(strict_types=1); +namespace Firegento\ContentProvisioning\Model\Repository; + +use Firegento\ContentProvisioning\Api\CmsBlockRepositoryInterface; +use Magento\Framework\App\ResourceConnection; + +class CmsBlockRepository implements CmsBlockRepositoryInterface +{ + /** + * @var ResourceConnection + */ + private $resource; + + /** + * CmsBlockRepository constructor. + * + * @param ResourceConnection $resource + */ + public function __construct( + ResourceConnection $resource + ) { + $this->resource = $resource; + } + + /** + * Get CMS Block data by its identifier. + * + * @param string $identifier + * @return array + */ + public function getByIdentifier(string $identifier): array + { + $connection = $this->resource->getConnection(); + $tableName = $this->resource->getTableName('cms_block'); // Get table with prefix + + $sql = "SELECT * FROM $tableName WHERE identifier = :identifier"; + $bind = ['identifier' => $identifier]; + + $result = $connection->fetchRow($sql, $bind); // Fetch a single row + return $result ? $result : []; + } +} \ No newline at end of file diff --git a/etc/di.xml b/etc/di.xml index cea4de4..d3e79e8 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -148,4 +148,10 @@ </argument> </arguments> </type> + <type name="Firegento\ContentProvisioning\Api\CmsBlockRepositoryInterface"> + <arguments> + <argument name="resource" xsi:type="object">Magento\Framework\App\ResourceConnection</argument> + </arguments> + </type> + <preference for="Firegento\ContentProvisioning\Api\CmsBlockRepositoryInterface" type="Firegento\ContentProvisioning\Model\Repository\CmsBlockRepository" /> </config> -- GitLab