Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
95.65% |
22 / 23 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
SharedStimulusInstanceData | |
95.65% |
22 / 23 |
|
66.67% |
2 / 3 |
4 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
fromResource | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
getOneProperty | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
2.01 |
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) 2022 (original work) Open Assessment Technologies SA. |
19 | */ |
20 | |
21 | declare(strict_types=1); |
22 | |
23 | namespace oat\taoMediaManager\model\sharedStimulus\dto; |
24 | |
25 | use oat\generis\model\OntologyRdfs; |
26 | use oat\taoMediaManager\model\TaoMediaOntology; |
27 | use core_kernel_classes_Resource; |
28 | use core_kernel_classes_Property; |
29 | |
30 | class SharedStimulusInstanceData |
31 | { |
32 | /** @var string */ |
33 | public $resourceUri; |
34 | |
35 | /** @var ?string */ |
36 | public $label; |
37 | |
38 | /** @var ?string */ |
39 | public $link; |
40 | |
41 | /** @var ?string */ |
42 | public $language; |
43 | |
44 | /** @var ?string */ |
45 | public $md5; |
46 | |
47 | /** @var ?string */ |
48 | public $mimeType; |
49 | |
50 | /** @var ?string */ |
51 | public $altText; |
52 | |
53 | public function __construct( |
54 | string $resourceUri, |
55 | ?string $label, |
56 | ?string $link, |
57 | ?string $language, |
58 | ?string $md5, |
59 | ?string $mimeType, |
60 | ?string $altText |
61 | ) { |
62 | $this->resourceUri = $resourceUri; |
63 | $this->label = $label; |
64 | $this->link = $link; |
65 | $this->language = $language; |
66 | $this->md5 = $md5; |
67 | $this->mimeType = $mimeType; |
68 | $this->altText = $altText; |
69 | } |
70 | |
71 | public static function fromResource( |
72 | core_kernel_classes_Resource $resource, |
73 | string $dataLanguage |
74 | ): self { |
75 | return new SharedStimulusInstanceData( |
76 | $resource->getUri(), |
77 | self::getOneProperty($resource, OntologyRdfs::RDFS_LABEL, $dataLanguage), |
78 | self::getOneProperty($resource, TaoMediaOntology::PROPERTY_LINK, $dataLanguage), |
79 | self::getOneProperty($resource, TaoMediaOntology::PROPERTY_LANGUAGE, $dataLanguage), |
80 | self::getOneProperty($resource, TaoMediaOntology::PROPERTY_MD5, $dataLanguage), |
81 | self::getOneProperty($resource, TaoMediaOntology::PROPERTY_MIME_TYPE, $dataLanguage), |
82 | self::getOneProperty($resource, TaoMediaOntology::PROPERTY_ALT_TEXT, $dataLanguage) |
83 | ); |
84 | } |
85 | |
86 | private static function getOneProperty( |
87 | core_kernel_classes_Resource $resource, |
88 | string $propertyUri, |
89 | string $dataLanguage |
90 | ): ?string { |
91 | $value = $resource->getPropertyValuesByLg( |
92 | new core_kernel_classes_Property($propertyUri), |
93 | $dataLanguage |
94 | ); |
95 | |
96 | if ($value->isEmpty()) { |
97 | return null; |
98 | } |
99 | |
100 | return (string) $value->get(0); |
101 | } |
102 | } |