DeliveriesCreateParams.php
| 1 | <?php |
| 2 | |
| 3 | namespace WonderPush\Params; |
| 4 | |
| 5 | if (count(get_included_files()) === 1) { http_response_code(403); exit(); } // Prevent direct access |
| 6 | |
| 7 | use WonderPush\Obj\BaseObject; |
| 8 | |
| 9 | class DeliveriesCreateParams extends BaseObject { |
| 10 | |
| 11 | /** |
| 12 | * The endpoint of this API. |
| 13 | */ |
| 14 | const PATH = '/deliveries'; |
| 15 | |
| 16 | private $viewId; |
| 17 | private $campaignId; |
| 18 | private $targetType; |
| 19 | private $targetValues; |
| 20 | private $segmentParams; |
| 21 | private $notification; |
| 22 | private $notificationOverride; |
| 23 | private $notificationParams; |
| 24 | private $notificationId; |
| 25 | private $deliveryDate; |
| 26 | private $deliveryTime; |
| 27 | /** @var bool */ |
| 28 | private $inheritUrlParameters; |
| 29 | /** @var array|null */ |
| 30 | private $filterWebDomains; |
| 31 | private $deliverySource; |
| 32 | |
| 33 | /** |
| 34 | * @return string|null |
| 35 | */ |
| 36 | public function getDeliveryTime() { |
| 37 | return $this->deliveryTime; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @param string $deliveryTime |
| 42 | * @return DeliveriesCreateParams |
| 43 | */ |
| 44 | public function setDeliveryTime($deliveryTime) { |
| 45 | $this->deliveryTime = $deliveryTime; |
| 46 | return $this; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @return string|null |
| 51 | */ |
| 52 | public function getDeliveryDate() { |
| 53 | return $this->deliveryDate; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @param string $deliveryDate |
| 58 | * @return DeliveriesCreateParams |
| 59 | */ |
| 60 | public function setDeliveryDate($deliveryDate) { |
| 61 | $this->deliveryDate = $deliveryDate; |
| 62 | return $this; |
| 63 | } |
| 64 | |
| 65 | protected function buildDataFromFields() { |
| 66 | return (object) \WonderPush\Util\ArrayUtil::filterNulls(array( |
| 67 | 'viewId' => $this->viewId, |
| 68 | 'campaignId' => $this->campaignId, |
| 69 | $this->targetType => $this->targetValues, |
| 70 | 'segmentParams' => $this->segmentParams, |
| 71 | // With PHP 5.3.x, json_encode strips protected and private properties |
| 72 | // Transforming to array to avoid this |
| 73 | 'notification' => $this->notification ? (is_array($this->notification) ? $this->notification : (object)$this->notification->toArray()) : null, |
| 74 | 'notificationOverride' => $this->notificationOverride ? (is_array($this->notificationOverride) ? $this->notificationOverride : (object)$this->notificationOverride->toArray()) : null, |
| 75 | 'notificationParams' => $this->notificationParams, |
| 76 | 'notificationId' => $this->notificationId, |
| 77 | 'deliveryDate' => $this->deliveryDate ? $this->deliveryDate : null, |
| 78 | 'deliveryTime' => $this->deliveryTime ? $this->deliveryTime : null, |
| 79 | 'inheritUrlParameters' => (bool)$this->inheritUrlParameters, |
| 80 | 'filterWebDomains' => $this->filterWebDomains, |
| 81 | 'deliverySource' => $this->deliverySource, |
| 82 | )); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @param string $viewId |
| 87 | * @return $this |
| 88 | */ |
| 89 | public function setViewId($viewId) { |
| 90 | $this->viewId = $viewId; |
| 91 | return $this; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * @param string $campaignId |
| 96 | * @return $this |
| 97 | */ |
| 98 | public function setCampaignId($campaignId) { |
| 99 | $this->campaignId = $campaignId; |
| 100 | return $this; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * @param string|string[] $targetTag A single tag, an array of tags, or multiple tag parameters. |
| 105 | * @return $this |
| 106 | */ |
| 107 | public function setTargetTags($targetTag) { |
| 108 | $this->targetType = 'targetTags'; |
| 109 | $this->targetValues = \WonderPush\Util\ArrayUtil::flatten(func_get_args()); |
| 110 | return $this; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * @param string|string[] $segmentId A single id, an array of ids, or multiple id parameters. |
| 115 | * @return $this |
| 116 | */ |
| 117 | public function setTargetSegmentIds($segmentId) { |
| 118 | $this->targetType = 'targetSegmentIds'; |
| 119 | $this->targetValues = \WonderPush\Util\ArrayUtil::flatten(func_get_args()); |
| 120 | return $this; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @param int|int[] $segmentId A single id, an array of ids, or multiple id parameters. |
| 125 | * @return $this |
| 126 | */ |
| 127 | public function setTargetBrevoSegmentIds($segmentId) { |
| 128 | $this->targetType = 'targetBrevoSegmentIds'; |
| 129 | $this->targetValues = \WonderPush\Util\ArrayUtil::flatten(func_get_args()); |
| 130 | return $this; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * @param int|int[] $listId A single id, an array of ids, or multiple id parameters. |
| 135 | * @return $this |
| 136 | */ |
| 137 | public function setTargetBrevoListIds($segmentId) { |
| 138 | $this->targetType = 'targetBrevoListIds'; |
| 139 | $this->targetValues = \WonderPush\Util\ArrayUtil::flatten(func_get_args()); |
| 140 | return $this; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * @param array $segment A segment definition |
| 145 | * @return $this |
| 146 | */ |
| 147 | public function setTargetSegmentBody($segment) { |
| 148 | $this->targetType = 'targetSegmentBody'; |
| 149 | $this->targetValues = $segment; |
| 150 | return $this; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * @param string|string[] $userId A single id, an array of ids, or multiple id parameters. |
| 155 | * @return $this |
| 156 | */ |
| 157 | public function setTargetUserIds($userId) { |
| 158 | $this->targetType = 'targetUserIds'; |
| 159 | $this->targetValues = \WonderPush\Util\ArrayUtil::flatten(func_get_args()); |
| 160 | return $this; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * @param string|string[] $installationId A single id, an array of ids, or multiple id parameters. |
| 165 | * @return $this |
| 166 | */ |
| 167 | public function setTargetInstallationIds($installationId) { |
| 168 | $this->targetType = 'targetInstallationIds'; |
| 169 | $this->targetValues = \WonderPush\Util\ArrayUtil::flatten(func_get_args()); |
| 170 | return $this; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * @param string|string[] $deviceIds A single id, an array of ids, or multiple id parameters. |
| 175 | * @return $this |
| 176 | */ |
| 177 | public function setTargetDeviceIds($deviceIds) { |
| 178 | $this->targetType = 'targetDeviceIds'; |
| 179 | $this->targetValues = \WonderPush\Util\ArrayUtil::flatten(func_get_args()); |
| 180 | return $this; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * @param string|string[] $pushTokens A single token, an array of tokens, or multiple token parameters. |
| 185 | * @return $this |
| 186 | */ |
| 187 | public function setTargetPushTokens($pushTokens) { |
| 188 | $this->targetType = 'targetPushTokens'; |
| 189 | $this->targetValues = \WonderPush\Util\ArrayUtil::flatten(func_get_args()); |
| 190 | return $this; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * @param string|string[] $accessTokens A single token, an array of tokens, or multiple token parameters. |
| 195 | * @return $this |
| 196 | */ |
| 197 | public function setTargetAccessTokens($accessTokens) { |
| 198 | $this->targetType = 'targetAccessTokens'; |
| 199 | $this->targetValues = \WonderPush\Util\ArrayUtil::flatten(func_get_args()); |
| 200 | return $this; |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * @param array $segmentParams Segment parameters, or an array of those, one per targeted segment, in the same order. |
| 205 | * @return $this |
| 206 | */ |
| 207 | public function setSegmentParams($segmentParams) { |
| 208 | $this->segmentParams = $segmentParams; |
| 209 | return $this; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * @param string $notificationId |
| 214 | * @return $this |
| 215 | */ |
| 216 | public function setNotificationId($notificationId) { |
| 217 | $this->notificationId = $notificationId; |
| 218 | return $this; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * @param \WonderPush\Obj\Notification|array $notification |
| 223 | * @return $this |
| 224 | */ |
| 225 | public function setNotification($notification) { |
| 226 | $this->notification = $notification; |
| 227 | return $this; |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * @param \WonderPush\Obj\Notification|array $notificationOverride |
| 232 | * @return $this |
| 233 | */ |
| 234 | public function setNotificationOverride($notificationOverride) { |
| 235 | $this->notificationOverride = $notificationOverride; |
| 236 | return $this; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * @param array $notificationParams Notification parameters. |
| 241 | * @return $this |
| 242 | */ |
| 243 | public function setNotificationParams($notificationParams) { |
| 244 | $this->notificationParams = $notificationParams; |
| 245 | return $this; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * @return bool |
| 250 | */ |
| 251 | public function getInheritUrlParameters() { |
| 252 | return $this->inheritUrlParameters; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * @param bool $inheritUrlParameters |
| 257 | * @return DeliveriesCreateParams |
| 258 | */ |
| 259 | public function setInheritUrlParameters($inheritUrlParameters) { |
| 260 | $this->inheritUrlParameters = $inheritUrlParameters; |
| 261 | return $this; |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * @return string[]|null Returns the domains as a PHP array, or null if not set |
| 266 | */ |
| 267 | public function getFilterWebDomains() { |
| 268 | return is_array($this->filterWebDomains) ? $this->filterWebDomains : null; |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * @param string[]|null $domains |
| 273 | * @return DeliveriesCreateParams |
| 274 | */ |
| 275 | public function setFilterWebDomains($domains) { |
| 276 | $this->filterWebDomains = is_array($domains) && count($domains) > 0 ? $domains : null; |
| 277 | return $this; |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * @return string|null Returns the domains as a PHP array, or null if not set |
| 282 | */ |
| 283 | public function getDeliverySource() { |
| 284 | return $this->deliverySource; |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * @param string null $deliverySource |
| 289 | * @return DeliveriesCreateParams |
| 290 | */ |
| 291 | public function setDeliverySource($deliverySource) { |
| 292 | $this->deliverySource = $deliverySource ?: null; |
| 293 | return $this; |
| 294 | } |
| 295 | } |
| 296 |