Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| PropertySerializer | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| buildReturn | |
0.00% |
0 / 16 |
|
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) 2023 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\generis\model\kernel\persistence\starsql\search; |
| 23 | |
| 24 | use Laudis\Neo4j\Databags\Statement; |
| 25 | use oat\generis\model\data\ModelManager; |
| 26 | use WikibaseSolutions\CypherDSL\Expressions\Procedures\Procedure; |
| 27 | use WikibaseSolutions\CypherDSL\Patterns\Node; |
| 28 | use WikibaseSolutions\CypherDSL\Query; |
| 29 | |
| 30 | class PropertySerializer extends QuerySerializer |
| 31 | { |
| 32 | private string $propertyUri; |
| 33 | private bool $isDistinct = false; |
| 34 | |
| 35 | public function __construct(string $propertyUri, bool $isDistinct = false) |
| 36 | { |
| 37 | $this->propertyUri = $propertyUri; |
| 38 | $this->isDistinct = $isDistinct; |
| 39 | } |
| 40 | |
| 41 | protected function buildReturn(Node $subject): void |
| 42 | { |
| 43 | $property = $this->propertyUri; |
| 44 | $returnProperty = ModelManager::getModel()->getProperty($property); |
| 45 | |
| 46 | $predicate = $subject->property($property); |
| 47 | if ($returnProperty->isLgDependent()) { |
| 48 | $predicate = $this->buildLanguagePattern($predicate); |
| 49 | } |
| 50 | |
| 51 | $predicate = Procedure::raw('toStringOrNull', $predicate); |
| 52 | if ($this->isDistinct) { |
| 53 | $predicate = Query::rawExpression(sprintf('DISTINCT %s', $predicate->toQuery())); |
| 54 | $this->returnStatements = [ |
| 55 | $predicate->alias('object') |
| 56 | ]; |
| 57 | } else { |
| 58 | $this->returnStatements = [ |
| 59 | Procedure::raw('elementId', $subject)->alias('id'), |
| 60 | $subject->property('uri')->alias('uri'), |
| 61 | $predicate->alias('object') |
| 62 | ]; |
| 63 | } |
| 64 | } |
| 65 | } |