User::getCreated()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace GorkaLaucirica\HipchatAPIv2Client\Model;
4
5
class User
6
{
7
    protected $xmppJid;
8
9
    protected $deleted;
10
11
    protected $name;
12
13
    protected $lastActive;
14
15
    protected $title;
16
17
    protected $links;
18
19
    //protected $presence;
20
21
    protected $created;
22
23
    protected $id;
24
25
    protected $mentionName;
26
27
    protected $groupAdmin;
28
29
    protected $timezone;
30
31
    protected $guest;
32
33
    protected $email;
34
35
    protected $photoUrl;
36
37
    /**
38
     * Builds a user object from server response if json given, otherwise creates an empty object
39
     * Works with partial and full user information.
40
     *
41
     * @param array $json json_decoded response in json given by the server
42
     * 
43
     */
44
    public function __construct($json = null)
45
    {
46
        if ($json) {
47
            $this->parseJson($json);
48
        } else {
49
            $this->groupAdmin = false;
50
            $this->timezone = 'UTC';
51
        }
52
    }
53
54
    /**
55
     * Parses response given by the API and maps the fields to User object
56
     *
57
     * @param array $json json_decoded response in json given by the server
58
     *
59
     * @return void
60
     */
61
    public function parseJson($json)
62
    {
63
        $this->mentionName = $json['mention_name'];
64
        $this->id = $json['id'];
65
        $this->name = $json['name'];
66
        if (isset($json['links'])) {
67
            $this->links = $json['links'];
68
        }
69
        if(isset($json['xmpp_jid'])) {
70
            $this->xmppJid = $json['xmpp_jid'];
71
            $this->deleted = $json['is_deleted'];
72
            $this->lastActive = $json['last_active'];
73
            $this->title = $json['title'];
74
            $this->created = new \Datetime($json['created']);
75
            $this->groupAdmin = $json['is_group_admin'];
76
            $this->timezone = $json['timezone'];
77
            $this->guest = $json['is_guest'];
78
            $this->email = $json['email'];
79
            $this->photoUrl = $json['photo_url'];
80
        }
81
    }
82
83
    public function toJson()
84
    {
85
        $json = array();
86
        $json['name'] = $this->name;
87
        $json['title'] = $this->title;
88
        $json['mention_name'] = $this->mentionName;
89
        $json['is_group_admin'] = $this->groupAdmin;
90
        $json['timezone'] = $this->timezone;
91
        $json['email'] = $this->email;
92
93
        return $json;
94
    }
95
96
    /**
97
     * Sets XMPP/Jabber ID of the user.
98
     *
99
     * @param string $xmppJid XMPP/Jabber ID of the user
100
     *
101
     * @return self
102
     */
103
    public function setXmppJid($xmppJid)
104
    {
105
        $this->xmppJid = $xmppJid;
106
        return $this;
107
    }
108
109
    /**
110
     * Returns XMPP/Jabber ID of the user.
111
     *
112
     * @return string
113
     */
114
    public function getXmppJid()
115
    {
116
        return $this->xmppJid;
117
    }
118
119
    /**
120
     * Sets whether the user has been deleted or not
121
     *
122
     * @param boolean $deleted Whether the user has been deleted or not
123
     *
124
     * @return self
125
     */
126
    public function setDeleted($deleted)
127
    {
128
        $this->deleted = $deleted;
129
        return $this;
130
    }
131
132
    /**
133
     * Returns whether the user has been deleted or not
134
     *
135
     * @return boolean
136
     */
137
    public function isDeleted()
138
    {
139
        return $this->deleted;
140
    }
141
142
    /**
143
     * Sets user's full name
144
     *
145
     * @param string $name User's full name
146
     *
147
     * @return self
148
     */
149
    public function setName($name)
150
    {
151
        $this->name = $name;
152
        return $this;
153
    }
154
155
    /**
156
     * Returns user's full name
157
     *
158
     * @return string
159
     */
160
    public function getName()
161
    {
162
        return $this->name;
163
    }
164
165
    /**
166
     * Sets when the user was last active
167
     *
168
     * @param \Datetime $lastActive When the user was last active
169
     *
170
     * @return self
171
     */
172
    public function setLastActive($lastActive)
173
    {
174
        $this->lastActive = $lastActive;
175
        return $this;
176
    }
177
178
    /**
179
     * Returns when the user was last active
180
     *
181
     * @return \Datetime
182
     */
183
    public function getLastActive()
184
    {
185
        return $this->lastActive;
186
    }
187
188
    /**
189
     * Sets user's title
190
     *
191
     * @param mixed $title User's title
192
     *
193
     * @return self
194
     */
195
    public function setTitle($title)
196
    {
197
        $this->title = $title;
198
        return $this;
199
    }
200
201
    /**
202
     * Returns user's title
203
     *
204
     * @return mixed
205
     */
206
    public function getTitle()
207
    {
208
        return $this->title;
209
    }
210
211
    /**
212
     * Sets when the user was created
213
     *
214
     * @param \Datetime $created When the user was created
215
     *
216
     * @return self
217
     */
218
    public function setCreated($created)
219
    {
220
        $this->created = $created;
221
        return $this;
222
    }
223
224
    /**
225
     * Returns when the user was created
226
     *
227
     * @return \Datetime
228
     */
229
    public function getCreated()
230
    {
231
        return $this->created;
232
    }
233
234
    /**
235
     * Sets user's ID
236
     *
237
     * @param mixed $id User's ID
238
     *
239
     * @return self
240
     */
241
    public function setId($id)
242
    {
243
        $this->id = $id;
244
        return $this;
245
    }
246
247
    /**
248
     * Returns user's ID
249
     *
250
     * @return mixed
251
     */
252
    public function getId()
253
    {
254
        return $this->id;
255
    }
256
257
    /**
258
     * Sets user's @mention name
259
     *
260
     * @param mixed $mentionName User's @mention name
261
     *
262
     * @return self
263
     */
264
    public function setMentionName($mentionName)
265
    {
266
        $this->mentionName = $mentionName;
267
        return $this;
268
    }
269
270
    /**
271
     * Returns user's @mention name
272
     *
273
     * @return mixed
274
     */
275
    public function getMentionName()
276
    {
277
        return $this->mentionName;
278
    }
279
280
    /**
281
     * Sets whether or not this user is an admin of the group
282
     *
283
     * @param boolean $groupAdmin Whether or not this user is an admin of the group
284
     *
285
     * @return self
286
     */
287
    public function setGroupAdmin($groupAdmin)
288
    {
289
        $this->groupAdmin = $groupAdmin;
290
        return $this;
291
    }
292
293
    /**
294
     * Returns whether or not this user is an admin of the group
295
     *
296
     * @return boolean
297
     */
298
    public function isGroupAdmin()
299
    {
300
        return $this->groupAdmin;
301
    }
302
303
    /**
304
     * Sets the desired user timezone
305
     *
306
     * @param string $timezone The desired user timezone
307
     *
308
     * @return self
309
     */
310
    public function setTimezone($timezone)
311
    {
312
        $this->timezone = $timezone;
313
        return $this;
314
    }
315
316
    /**
317
     * Returns the desired user timezone
318
     *
319
     * @return mixed
320
     */
321
    public function getTimezone()
322
    {
323
        return $this->timezone;
324
    }
325
326
    /**
327
     * Sets whether or not this user is a guest or registered user
328
     *
329
     * @param boolean $guest Whether or not this user is a guest or registered user
330
     *
331
     * @return self
332
     */
333
    public function setGuest($guest)
334
    {
335
        $this->guest = $guest;
336
        return $this;
337
    }
338
339
    /**
340
     * Returns whether or not this user is a guest or registered user
341
     *
342
     * @return boolean
343
     */
344
    public function isGuest()
345
    {
346
        return $this->guest;
347
    }
348
349
    /**
350
     * Sets user's email
351
     *
352
     * @param string $email User's email
353
     *
354
     * @return self
355
     */
356
    public function setEmail($email)
357
    {
358
        $this->email = $email;
359
        return $this;
360
    }
361
362
    /**
363
     * Returns user's email
364
     *
365
     * @return string
366
     */
367
    public function getEmail()
368
    {
369
        return $this->email;
370
    }
371
372
    /**
373
     * Sets URL to user's photo.
374
     *
375
     * @param string $photoUrl URL to user's photo
376
     *
377
     * @return self
378
     */
379
    public function setPhotoUrl($photoUrl)
380
    {
381
        $this->photoUrl = $photoUrl;
382
        return $this;
383
    }
384
385
    /**
386
     * Returns URL to user's photo. 125px on the longest side
387
     *
388
     * @return string
389
     */
390
    public function getPhotoUrl()
391
    {
392
        return $this->photoUrl;
393
    }
394
}
395