Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
90.91% |
10 / 11 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
IdDiscoverService | |
90.91% |
10 / 11 |
|
66.67% |
2 / 3 |
6.03 | |
0.00% |
0 / 1 |
withMediaResolver | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
discover | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
getMediaResolver | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 |
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\service; |
24 | |
25 | use oat\oatbox\service\ConfigurableService; |
26 | use oat\tao\model\media\TaoMediaResolver; |
27 | use oat\taoItems\model\media\ItemMediaResolver; |
28 | use oat\taoMediaManager\model\MediaSource; |
29 | use tao_helpers_Uri; |
30 | |
31 | class IdDiscoverService extends ConfigurableService |
32 | { |
33 | /** @var TaoMediaResolver */ |
34 | private $mediaResolver; |
35 | |
36 | public function withMediaResolver(TaoMediaResolver $mediaResolver): self |
37 | { |
38 | $this->mediaResolver = $mediaResolver; |
39 | |
40 | return $this; |
41 | } |
42 | |
43 | public function discover(array $fileReferences): array |
44 | { |
45 | $ids = []; |
46 | |
47 | foreach ($fileReferences as $reference) { |
48 | $mediaAsset = $this->getMediaResolver()->resolve($reference); |
49 | |
50 | if ($mediaAsset->getMediaSource() instanceof MediaSource) { |
51 | $ids[] = tao_helpers_Uri::decode($mediaAsset->getMediaIdentifier()); |
52 | } |
53 | } |
54 | |
55 | return $ids; |
56 | } |
57 | |
58 | private function getMediaResolver(): TaoMediaResolver |
59 | { |
60 | if (!$this->mediaResolver) { |
61 | $this->mediaResolver = new ItemMediaResolver('', null); |
62 | } |
63 | |
64 | return $this->mediaResolver; |
65 | } |
66 | } |