b374k
m1n1 1.01
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 / Geissweb / Euvat / Model /
Filename/home/dev2.destoffenstraat.com/app/code/Geissweb/Euvat/Model/ValidationRepository.php
Size6.6 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified09-Jul-2024 08:39
Last accessed21-Aug-2025 12:29
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
/**
* ||GEISSWEB| EU VAT Enhanced
*
* NOTICE OF LICENSE
*
* This source file is subject to the GEISSWEB End User License Agreement
* that is available through the world-wide-web at this URL: https://www.geissweb.de/legal-information/eula
*
* DISCLAIMER
*
* Do not edit this file if you wish to update the extension in the future. If you wish to customize the extension
* for your needs please refer to our support for more information.
*
* @copyright Copyright (c) 2015 GEISS Weblösungen (https://www.geissweb.de)
* @license https://www.geissweb.de/legal-information/eula GEISSWEB End User License Agreement
*/
declare(strict_types=1);

namespace Geissweb\Euvat\Model;

use Geissweb\Euvat\Api\Data\ValidationInterface;
use Geissweb\Euvat\Api\Data\ValidationInterfaceFactory;
use Geissweb\Euvat\Api\Data\ValidationSearchResultsInterfaceFactory;
use Geissweb\Euvat\Api\ValidationRepositoryInterface;
use Geissweb\Euvat\Model\ResourceModel\Validation as ResourceValidation;
use Geissweb\Euvat\Model\ResourceModel\Validation\CollectionFactory as ValidationCollectionFactory;

use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Api\SearchResults;
use Magento\Framework\Reflection\DataObjectProcessor;
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;

use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\CouldNotDeleteException;
use Magento\Framework\Exception\NoSuchEntityException;

/**
* Class ValidationRepository
* Repository for VAT number validation results (database represendation)
*/
class ValidationRepository implements ValidationRepositoryInterface
{
protected DataObjectHelper $dataObjectHelper;
protected ValidationSearchResultsInterfaceFactory $searchResultsFactory;
protected ValidationFactory $validationFactory;
protected ValidationCollectionFactory $validationCollectionFactory;
protected ResourceValidation $resource;
protected DataObjectProcessor $dataObjectProcessor;
protected ValidationInterfaceFactory $dataValidationFactory;
private CollectionProcessorInterface $collectionProcessor;

/**
* @param ResourceValidation $resource
* @param ValidationFactory $validationFactory
* @param ValidationInterfaceFactory $dataValidationFactory
* @param ValidationCollectionFactory $validationCollectionFactory
* @param ValidationSearchResultsInterfaceFactory $searchResultsFactory
* @param DataObjectHelper $dataObjectHelper
* @param DataObjectProcessor $dataObjectProcessor
* @param \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface $collectionProcessor
*/
public function __construct(
ResourceValidation $resource,
ValidationFactory $validationFactory,
ValidationInterfaceFactory $dataValidationFactory,
ValidationCollectionFactory $validationCollectionFactory,
ValidationSearchResultsInterfaceFactory $searchResultsFactory,
DataObjectHelper $dataObjectHelper,
DataObjectProcessor $dataObjectProcessor,
CollectionProcessorInterface $collectionProcessor
) {
$this->resource = $resource;
$this->validationFactory = $validationFactory;
$this->validationCollectionFactory = $validationCollectionFactory;
$this->searchResultsFactory = $searchResultsFactory;
$this->dataObjectHelper = $dataObjectHelper;
$this->dataValidationFactory = $dataValidationFactory;
$this->dataObjectProcessor = $dataObjectProcessor;
$this->collectionProcessor = $collectionProcessor;
}

/**
* @inheritDoc
*/
public function get(int $validationId) : ValidationInterface
{
$validation = $this->validationFactory->create();
$this->resource->load($validation, $validationId);
if (!$validation->getId()) {
throw new NoSuchEntityException(__('Validation with id "%1" does not exist.', $validationId));
}
return $validation;
}

/**
* Get existing validation data
*
* @param null|string $vatId
*
* @return bool|ValidationInterface
*/
public function getByVatId(?string $vatId)
{
if ($vatId === null || $vatId === '') {
return false;
}
$validation = $this->validationFactory->create();
$this->resource->load($validation, $vatId, 'vat_id');
if (!$validation->getId()) {
return false;
}
return $validation;
}

/**
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
*
* @return \Magento\Framework\Api\SearchResults
*/
public function getList(
SearchCriteriaInterface $searchCriteria
): SearchResults {
$collection = $this->validationCollectionFactory->create();
$this->collectionProcessor->process($searchCriteria, $collection);

/** @var \Magento\Framework\Api\SearchResults $searchResults */
$searchResults = $this->searchResultsFactory->create();
$searchResults->setSearchCriteria($searchCriteria);

$items = [];
foreach ($collection as $model) {
$items[] = $model;
}

$searchResults->setItems($items);
$searchResults->setTotalCount($collection->getSize());
return $searchResults;
}

/**
* @param \Geissweb\Euvat\Api\Data\ValidationInterface $validation
* @return \Geissweb\Euvat\Api\Data\ValidationInterface
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
public function save(
ValidationInterface $validation
) : ValidationInterface {
try {
/** @var Validation $validation */
$this->resource->save($validation);
} catch (\Exception $exception) {
throw new CouldNotSaveException(__(
'Could not save the validation: %1',
$exception->getMessage()
));
}
return $validation;
}

/**
* @inheritdoc
*/
public function delete(
ValidationInterface $validation
) : bool {
try {
/** @var ValidationInterface|\Magento\Framework\Model\AbstractModel $validation */
$this->resource->delete($validation);
} catch (\Exception $exception) {
throw new CouldNotDeleteException(__(
'Could not delete the Validation: %1',
$exception->getMessage()
));
}
return true;
}

/**
* @inheritdoc
*/
public function deleteById(int $validationId) : bool
{
return $this->delete($this->get($validationId));
}
}