forked from Furgas/php-api-library
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkyNewsSubscriber.php
executable file
·183 lines (161 loc) · 3.99 KB
/
kyNewsSubscriber.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
/**
* Kayako NewsSubscriber object.
*
* @author Tomasz Sawicki (https://github.com/Furgas)
* @link http://wiki.kayako.com/display/DEV/REST+-+NewsSubscriber
* @since Kayako version 4.51.1891
* @package Object\News
*
* @noinspection PhpDocSignatureInspection
*/
class kyNewsSubscriber extends kyObjectBase {
static protected $controller = '/News/Subscriber';
static protected $object_xml_name = 'newssubscriber';
/**
* News subscriber identifier.
* @apiField
* @var int
*/
protected $id;
/**
* Template group identifier of this news subscriber.
* @apiField name=tgroupid
* @var int
*/
protected $template_group_id;
/**
* User identifier of this news subscriber.
* @apiField
* @var int
*/
protected $user_id;
/**
* News subscriber e-mail.
* @apiField required=true
* @var string
*/
protected $email;
/**
* Whether the email is validated.
* @apiField
* @var bool
*/
protected $is_validated;
/**
* User group identifier of this news subscriber.
* @apiField
* @var int
*/
protected $user_group_id;
protected function parseData($data) {
$this->id = ky_assure_positive_int($data['id']);
$this->template_group_id = ky_assure_positive_int($data['tgroupid']);
$this->user_id = ky_assure_positive_int($data['userid']);
$this->email = ky_assure_string($data['email']);
$this->is_validated = ky_assure_bool($data['isvalidated']);
$this->user_group_id = ky_assure_positive_int($data['usergroupid']);
}
public function buildData($create) {
$this->checkRequiredAPIFields($create);
$data = array();
$this->buildDataString($data, 'email', $this->email);
if ($create) {
//this field works different than other bool fields (http://dev.kayako.com/browse/SWIFT-3141)
if ($this->is_validated) {
$this->buildDataBool($data, 'isvalidated', $this->is_validated);
}
}
return $data;
}
public function toString() {
return sprintf("%s (%svalidated)", $this->getEmail(), $this->getIsValidated() ? "" : "not ");
}
public function getId($complete = false) {
return $complete ? array($this->id) : $this->id;
}
/**
* Returns template group identifier of the news subscriber.
*
* @return int
* @filterBy
* @orderBy
*/
public function getTemplateGroupId() {
return $this->template_group_id;
}
/**
* Returns user identifier of the news subscriber.
*
* @return int
* @filterBy
* @orderBy
*/
public function getUserId() {
return $this->user_id;
}
/**
* Returns email of the news subscriber.
*
* @return string
* @filterBy
* @orderBy
*/
public function getEmail() {
return $this->email;
}
/**
* Sets email of the news subscriber.
*
* @param string $email Email of the news subscriber.
* @return kyNewsSubscriber
*/
public function setEmail($email) {
$this->email = ky_assure_string($email);
return $this;
}
/**
* Returns whether the news subscriber's email is validated.
*
* @return bool
* @filterBy
* @orderBy
*/
public function getIsValidated() {
return $this->is_validated;
}
/**
* Sets whether the news subscriber's email is validated.
*
* @param bool $is_validated Whether the news subscriber's email is validated.
* @return kyNewsSubscriber
*/
public function setIsValidated($is_validated) {
$this->is_validated = $is_validated;
return $this;
}
/**
* Returns user group identifier of the news subscriber.
*
* @return int
* @filterBy
* @orderBy
*/
public function getUserGroupId() {
return $this->user_group_id;
}
/**
* Creates a news subscriber.
* WARNING: Data is not sent to Kayako unless you explicitly call create() on this method's result.
*
* @param string $email Email of news subscriber.
* @param bool $is_validated Whether email address is validated.
* @return kyNewsSubscriber
*/
static public function createNew($email, $is_validated = false) {
$new_news_subscriber = new kyNewsSubscriber();
$new_news_subscriber->setEmail($email);
$new_news_subscriber->setIsValidated($is_validated);
return $new_news_subscriber;
}
}