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)); } }