-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.php
108 lines (90 loc) · 2.36 KB
/
User.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* Created by IntelliJ IDEA.
* User: Mattias Kågström
* Date: 2017-04-04
* Time: 11:19
*/
spl_autoload_register(function ($class_name) {
include $class_name . '.php';
});
class User
{
private $id, $name, $email, $devices = array(), $groups = array(), $authToken, $dateCreated, $applications = array();
function __construct($id, $name, $email, $authToken = null, $dateCreated = null)
{
$this->id = $id;
$this->name = $name;
$this->email = $email;
$this->authToken = $authToken;
$this->dateCreated = $dateCreated;
}
function __sleep()
{
return array("name", "email", "devices", "groups");
}
function __toString()
{
return json_encode($this->getObject());
}
function getObject(){
$user["id"] = $this->id;
$user["name"] = $this->name;
$user["email"] = $this->email;
$user["authToken"] = $this->authToken;
$user["dateCreated"] = $this->dateCreated;
$user["devices"] = $this->devices;
$user["groups"] = $this->groups;
$user["applications"] = $this->applications;
return $user;
}
/**
* @param $device Device
*/
public function addDevice(Device $device){
array_push($this->devices,$device->getObject());
}
/**
* @param $devices Device[]
*/
public function addDevices($devices){
for ($i = 0; $i < count($devices); $i++)
$this->addDevice($devices[$i]);
}
public function addGroup(Group $group){
array_push($this->groups, $group->getObject());
}
/**
* @param $devices Device[]
*/
public function addGroups($groups){
for ($i = 0; $i < count($groups); $i++)
$this->addGroup($groups[$i]);
}
public function addApplication(Application $application){
array_push($this->applications, $application->getObject());
}
/**
* @return array
*/
public function getApplications()
{
return $this->applications;
}
public function getName(){
return $this->name;
}
public function getEmail(){
return $this->email;
}
public function getDevices(){
return $this->devices;
}
public function getGroups(){
return $this->groups;
}
public function getId()
{
return $this->id;
}
}