|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / dev2.destoffenstraat.com / app / code / SR / Theme / Model / |
Filename | /home/dev2.destoffenstraat.com/app/code/SR/Theme/Model/ThemeRepository.php |
Size | 5.82 kb |
Permission | rwxrwxrwx |
Owner | root : root |
Create time | 17-Aug-2025 10:26 |
Last modified | 06-Apr-2021 18:06 |
Last accessed | 22-Aug-2025 06:06 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
namespace SR\Theme\Model;
use SR\Theme\Api\Data\ThemeInterfaceFactory;
use Magento\Framework\Exception\CouldNotDeleteException;
use SR\Theme\Model\ResourceModel\Theme as ResourceTheme;
use SR\Theme\Api\Data\ThemeSearchResultsInterfaceFactory;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\Reflection\DataObjectProcessor;
use SR\Theme\Api\ThemeRepositoryInterface;
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
use SR\Theme\Model\ResourceModel\Theme\CollectionFactory as ThemeCollectionFactory;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\Api\ExtensibleDataObjectConverter;
class ThemeRepository implements ThemeRepositoryInterface
{
protected $themeCollectionFactory;
protected $dataObjectHelper;
protected $dataThemeFactory;
protected $dataObjectProcessor;
protected $themeFactory;
protected $extensionAttributesJoinProcessor;
protected $resource;
private $collectionProcessor;
protected $searchResultsFactory;
protected $extensibleDataObjectConverter;
private $storeManager;
/**
* @param ResourceTheme $resource
* @param ThemeFactory $themeFactory
* @param ThemeInterfaceFactory $dataThemeFactory
* @param ThemeCollectionFactory $themeCollectionFactory
* @param ThemeSearchResultsInterfaceFactory $searchResultsFactory
* @param DataObjectHelper $dataObjectHelper
* @param DataObjectProcessor $dataObjectProcessor
* @param StoreManagerInterface $storeManager
* @param CollectionProcessorInterface $collectionProcessor
* @param JoinProcessorInterface $extensionAttributesJoinProcessor
* @param ExtensibleDataObjectConverter $extensibleDataObjectConverter
*/
public function __construct(
ResourceTheme $resource,
ThemeFactory $themeFactory,
ThemeInterfaceFactory $dataThemeFactory,
ThemeCollectionFactory $themeCollectionFactory,
ThemeSearchResultsInterfaceFactory $searchResultsFactory,
DataObjectHelper $dataObjectHelper,
DataObjectProcessor $dataObjectProcessor,
StoreManagerInterface $storeManager,
CollectionProcessorInterface $collectionProcessor,
JoinProcessorInterface $extensionAttributesJoinProcessor,
ExtensibleDataObjectConverter $extensibleDataObjectConverter
) {
$this->resource = $resource;
$this->themeFactory = $themeFactory;
$this->themeCollectionFactory = $themeCollectionFactory;
$this->searchResultsFactory = $searchResultsFactory;
$this->dataObjectHelper = $dataObjectHelper;
$this->dataThemeFactory = $dataThemeFactory;
$this->dataObjectProcessor = $dataObjectProcessor;
$this->storeManager = $storeManager;
$this->collectionProcessor = $collectionProcessor;
$this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
$this->extensibleDataObjectConverter = $extensibleDataObjectConverter;
}
/**
* {@inheritdoc}
*/
public function save(\SR\Theme\Api\Data\ThemeInterface $theme)
{
/* if (empty($theme->getStoreId())) {
$storeId = $this->storeManager->getStore()->getId();
$theme->setStoreId($storeId);
} */
$themeData = $this->extensibleDataObjectConverter->toNestedArray(
$theme,
[],
\SR\Theme\Api\Data\ThemeInterface::class
);
$themeModel = $this->themeFactory->create()->setData($themeData);
try {
$this->resource->save($themeModel);
} catch (\Exception $exception) {
throw new CouldNotSaveException(__(
'Could not save the theme: %1',
$exception->getMessage()
));
}
return $themeModel->getDataModel();
}
/**
* {@inheritdoc}
*/
public function getById($themeId)
{
$theme = $this->themeFactory->create();
$this->resource->load($theme, $themeId);
if (!$theme->getId()) {
throw new NoSuchEntityException(__('Theme with id "%1" does not exist.', $themeId));
}
return $theme->getDataModel();
}
/**
* {@inheritdoc}
*/
public function getList(
\Magento\Framework\Api\SearchCriteriaInterface $criteria
) {
$collection = $this->themeCollectionFactory->create();
$this->extensionAttributesJoinProcessor->process(
$collection,
\SR\Theme\Api\Data\ThemeInterface::class
);
$this->collectionProcessor->process($criteria, $collection);
$searchResults = $this->searchResultsFactory->create();
$searchResults->setSearchCriteria($criteria);
$items = [];
foreach ($collection as $model) {
$items[] = $model->getDataModel();
}
$searchResults->setItems($items);
$searchResults->setTotalCount($collection->getSize());
return $searchResults;
}
/**
* {@inheritdoc}
*/
public function delete(\SR\Theme\Api\Data\ThemeInterface $theme)
{
try {
$themeModel = $this->themeFactory->create();
$this->resource->load($themeModel, $theme->getThemeId());
$this->resource->delete($themeModel);
} catch (\Exception $exception) {
throw new CouldNotDeleteException(__(
'Could not delete the Theme: %1',
$exception->getMessage()
));
}
return true;
}
/**
* {@inheritdoc}
*/
public function deleteById($themeId)
{
return $this->delete($this->getById($themeId));
}
}
namespace SR\Theme\Model;
use SR\Theme\Api\Data\ThemeInterfaceFactory;
use Magento\Framework\Exception\CouldNotDeleteException;
use SR\Theme\Model\ResourceModel\Theme as ResourceTheme;
use SR\Theme\Api\Data\ThemeSearchResultsInterfaceFactory;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\Reflection\DataObjectProcessor;
use SR\Theme\Api\ThemeRepositoryInterface;
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
use SR\Theme\Model\ResourceModel\Theme\CollectionFactory as ThemeCollectionFactory;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\Api\ExtensibleDataObjectConverter;
class ThemeRepository implements ThemeRepositoryInterface
{
protected $themeCollectionFactory;
protected $dataObjectHelper;
protected $dataThemeFactory;
protected $dataObjectProcessor;
protected $themeFactory;
protected $extensionAttributesJoinProcessor;
protected $resource;
private $collectionProcessor;
protected $searchResultsFactory;
protected $extensibleDataObjectConverter;
private $storeManager;
/**
* @param ResourceTheme $resource
* @param ThemeFactory $themeFactory
* @param ThemeInterfaceFactory $dataThemeFactory
* @param ThemeCollectionFactory $themeCollectionFactory
* @param ThemeSearchResultsInterfaceFactory $searchResultsFactory
* @param DataObjectHelper $dataObjectHelper
* @param DataObjectProcessor $dataObjectProcessor
* @param StoreManagerInterface $storeManager
* @param CollectionProcessorInterface $collectionProcessor
* @param JoinProcessorInterface $extensionAttributesJoinProcessor
* @param ExtensibleDataObjectConverter $extensibleDataObjectConverter
*/
public function __construct(
ResourceTheme $resource,
ThemeFactory $themeFactory,
ThemeInterfaceFactory $dataThemeFactory,
ThemeCollectionFactory $themeCollectionFactory,
ThemeSearchResultsInterfaceFactory $searchResultsFactory,
DataObjectHelper $dataObjectHelper,
DataObjectProcessor $dataObjectProcessor,
StoreManagerInterface $storeManager,
CollectionProcessorInterface $collectionProcessor,
JoinProcessorInterface $extensionAttributesJoinProcessor,
ExtensibleDataObjectConverter $extensibleDataObjectConverter
) {
$this->resource = $resource;
$this->themeFactory = $themeFactory;
$this->themeCollectionFactory = $themeCollectionFactory;
$this->searchResultsFactory = $searchResultsFactory;
$this->dataObjectHelper = $dataObjectHelper;
$this->dataThemeFactory = $dataThemeFactory;
$this->dataObjectProcessor = $dataObjectProcessor;
$this->storeManager = $storeManager;
$this->collectionProcessor = $collectionProcessor;
$this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
$this->extensibleDataObjectConverter = $extensibleDataObjectConverter;
}
/**
* {@inheritdoc}
*/
public function save(\SR\Theme\Api\Data\ThemeInterface $theme)
{
/* if (empty($theme->getStoreId())) {
$storeId = $this->storeManager->getStore()->getId();
$theme->setStoreId($storeId);
} */
$themeData = $this->extensibleDataObjectConverter->toNestedArray(
$theme,
[],
\SR\Theme\Api\Data\ThemeInterface::class
);
$themeModel = $this->themeFactory->create()->setData($themeData);
try {
$this->resource->save($themeModel);
} catch (\Exception $exception) {
throw new CouldNotSaveException(__(
'Could not save the theme: %1',
$exception->getMessage()
));
}
return $themeModel->getDataModel();
}
/**
* {@inheritdoc}
*/
public function getById($themeId)
{
$theme = $this->themeFactory->create();
$this->resource->load($theme, $themeId);
if (!$theme->getId()) {
throw new NoSuchEntityException(__('Theme with id "%1" does not exist.', $themeId));
}
return $theme->getDataModel();
}
/**
* {@inheritdoc}
*/
public function getList(
\Magento\Framework\Api\SearchCriteriaInterface $criteria
) {
$collection = $this->themeCollectionFactory->create();
$this->extensionAttributesJoinProcessor->process(
$collection,
\SR\Theme\Api\Data\ThemeInterface::class
);
$this->collectionProcessor->process($criteria, $collection);
$searchResults = $this->searchResultsFactory->create();
$searchResults->setSearchCriteria($criteria);
$items = [];
foreach ($collection as $model) {
$items[] = $model->getDataModel();
}
$searchResults->setItems($items);
$searchResults->setTotalCount($collection->getSize());
return $searchResults;
}
/**
* {@inheritdoc}
*/
public function delete(\SR\Theme\Api\Data\ThemeInterface $theme)
{
try {
$themeModel = $this->themeFactory->create();
$this->resource->load($themeModel, $theme->getThemeId());
$this->resource->delete($themeModel);
} catch (\Exception $exception) {
throw new CouldNotDeleteException(__(
'Could not delete the Theme: %1',
$exception->getMessage()
));
}
return true;
}
/**
* {@inheritdoc}
*/
public function deleteById($themeId)
{
return $this->delete($this->getById($themeId));
}
}