Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
95.83% |
23 / 24 |
|
87.50% |
7 / 8 |
CRAP | |
0.00% |
0 / 1 |
ResourceDeleted | |
95.83% |
23 / 24 |
|
87.50% |
7 / 8 |
10 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setSelectedClass | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
setParentClass | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
setResourceType | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getResourceType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
jsonSerialize | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
3 |
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) 2018-2021 (original work) Open Assessment Technologies SA. |
19 | */ |
20 | |
21 | declare(strict_types=1); |
22 | |
23 | namespace oat\generis\model\data\event; |
24 | |
25 | use JsonSerializable; |
26 | use oat\oatbox\event\Event; |
27 | use core_kernel_classes_Class; |
28 | use core_kernel_classes_Resource; |
29 | |
30 | class ResourceDeleted implements Event, JsonSerializable |
31 | { |
32 | /** @var string */ |
33 | private $uri; |
34 | |
35 | /** @var core_kernel_classes_Class|null */ |
36 | private $selectedClass; |
37 | |
38 | /** @var core_kernel_classes_Resource|null */ |
39 | private $parentClass; |
40 | private string $resourceType; |
41 | |
42 | /** |
43 | * @param string $uri |
44 | */ |
45 | public function __construct($uri) |
46 | { |
47 | $this->uri = $uri; |
48 | } |
49 | |
50 | public function getId(): string |
51 | { |
52 | return $this->uri; |
53 | } |
54 | |
55 | /** |
56 | * {@inheritdoc} |
57 | */ |
58 | public function getName() |
59 | { |
60 | return __CLASS__; |
61 | } |
62 | |
63 | public function setSelectedClass(?core_kernel_classes_Class $class): self |
64 | { |
65 | $this->selectedClass = $class; |
66 | |
67 | return $this; |
68 | } |
69 | |
70 | public function setParentClass(?core_kernel_classes_Class $class): self |
71 | { |
72 | $this->parentClass = $class; |
73 | |
74 | return $this; |
75 | } |
76 | |
77 | public function setResourceType(string $resourceType): self |
78 | { |
79 | $this->resourceType = $resourceType; |
80 | |
81 | return $this; |
82 | } |
83 | |
84 | public function getResourceType(): string |
85 | { |
86 | return $this->resourceType; |
87 | } |
88 | |
89 | public function jsonSerialize(): array |
90 | { |
91 | $data = [ |
92 | 'uri' => $this->uri, |
93 | ]; |
94 | |
95 | if ($this->selectedClass !== null) { |
96 | $data['selectedClass'] = [ |
97 | 'uri' => $this->selectedClass->getUri(), |
98 | 'label' => $this->selectedClass->getLabel(), |
99 | ]; |
100 | } |
101 | |
102 | if ($this->parentClass !== null) { |
103 | $data['parentClass'] = [ |
104 | 'uri' => $this->parentClass->getUri(), |
105 | 'label' => $this->parentClass->getLabel(), |
106 | ]; |
107 | } |
108 | |
109 | return $data; |
110 | } |
111 | } |