init
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Webinar\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
|
||||
class Webinar extends AbstractDb
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('webinar_request', 'entity_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Webinar\Model\ResourceModel\Webinar;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
|
||||
|
||||
class Collection extends AbstractCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected $_idFieldName = 'entity_id';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(
|
||||
\Stemcell\Webinar\Model\Webinar::class,
|
||||
\Stemcell\Webinar\Model\ResourceModel\Webinar::class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Webinar\Model;
|
||||
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\Data\Collection\AbstractDb;
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
use Magento\Framework\Model\Context;
|
||||
use Magento\Framework\Model\ResourceModel\AbstractResource;
|
||||
use Magento\Framework\Registry;
|
||||
use Stemcell\Webinar\Api\Data\WebinarInterface;
|
||||
|
||||
class Webinar extends AbstractModel implements WebinarInterface
|
||||
{
|
||||
protected Session $customerSession;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Registry $registry,
|
||||
Session $customerSession,
|
||||
AbstractResource $resource = null,
|
||||
AbstractDb $resourceCollection = null,
|
||||
array $data = []
|
||||
) {
|
||||
$this->customerSession = $customerSession;
|
||||
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function _construct(): void
|
||||
{
|
||||
$this->_init(\Stemcell\Webinar\Model\ResourceModel\Webinar::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->getData(self::EMAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setEmail($email)
|
||||
{
|
||||
return $this->setData(self::EMAIL, $email);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCustomerId(int $customerId)
|
||||
{
|
||||
return $this->setData(self::CUSTOMER_ID, $this->customerSession->getCustomerId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCustomerId(): ?int
|
||||
{
|
||||
return $this->getData(self::CUSTOMER_ID);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setName(string $name)
|
||||
{
|
||||
return $this->setData(self::NAME, $name);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->getData(self::NAME);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setMobile(string $mobile)
|
||||
{
|
||||
return $this->setData(self::MOBILE, $mobile);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getMobile()
|
||||
{
|
||||
return $this->getData(self::MOBILE);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCompany(string $company)
|
||||
{
|
||||
return $this->setData(self::COMPANY, $company);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCompany()
|
||||
{
|
||||
return $this->getData(self::COMPANY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setTitle(string $title)
|
||||
{
|
||||
return $this->setData(self::TITLE, $title);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->getData(self::TITLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setState(string $state)
|
||||
{
|
||||
return $this->setData(self::STATE, $state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getState()
|
||||
{
|
||||
return $this->getData(self::STATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCity(string $city)
|
||||
{
|
||||
return $this->setData(self::CITY, $city);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCity()
|
||||
{
|
||||
return $this->getData(self::CITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setStreet(string $street)
|
||||
{
|
||||
return $this->setData(self::STREET, $street);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getStreet()
|
||||
{
|
||||
return $this->getData(self::STREET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setZip(string $zip)
|
||||
{
|
||||
return $this->setData(self::ZIP, $zip);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getZip()
|
||||
{
|
||||
return $this->getData(self::ZIP);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setFrom(string $from)
|
||||
{
|
||||
return $this->setData(self::FROM, $from);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getFrom()
|
||||
{
|
||||
return $this->getData(self::FROM);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setRemark(string $remark)
|
||||
{
|
||||
return $this->setData(self::REMARK, $remark);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getRemark()
|
||||
{
|
||||
return $this->getData(self::REMARK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Webinar\Model;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
|
||||
use Magento\Framework\Exception\CouldNotDeleteException;
|
||||
use Magento\Framework\Exception\CouldNotSaveException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Stemcell\Webinar\Api\Data\WebinarInterface;
|
||||
use Stemcell\Webinar\Api\Data\WebinarInterfaceFactory;
|
||||
use Stemcell\Webinar\Api\Data\WebinarSearchResultsInterfaceFactory;
|
||||
use Stemcell\Webinar\Api\WebinarRepositoryInterface;
|
||||
use Stemcell\Webinar\Model\ResourceModel\Webinar as ResourceWebinar;
|
||||
use Stemcell\Webinar\Model\ResourceModel\Webinar\CollectionFactory as WebinarCollectionFactory;
|
||||
|
||||
class WebinarRepository implements WebinarRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var WebinarCollectionFactory
|
||||
*/
|
||||
protected $webinarCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var WebinarInterfaceFactory
|
||||
*/
|
||||
protected $webinarFactory;
|
||||
|
||||
/**
|
||||
* @var CollectionProcessorInterface
|
||||
*/
|
||||
protected $collectionProcessor;
|
||||
|
||||
/**
|
||||
* @var ResourceWebinar
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var Webinar
|
||||
*/
|
||||
protected $searchResultsFactory;
|
||||
|
||||
|
||||
/**
|
||||
* @param ResourceWebinar $resource
|
||||
* @param WebinarInterfaceFactory $webinarFactory
|
||||
* @param WebinarCollectionFactory $webinarCollectionFactory
|
||||
* @param WebinarSearchResultsInterfaceFactory $searchResultsFactory
|
||||
* @param CollectionProcessorInterface $collectionProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
ResourceWebinar $resource,
|
||||
WebinarInterfaceFactory $webinarFactory,
|
||||
WebinarCollectionFactory $webinarCollectionFactory,
|
||||
WebinarSearchResultsInterfaceFactory $searchResultsFactory,
|
||||
CollectionProcessorInterface $collectionProcessor
|
||||
) {
|
||||
$this->resource = $resource;
|
||||
$this->webinarFactory = $webinarFactory;
|
||||
$this->webinarCollectionFactory = $webinarCollectionFactory;
|
||||
$this->searchResultsFactory = $searchResultsFactory;
|
||||
$this->collectionProcessor = $collectionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function save(WebinarInterface $webinar)
|
||||
{
|
||||
try {
|
||||
$this->resource->save($webinar);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotSaveException(__(
|
||||
'Could not save the webinar: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return $webinar;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $field
|
||||
* @return WebinarInterface
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
public function get($value, $field)
|
||||
{
|
||||
$webinar = $this->webinarFactory->create();
|
||||
$this->resource->load($webinar, $value, $field);
|
||||
if (!$webinar->getId()) {
|
||||
throw new NoSuchEntityException(__('Webinar with %1 "%2" does not exist.', $field, $value));
|
||||
}
|
||||
return $webinar;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getList(
|
||||
\Magento\Framework\Api\SearchCriteriaInterface $criteria
|
||||
) {
|
||||
$collection = $this->webinarCollectionFactory->create();
|
||||
|
||||
$this->collectionProcessor->process($criteria, $collection);
|
||||
|
||||
$searchResults = $this->searchResultsFactory->create();
|
||||
$searchResults->setSearchCriteria($criteria);
|
||||
|
||||
$items = [];
|
||||
foreach ($collection as $model) {
|
||||
$items[] = $model;
|
||||
}
|
||||
|
||||
$searchResults->setItems($items);
|
||||
$searchResults->setTotalCount($collection->getSize());
|
||||
return $searchResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(WebinarInterface $webinar)
|
||||
{
|
||||
try {
|
||||
$webinarModel = $this->webinarFactory->create();
|
||||
$this->resource->load($webinarModel, $webinar->getWebinarId());
|
||||
$this->resource->delete($webinarModel);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotDeleteException(__(
|
||||
'Could not delete the Webinar: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deleteById($webinarId)
|
||||
{
|
||||
return $this->delete($this->get($webinarId));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user