Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| QueryFactory | |
0.00% |
0 / 6 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| createFindAllQueryByRequest | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| getMediaRelationRepository | |
0.00% |
0 / 1 |
|
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) 2020 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoMediaManager\model\relation\factory; |
| 24 | |
| 25 | use InvalidArgumentException; |
| 26 | use oat\oatbox\service\ConfigurableService; |
| 27 | use oat\taoMediaManager\model\relation\repository\MediaRelationRepositoryInterface; |
| 28 | use oat\taoMediaManager\model\relation\repository\query\FindAllQuery; |
| 29 | use Psr\Http\Message\ServerRequestInterface; |
| 30 | |
| 31 | class QueryFactory extends ConfigurableService |
| 32 | { |
| 33 | private const SOURCE_ID = 'sourceId'; |
| 34 | private const CLASS_ID = 'classId'; |
| 35 | |
| 36 | public function createFindAllQueryByRequest(ServerRequestInterface $request): FindAllQuery |
| 37 | { |
| 38 | $sourceId = $request->getQueryParams()[self::SOURCE_ID] ?? null; |
| 39 | $classId = $request->getQueryParams()[self::CLASS_ID] ?? null; |
| 40 | |
| 41 | if ($sourceId === null && $classId === null) { |
| 42 | throw new InvalidArgumentException('Parameter sourceId or classId must be provided'); |
| 43 | } |
| 44 | |
| 45 | return new FindAllQuery($sourceId, $classId); |
| 46 | } |
| 47 | |
| 48 | private function getMediaRelationRepository(): MediaRelationRepositoryInterface |
| 49 | { |
| 50 | return $this->getServiceLocator()->get(MediaRelationRepositoryInterface::SERVICE_ID); |
| 51 | } |
| 52 | } |