Skip to content
Snippets Groups Projects
CmsBlockRepository.php 1.12 KiB
Newer Older
<?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 : [];
    }
}