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 Magento\Framework\Api\SortOrder; |
||||
0 ignored issues
–
show
|
|||||
25 | 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 ![]() |
|||||
26 | use Magento\Framework\Exception\CouldNotSaveException; |
||||
0 ignored issues
–
show
The type
Magento\Framework\Exception\CouldNotSaveException 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 ![]() |
|||||
27 | 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 ![]() |
|||||
28 | use Mageprince\Faq\Api\Data\FaqInterface; |
||||
29 | use Mageprince\Faq\Api\Data\FaqSearchResultsInterfaceFactory; |
||||
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 ![]() |
|||||
30 | use Mageprince\Faq\Api\FaqRepositoryInterface; |
||||
31 | use Mageprince\Faq\Model\ResourceModel\Faq as ResourceFaq; |
||||
32 | use Mageprince\Faq\Model\ResourceModel\Faq\CollectionFactory as FaqCollectionFactory; |
||||
0 ignored issues
–
show
The type
Mageprince\Faq\Model\Res...l\Faq\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 ![]() |
|||||
33 | |||||
34 | class FaqRepository implements FaqRepositoryInterface |
||||
35 | { |
||||
36 | /** |
||||
37 | * @var \Mageprince\Faq\Model\ResourceModel\Faq |
||||
38 | */ |
||||
39 | protected $resource; |
||||
40 | |||||
41 | /** |
||||
42 | * @var \Mageprince\Faq\Api\Data\FaqSearchResultsInterfaceFactory |
||||
43 | */ |
||||
44 | protected $searchResultsFactory; |
||||
45 | |||||
46 | /** |
||||
47 | * @var FaqCollectionFactory |
||||
48 | */ |
||||
49 | protected $faqCollectionFactory; |
||||
50 | |||||
51 | /** |
||||
52 | * @var FaqFactory |
||||
0 ignored issues
–
show
The type
Mageprince\Faq\Model\FaqFactory 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 ![]() |
|||||
53 | */ |
||||
54 | protected $faqFactory; |
||||
55 | |||||
56 | /** |
||||
57 | * FaqRepository constructor. |
||||
58 | * @param ResourceFaq $resource |
||||
59 | * @param FaqFactory $faqFactory |
||||
60 | * @param FaqCollectionFactory $faqCollectionFactory |
||||
61 | * @param FaqSearchResultsInterfaceFactory $searchResultsFactory |
||||
62 | */ |
||||
63 | public function __construct( |
||||
64 | ResourceFaq $resource, |
||||
65 | FaqFactory $faqFactory, |
||||
66 | FaqCollectionFactory $faqCollectionFactory, |
||||
67 | FaqSearchResultsInterfaceFactory $searchResultsFactory |
||||
68 | ) { |
||||
69 | $this->resource = $resource; |
||||
70 | $this->faqFactory = $faqFactory; |
||||
71 | $this->faqCollectionFactory = $faqCollectionFactory; |
||||
72 | $this->searchResultsFactory = $searchResultsFactory; |
||||
73 | } |
||||
74 | |||||
75 | /** |
||||
76 | * {@inheritdoc} |
||||
77 | */ |
||||
78 | public function save(FaqInterface $faq) |
||||
79 | { |
||||
80 | try { |
||||
81 | $this->resource->save($faq); |
||||
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
![]() |
|||||
84 | 'Could not save the faq: %1', |
||||
85 | $exception->getMessage() |
||||
86 | )); |
||||
87 | } |
||||
88 | return $faq; |
||||
89 | } |
||||
90 | |||||
91 | /** |
||||
92 | * {@inheritdoc} |
||||
93 | */ |
||||
94 | public function getById($faqId) |
||||
95 | { |
||||
96 | $faq = $this->faqFactory->create(); |
||||
97 | $faq->getResource()->load($faq, $faqId); |
||||
98 | if (!$faq->getId()) { |
||||
99 | throw new NoSuchEntityException(__('Faq with id "%1" does not exist.', $faqId)); |
||||
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
![]() |
|||||
100 | } |
||||
101 | return $faq; |
||||
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 ![]() |
|||||
109 | ) { |
||||
110 | $collection = $this->faqCollectionFactory->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(FaqInterface $faq) |
||||
146 | { |
||||
147 | try { |
||||
148 | $this->resource->delete($faq); |
||||
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
![]() |
|||||
151 | 'Could not delete the Faq: %1', |
||||
152 | $exception->getMessage() |
||||
153 | )); |
||||
154 | } |
||||
155 | return true; |
||||
156 | } |
||||
157 | |||||
158 | /** |
||||
159 | * {@inheritdoc} |
||||
160 | */ |
||||
161 | public function deleteById($faqId) |
||||
162 | { |
||||
163 | return $this->delete($this->getById($faqId)); |
||||
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