Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       100.00%  | 
       18 / 18  | 
               | 
       100.00%  | 
       4 / 4  | 
       CRAP |         | 
       100.00%  | 
       1 / 1  | 
      
| DependentPropertiesRepository |         | 
       100.00%  | 
       18 / 18  | 
               | 
       100.00%  | 
       4 / 4  | 
       4 |         | 
       100.00%  | 
       1 / 1  | 
      
| findAll |         | 
       100.00%  | 
       1 / 1  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| findTotalChildren |         | 
       100.00%  | 
       1 / 1  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| executeSearch |         | 
       100.00%  | 
       15 / 15  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| getComplexSearchService |         | 
       100.00%  | 
       1 / 1  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| 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) 2021 (original work) Open Assessment Technologies SA; | 
| 19 | */ | 
| 20 | |
| 21 | declare(strict_types=1); | 
| 22 | |
| 23 | namespace oat\tao\model\Lists\DataAccess\Repository; | 
| 24 | |
| 25 | use core_kernel_classes_Property; | 
| 26 | use oat\generis\model\GenerisRdf; | 
| 27 | use oat\generis\model\OntologyRdf; | 
| 28 | use oat\oatbox\service\ConfigurableService; | 
| 29 | use oat\search\base\ResultSetInterface; | 
| 30 | use oat\tao\model\Context\ContextInterface; | 
| 31 | use oat\search\helper\SupportedOperatorHelper; | 
| 32 | use oat\tao\model\Lists\Business\Domain\DependentPropertiesRepositoryContext; | 
| 33 | use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService; | 
| 34 | use oat\tao\model\Lists\Business\Contract\DependentPropertiesRepositoryInterface; | 
| 35 | |
| 36 | class DependentPropertiesRepository extends ConfigurableService implements DependentPropertiesRepositoryInterface | 
| 37 | { | 
| 38 | /** | 
| 39 | * {@inheritdoc} | 
| 40 | */ | 
| 41 | public function findAll(ContextInterface $context): array | 
| 42 | { | 
| 43 | return iterator_to_array($this->executeSearch($context)); | 
| 44 | } | 
| 45 | |
| 46 | /** | 
| 47 | * {@inheritdoc} | 
| 48 | */ | 
| 49 | public function findTotalChildren(ContextInterface $context): int | 
| 50 | { | 
| 51 | return $this->executeSearch($context)->total(); | 
| 52 | } | 
| 53 | |
| 54 | /** | 
| 55 | * {@inheritdoc} | 
| 56 | */ | 
| 57 | private function executeSearch(ContextInterface $context): ResultSetInterface | 
| 58 | { | 
| 59 | /** @var core_kernel_classes_Property $property */ | 
| 60 | $property = $context->getParameter(DependentPropertiesRepositoryContext::PARAM_PROPERTY); | 
| 61 | |
| 62 | $search = $this->getComplexSearchService(); | 
| 63 | $dependentPropertiesQueryBuilder = $search->query(); | 
| 64 | $dependentPropertiesQuery = $search->searchType( | 
| 65 | $dependentPropertiesQueryBuilder, | 
| 66 | OntologyRdf::RDF_PROPERTY, | 
| 67 | true | 
| 68 | ); | 
| 69 | $dependentPropertiesQuery->addCriterion( | 
| 70 | GenerisRdf::PROPERTY_DEPENDS_ON_PROPERTY, | 
| 71 | SupportedOperatorHelper::EQUAL, | 
| 72 | $property->getUri() | 
| 73 | ); | 
| 74 | $dependentPropertiesQueryBuilder->setCriteria($dependentPropertiesQuery); | 
| 75 | |
| 76 | return $search->getGateway()->search($dependentPropertiesQueryBuilder); | 
| 77 | } | 
| 78 | |
| 79 | private function getComplexSearchService(): ComplexSearchService | 
| 80 | { | 
| 81 | return $this->getServiceLocator()->get(ComplexSearchService::SERVICE_ID); | 
| 82 | } | 
| 83 | } |