Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
94.12% |
16 / 17 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| PropertyRepository | |
94.12% |
16 / 17 |
|
66.67% |
2 / 3 |
4.00 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| findBy | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
2 | |||
| delete | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2022 (original work) Open Assessment Technologies SA. |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\generis\model\resource\Repository; |
| 24 | |
| 25 | use BadMethodCallException; |
| 26 | use oat\generis\model\GenerisRdf; |
| 27 | use oat\generis\model\OntologyRdf; |
| 28 | use oat\search\helper\SupportedOperatorHelper; |
| 29 | use oat\generis\model\Context\ContextInterface; |
| 30 | use oat\generis\model\resource\Context\PropertyRepositoryContext; |
| 31 | use oat\generis\model\resource\Contract\ResourceRepositoryInterface; |
| 32 | use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService; |
| 33 | |
| 34 | class PropertyRepository implements ResourceRepositoryInterface |
| 35 | { |
| 36 | /** @var ComplexSearchService */ |
| 37 | private $complexSearch; |
| 38 | |
| 39 | public function __construct(ComplexSearchService $complexSearch) |
| 40 | { |
| 41 | $this->complexSearch = $complexSearch; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * {@inheritdoc} |
| 46 | */ |
| 47 | public function findBy(ContextInterface $context): array |
| 48 | { |
| 49 | $queryBuilder = $this->complexSearch->query(); |
| 50 | |
| 51 | $query = $this->complexSearch->searchType($queryBuilder, OntologyRdf::RDF_PROPERTY, true); |
| 52 | $query->addCriterion( |
| 53 | OntologyRdf::RDF_TYPE, |
| 54 | SupportedOperatorHelper::EQUAL, |
| 55 | OntologyRdf::RDF_PROPERTY |
| 56 | ); |
| 57 | |
| 58 | if ($context->hasParameter(PropertyRepositoryContext::PARAM_ALIASES)) { |
| 59 | $query->addCriterion( |
| 60 | GenerisRdf::PROPERTY_ALIAS, |
| 61 | SupportedOperatorHelper::IN, |
| 62 | $context->getParameter(PropertyRepositoryContext::PARAM_ALIASES, []) |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | $queryBuilder->setCriteria($query); |
| 67 | |
| 68 | return iterator_to_array($this->complexSearch->getGateway()->search($queryBuilder)); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * {@inheritdoc} |
| 73 | */ |
| 74 | public function delete(ContextInterface $context): void |
| 75 | { |
| 76 | throw new BadMethodCallException(sprintf('Method %s not implemented.', __METHOD__)); |
| 77 | } |
| 78 | } |