Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
core_kernel_persistence_starsql_StarIterator
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 4
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 hasChildren
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 current
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getChildren
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
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) 2023 (original work) Open Assessment Technologies SA
19 *
20 */
21
22use oat\generis\model\data\Model;
23use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService;
24use oat\generis\model\kernel\persistence\starsql\FlatRecursiveIterator;
25
26/**
27 * Iterator over all triples
28 *
29 */
30class core_kernel_persistence_starsql_StarIterator extends \IteratorIterator implements \RecursiveIterator
31{
32    public function __construct(Model $model)
33    {
34        /** @var ComplexSearchService $search */
35        $search = $model->getSearchInterface();
36        $query = $search->query();
37
38        $queryOptions = $query->getOptions();
39        $queryOptions['system_only'] = true;
40        $query->setOptions($queryOptions);
41
42        parent::__construct($search->getGateway()->search($query));
43    }
44
45    public function hasChildren()
46    {
47        return true;
48    }
49
50    public function current()
51    {
52        $current = parent::current();
53
54        if ($current instanceof \core_kernel_classes_Literal) {
55            $current = new \core_kernel_classes_Resource($current->literal);
56        }
57
58        return $current;
59    }
60
61
62    public function getChildren()
63    {
64        /** @var \core_kernel_classes_Resource $currentResource */
65        $currentResource = $this->current();
66
67        return new FlatRecursiveIterator($currentResource->getRdfTriples());
68    }
69}