Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
96.43% |
27 / 28 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| GenerisSearchBridge | |
96.43% |
27 / 28 |
|
75.00% |
3 / 4 |
11 | |
0.00% |
0 / 1 |
| withLocalNamespace | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| search | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
4 | |||
| isUriSearch | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| getLocalNamespace | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
3.33 | |||
| 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) 2020 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | namespace oat\tao\model\search; |
| 22 | |
| 23 | use oat\generis\model\OntologyAwareTrait; |
| 24 | use oat\oatbox\service\ConfigurableService; |
| 25 | |
| 26 | /** |
| 27 | * @deprecated User SearchProxy instead |
| 28 | */ |
| 29 | class GenerisSearchBridge extends ConfigurableService implements SearchBridgeInterface |
| 30 | { |
| 31 | use OntologyAwareTrait; |
| 32 | |
| 33 | /** @var string */ |
| 34 | private $localNamespace; |
| 35 | |
| 36 | public function withLocalNamespace(string $localNameSpace): self |
| 37 | { |
| 38 | $this->localNamespace = $localNameSpace; |
| 39 | |
| 40 | return $this; |
| 41 | } |
| 42 | |
| 43 | public function search(SearchQuery $query): ResultSet |
| 44 | { |
| 45 | if ($this->isUriSearch($query->getTerm())) { |
| 46 | $resource = $this->getResource($query->getTerm()); |
| 47 | $class = $this->getClass($query->getParentClass()); |
| 48 | |
| 49 | if ($resource->exists() && $resource->isInstanceOf($class)) { |
| 50 | return new ResultSet( |
| 51 | [ |
| 52 | [ |
| 53 | 'id' => $resource->getUri(), |
| 54 | 'label' => $resource->getLabel(), |
| 55 | ], |
| 56 | ], |
| 57 | 1 |
| 58 | ); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return $this->getServiceLocator()->get(Search::SERVICE_ID)->query( |
| 63 | $query->getTerm(), |
| 64 | $query->getParentClass(), |
| 65 | $query->getStartRow(), |
| 66 | $query->getRows() |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | private function isUriSearch(string $queryString): bool |
| 71 | { |
| 72 | $localNameSpace = $this->getLocalNamespace(); |
| 73 | |
| 74 | if (!empty($localNameSpace) && strpos($queryString, $localNameSpace) === 0) { |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | return filter_var($queryString, FILTER_VALIDATE_URL) !== false; |
| 79 | } |
| 80 | |
| 81 | private function getLocalNamespace(): ?string |
| 82 | { |
| 83 | return empty($this->localNamespace) && defined('LOCAL_NAMESPACE') |
| 84 | ? LOCAL_NAMESPACE |
| 85 | : $this->localNamespace; |
| 86 | } |
| 87 | } |