Completed
Pull Request — master (#30)
by nonanerz
06:00
created

DtoEvent::getEnd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
ccs 0
cts 4
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace AppBundle\Entity\DTO;
4
5
use AppBundle\Entity\User;
6
use Symfony\Component\Validator\Constraints as Assert;
7
8
class DtoEvent implements \JsonSerializable
9
{
10
    /**
11
     * @Assert\NotBlank()
12
     */
13
    private $user;
14
15
    private $summary;
16
17
    private $description;
18
19
    private $location;
20
21
    /**
22
     * @Assert\NotBlank()
23
     */
24
    private $start;
25
26
    /**
27
     * @Assert\NotBlank()
28
     */
29
    private $end;
30
31
    private $googleEventId;
32
33
    public function __construct(\Google_Service_Calendar_Event $event = null)
34
    {
35
        if ($event && $event instanceof \Google_Service_Calendar_Event) {
36
            $this->summary = $event->getSummary();
37
            $this->description = $event->getDescription();
38
            $this->summary = $event->getSummary();
39
            $this->location = $event->getLocation();
40
            $this->start = $event->getStart();
41
            $this->end = $event->getEnd();
42
            $this->googleEventId = $event->getId();
43
        }
44
    }
45
46
    public function jsonSerialize()
47
    {
48
        $description = json_decode($this->description, true);
49
        $users = [];
50
        foreach ($description['user'] as $user) {
51
            $users[] = $user;
52
        }
53
        return [
54
            'user' => $users,
55
            'title' => $this->summary,
56
            'description' => $description['description'],
57
            'location' => $this->location,
58
            'start' => $this->start->dateTime,
59
            'end' => $this->end->dateTime,
60
            'id' => $this->googleEventId,
61
        ];
62
    }
63
64
    /**
65
     * @return mixed
66
     */
67
    public function getSummary()
68
    {
69
        return $this->summary;
70
    }
71
72
    /**
73
     * @param mixed $summary
74
     */
75
    public function setSummary($summary)
76
    {
77
        $this->summary = $summary;
78
    }
79
80
    /**
81
     * @return mixed
82
     */
83
    public function getDescription()
84
    {
85
        return $this->description;
86
    }
87
88
    /**
89
     * @param mixed $description
90
     */
91
    public function setDescription($description)
92
    {
93
        $this->description = $description;
94
    }
95
96
    /**
97
     * @return mixed
98
     */
99
    public function getLocation()
100
    {
101
        return $this->location;
102
    }
103
104
    /**
105
     * @param mixed $location
106
     */
107
    public function setLocation($location)
108
    {
109
        $this->location = $location;
110
    }
111
112
    /**
113
     * @return mixed
114
     */
115
    public function getStart()
116
    {
117
        return $this->start;
118
    }
119
120
    /**
121
     * @param mixed $start
122
     */
123
    public function setStart($start)
124
    {
125
        $this->start = $start;
126
    }
127
128
    /**
129
     * @return mixed
130
     */
131
    public function getEnd()
132
    {
133
        return $this->end;
134
    }
135
136
    /**
137
     * @param mixed $end
138
     */
139
    public function setEnd($end)
140
    {
141
        $this->end = $end;
142
    }
143
144
    /**
145
     * @return User
146
     */
147
    public function getUser()
148
    {
149
        return $this->user;
150
    }
151
152
    /**
153
     * @param User $user
154
     *
155
     * @return $this
156
     */
157
    public function setUser($user)
158
    {
159
        $this->user = $user;
160
161
        return $this;
162
    }
163
164
    /**
165
     * @return mixed
166
     */
167
    public function getGoogleEventId()
168
    {
169
        return $this->googleEventId;
170
    }
171
172
    /**
173
     * @param mixed $googleEventId
174
     *
175
     * @return $this
176
     */
177
    public function setGoogleEventId($googleEventId)
178
    {
179
        $this->googleEventId = $googleEventId;
180
181
        return $this;
182
    }
183
}
184