Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
14.29% |
2 / 14 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ResourceIterator | |
14.29% |
2 / 14 |
|
50.00% |
1 / 2 |
14.08 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| loadResources | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
| 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) 2018 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\resources; |
| 23 | |
| 24 | use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService; |
| 25 | use oat\search\base\QueryInterface; |
| 26 | use Zend\ServiceManager\ServiceLocatorAwareTrait; |
| 27 | use Zend\ServiceManager\ServiceLocatorAwareInterface; |
| 28 | use core_kernel_classes_Resource; |
| 29 | use core_kernel_classes_Class; |
| 30 | |
| 31 | /** |
| 32 | * Class ResourceIterator |
| 33 | * @package oat\tao\model\search\index |
| 34 | * @author Aleh Hutnikau, <hutnikau@1pt.com> |
| 35 | */ |
| 36 | class ResourceIterator extends \core_kernel_classes_ResourceIterator implements ServiceLocatorAwareInterface |
| 37 | { |
| 38 | use ServiceLocatorAwareTrait; |
| 39 | |
| 40 | private $classessUsedInCriteria = []; |
| 41 | |
| 42 | /** @var QueryInterface */ |
| 43 | private $criteria; |
| 44 | |
| 45 | /** |
| 46 | * @inheritdoc |
| 47 | * @param array $criteria |
| 48 | */ |
| 49 | public function __construct($classes, QueryInterface $criteria = null) |
| 50 | { |
| 51 | parent::__construct($classes); |
| 52 | $this->criteria = $criteria; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Load resources from storage |
| 57 | * |
| 58 | * @param core_kernel_classes_Class $class |
| 59 | * @param integer $offset |
| 60 | * @return core_kernel_classes_Resource[] |
| 61 | */ |
| 62 | protected function loadResources(core_kernel_classes_Class $class, $offset) |
| 63 | { |
| 64 | $search = $this->getServiceLocator()->get(ComplexSearchService::SERVICE_ID); |
| 65 | $queryBuilder = $search->query()->setLimit(self::CACHE_SIZE)->setOffset($offset); |
| 66 | |
| 67 | $criteria = $search->searchType($queryBuilder, $class->getUri(), false); |
| 68 | if ($this->criteria !== null) { |
| 69 | foreach ($this->criteria->getStoredQueryCriteria() as $storedQueryCriterion) { |
| 70 | $criteria->addCriterion( |
| 71 | $storedQueryCriterion->getName(), |
| 72 | $storedQueryCriterion->getOperator(), |
| 73 | $storedQueryCriterion->getValue() |
| 74 | ); |
| 75 | } |
| 76 | } |
| 77 | $queryBuilder = $queryBuilder->setCriteria($criteria); |
| 78 | return $search->getGateway()->search($queryBuilder); |
| 79 | } |
| 80 | } |