mageprince /
magento2-FAQ
| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * MagePrince |
||||
| 4 | * |
||||
| 5 | * NOTICE OF LICENSE |
||||
| 6 | * |
||||
| 7 | * This source file is subject to the mageprince.com license that is |
||||
| 8 | * available through the world-wide-web at this URL: |
||||
| 9 | * https://mageprince.com/end-user-license-agreement |
||||
| 10 | * |
||||
| 11 | * DISCLAIMER |
||||
| 12 | * |
||||
| 13 | * Do not edit or add to this file if you wish to upgrade this extension to newer |
||||
| 14 | * version in the future. |
||||
| 15 | * |
||||
| 16 | * @category MagePrince |
||||
| 17 | * @package Mageprince_Faq |
||||
| 18 | * @copyright Copyright (c) MagePrince (https://mageprince.com/) |
||||
| 19 | * @license https://mageprince.com/end-user-license-agreement |
||||
| 20 | */ |
||||
| 21 | |||||
| 22 | namespace Mageprince\Faq\Model; |
||||
| 23 | |||||
| 24 | use Mageprince\Faq\Api\Data\FaqGroupInterface; |
||||
| 25 | use Mageprince\Faq\Model\ResourceModel\FaqGroup as ResourceFaqGroup; |
||||
| 26 | use Magento\Framework\Exception\CouldNotSaveException; |
||||
|
0 ignored issues
–
show
|
|||||
| 27 | use Mageprince\Faq\Api\Data\FaqGroupSearchResultsInterfaceFactory; |
||||
|
0 ignored issues
–
show
The type
Mageprince\Faq\Api\Data\...ResultsInterfaceFactory was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 28 | use Mageprince\Faq\Model\ResourceModel\FaqGroup\CollectionFactory as FaqGroupCollectionFactory; |
||||
|
0 ignored issues
–
show
The type
Mageprince\Faq\Model\Res...Group\CollectionFactory was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 29 | use Magento\Framework\Exception\CouldNotDeleteException; |
||||
|
0 ignored issues
–
show
The type
Magento\Framework\Except...CouldNotDeleteException was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 30 | use Magento\Framework\Exception\NoSuchEntityException; |
||||
|
0 ignored issues
–
show
The type
Magento\Framework\Exception\NoSuchEntityException was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 31 | use Magento\Framework\Api\SortOrder; |
||||
|
0 ignored issues
–
show
The type
Magento\Framework\Api\SortOrder was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 32 | use Mageprince\Faq\Api\FaqGroupRepositoryInterface; |
||||
| 33 | |||||
| 34 | class FaqGroupRepository implements FaqGroupRepositoryInterface |
||||
| 35 | { |
||||
| 36 | /** |
||||
| 37 | * @var \Mageprince\Faq\Model\ResourceModel\FaqGroup |
||||
| 38 | */ |
||||
| 39 | protected $resource; |
||||
| 40 | |||||
| 41 | /** |
||||
| 42 | * @var \Mageprince\Faq\Api\Data\FaqGroupSearchResultsInterfaceFactory |
||||
| 43 | */ |
||||
| 44 | protected $searchResultsFactory; |
||||
| 45 | |||||
| 46 | /** |
||||
| 47 | * @var FaqGroupCollectionFactory |
||||
| 48 | */ |
||||
| 49 | protected $faqGroupCollectionFactory; |
||||
| 50 | |||||
| 51 | /** |
||||
| 52 | * @var FaqGroupFactory |
||||
|
0 ignored issues
–
show
The type
Mageprince\Faq\Model\FaqGroupFactory was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 53 | */ |
||||
| 54 | protected $faqGroupFactory; |
||||
| 55 | |||||
| 56 | /** |
||||
| 57 | * FaqGroupRepository constructor. |
||||
| 58 | * @param ResourceFaqGroup $resource |
||||
| 59 | * @param FaqGroupFactory $faqGroupFactory |
||||
| 60 | * @param FaqGroupCollectionFactory $faqGroupCollectionFactory |
||||
| 61 | * @param FaqGroupSearchResultsInterfaceFactory $searchResultsFactory |
||||
| 62 | */ |
||||
| 63 | public function __construct( |
||||
| 64 | ResourceFaqGroup $resource, |
||||
| 65 | FaqGroupFactory $faqGroupFactory, |
||||
| 66 | FaqGroupCollectionFactory $faqGroupCollectionFactory, |
||||
| 67 | FaqGroupSearchResultsInterfaceFactory $searchResultsFactory |
||||
| 68 | ) { |
||||
| 69 | $this->resource = $resource; |
||||
| 70 | $this->faqGroupFactory = $faqGroupFactory; |
||||
| 71 | $this->faqGroupCollectionFactory = $faqGroupCollectionFactory; |
||||
| 72 | $this->searchResultsFactory = $searchResultsFactory; |
||||
| 73 | } |
||||
| 74 | |||||
| 75 | /** |
||||
| 76 | * {@inheritdoc} |
||||
| 77 | */ |
||||
| 78 | public function save(FaqGroupInterface $faqGroup) |
||||
| 79 | { |
||||
| 80 | try { |
||||
| 81 | $this->resource->save($faqGroup); |
||||
| 82 | } catch (\Exception $exception) { |
||||
| 83 | throw new CouldNotSaveException(__( |
||||
|
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 84 | 'Could not save the faqGroup: %1', |
||||
| 85 | $exception->getMessage() |
||||
| 86 | )); |
||||
| 87 | } |
||||
| 88 | return $faqGroup; |
||||
| 89 | } |
||||
| 90 | |||||
| 91 | /** |
||||
| 92 | * {@inheritdoc} |
||||
| 93 | */ |
||||
| 94 | public function getById($faqGroupId) |
||||
| 95 | { |
||||
| 96 | $faqGroup = $this->faqGroupFactory->create(); |
||||
| 97 | $this->resource->load($faqGroup, $faqGroupId); |
||||
| 98 | if (!$faqGroup->getId()) { |
||||
| 99 | throw new NoSuchEntityException(__('FaqGroup with id "%1" does not exist.', $faqGroupId)); |
||||
|
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 100 | } |
||||
| 101 | return $faqGroup; |
||||
| 102 | } |
||||
| 103 | |||||
| 104 | /** |
||||
| 105 | * {@inheritdoc} |
||||
| 106 | */ |
||||
| 107 | public function getList( |
||||
| 108 | \Magento\Framework\Api\SearchCriteriaInterface $criteria |
||||
|
0 ignored issues
–
show
The type
Magento\Framework\Api\SearchCriteriaInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 109 | ) { |
||||
| 110 | $collection = $this->faqGroupCollectionFactory->create(); |
||||
| 111 | foreach ($criteria->getFilterGroups() as $filterGroup) { |
||||
| 112 | foreach ($filterGroup->getFilters() as $filter) { |
||||
| 113 | if ($filter->getField() === 'store_id') { |
||||
| 114 | $collection->addStoreFilter($filter->getValue(), false); |
||||
| 115 | continue; |
||||
| 116 | } |
||||
| 117 | $condition = $filter->getConditionType() ?: 'eq'; |
||||
| 118 | $collection->addFieldToFilter($filter->getField(), [$condition => $filter->getValue()]); |
||||
| 119 | } |
||||
| 120 | } |
||||
| 121 | |||||
| 122 | $sortOrders = $criteria->getSortOrders(); |
||||
| 123 | if ($sortOrders) { |
||||
| 124 | /** @var SortOrder $sortOrder */ |
||||
| 125 | foreach ($sortOrders as $sortOrder) { |
||||
| 126 | $collection->addOrder( |
||||
| 127 | $sortOrder->getField(), |
||||
| 128 | ($sortOrder->getDirection() == SortOrder::SORT_ASC) ? 'ASC' : 'DESC' |
||||
| 129 | ); |
||||
| 130 | } |
||||
| 131 | } |
||||
| 132 | $collection->setCurPage($criteria->getCurrentPage()); |
||||
| 133 | $collection->setPageSize($criteria->getPageSize()); |
||||
| 134 | |||||
| 135 | $searchResults = $this->searchResultsFactory->create(); |
||||
| 136 | $searchResults->setSearchCriteria($criteria); |
||||
| 137 | $searchResults->setTotalCount($collection->getSize()); |
||||
| 138 | $searchResults->setItems($collection->getItems()); |
||||
| 139 | return $searchResults; |
||||
| 140 | } |
||||
| 141 | |||||
| 142 | /** |
||||
| 143 | * {@inheritdoc} |
||||
| 144 | */ |
||||
| 145 | public function delete(FaqGroupInterface $faqGroup) |
||||
| 146 | { |
||||
| 147 | try { |
||||
| 148 | $this->resource->delete($faqGroup); |
||||
| 149 | } catch (\Exception $exception) { |
||||
| 150 | throw new CouldNotDeleteException(__( |
||||
|
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 151 | 'Could not delete the FaqGroup: %1', |
||||
| 152 | $exception->getMessage() |
||||
| 153 | )); |
||||
| 154 | } |
||||
| 155 | return true; |
||||
| 156 | } |
||||
| 157 | |||||
| 158 | /** |
||||
| 159 | * {@inheritdoc} |
||||
| 160 | */ |
||||
| 161 | public function deleteById($faqGroupId) |
||||
| 162 | { |
||||
| 163 | return $this->delete($this->getById($faqGroupId)); |
||||
| 164 | } |
||||
| 165 | } |
||||
| 166 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths