resource = $resource; $this->slideFactory = $slideFactory; $this->slideCollectionFactory = $slideCollectionFactory; $this->searchResultsFactory = $searchResultsFactory; $this->dataObjectHelper = $dataObjectHelper; $this->dataSlideFactory = $dataSlideFactory; $this->dataObjectProcessor = $dataObjectProcessor; $this->storeManager = $storeManager; $this->collectionProcessor = $collectionProcessor; $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor; $this->extensibleDataObjectConverter = $extensibleDataObjectConverter; } /** * {@inheritdoc} */ public function save( SlideInterface $slide ) { /* if (empty($slide->getStoreId())) { $storeId = $this->storeManager->getStore()->getId(); $slide->setStoreId($storeId); } */ $slideData = $this->extensibleDataObjectConverter->toNestedArray( $slide, [], SlideInterface::class ); $slideModel = $this->slideFactory->create()->setData($slideData); try { $this->resource->save($slideModel); } catch (Exception $exception) { throw new CouldNotSaveException(__( 'Could not save the slide: %1', $exception->getMessage() )); } return $slideModel->getDataModel(); } /** * {@inheritdoc} */ public function getList( SearchCriteriaInterface $criteria ) { $collection = $this->slideCollectionFactory->create(); $this->extensionAttributesJoinProcessor->process( $collection, SlideInterface::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 deleteById($slideId) { return $this->delete($this->get($slideId)); } /** * {@inheritdoc} */ public function delete( SlideInterface $slide ) { try { $slideModel = $this->slideFactory->create(); $this->resource->load($slideModel, $slide->getSlideId()); $this->resource->delete($slideModel); } catch (Exception $exception) { throw new CouldNotDeleteException(__( 'Could not delete the Slide: %1', $exception->getMessage() )); } return true; } /** * {@inheritdoc} */ public function get($slideId) { $slide = $this->slideFactory->create(); $this->resource->load($slide, $slideId); if (!$slide->getId()) { throw new NoSuchEntityException(__('Slide with id "%1" does not exist.', $slideId)); } return $slide->getDataModel(); } }