Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
ResourceDeleted
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
6 / 6
8
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setSelectedClass
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setParentClass
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 jsonSerialize
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
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
21declare(strict_types=1);
22
23namespace oat\generis\model\data\event;
24
25use JsonSerializable;
26use oat\oatbox\event\Event;
27use core_kernel_classes_Class;
28use core_kernel_classes_Resource;
29
30class 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
41    /**
42     * @param string $uri
43     */
44    public function __construct($uri)
45    {
46        $this->uri = $uri;
47    }
48
49    public function getId(): string
50    {
51        return $this->uri;
52    }
53
54    /**
55     * {@inheritdoc}
56     */
57    public function getName()
58    {
59        return __CLASS__;
60    }
61
62    public function setSelectedClass(?core_kernel_classes_Class $class): self
63    {
64        $this->selectedClass = $class;
65
66        return $this;
67    }
68
69    public function setParentClass(?core_kernel_classes_Class $class): self
70    {
71        $this->parentClass = $class;
72
73        return $this;
74    }
75
76    public function jsonSerialize(): array
77    {
78        $data = [
79            'uri' => $this->uri,
80        ];
81
82        if ($this->selectedClass !== null) {
83            $data['selectedClass'] = [
84                'uri' => $this->selectedClass->getUri(),
85                'label' => $this->selectedClass->getLabel(),
86            ];
87        }
88
89        if ($this->parentClass !== null) {
90            $data['parentClass'] = [
91                'uri' => $this->parentClass->getUri(),
92                'label' => $this->parentClass->getLabel(),
93            ];
94        }
95
96        return $data;
97    }
98}