Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/OneSignalClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function sendNotificationToUser($message, $userId, $url = null, $data = n
$params = array(
'app_id' => $this->appId,
'contents' => $contents,
'include_player_ids' => is_array($userId) ? $userId : array($userId)
'include_player_ids' => $this->transformUserId($userId)
);

if (isset($url)) {
Expand All @@ -171,7 +171,7 @@ public function sendNotificationToUser($message, $userId, $url = null, $data = n
"en" => $headings
);
}

if(isset($subtitle)){
$params['subtitle'] = array(
"en" => $subtitle
Expand Down Expand Up @@ -199,7 +199,7 @@ public function sendNotificationToExternalUser($message, $userId, $url = null, $
$params = array(
'app_id' => $this->appId,
'contents' => $contents,
'include_external_user_ids' => is_array($userId) ? $userId : array($userId)
'include_external_user_ids' => $this->transformUserId($userId)
);

if (isset($url)) {
Expand Down Expand Up @@ -264,7 +264,7 @@ public function sendNotificationUsingTags($message, $tags, $url = null, $data =
"en" => $headings
);
}

if(isset($subtitle)){
$params['subtitle'] = array(
"en" => $subtitle
Expand Down Expand Up @@ -306,7 +306,7 @@ public function sendNotificationToAll($message, $url = null, $data = null, $butt
"en" => $headings
);
}

if(isset($subtitle)){
$params['subtitle'] = array(
"en" => $subtitle
Expand Down Expand Up @@ -348,7 +348,7 @@ public function sendNotificationToSegment($message, $segment, $url = null, $data
"en" => $headings
);
}

if(isset($subtitle)){
$params['subtitle'] = array(
"en" => $subtitle
Expand Down Expand Up @@ -415,7 +415,7 @@ public function getNotifications($app_id = null, $limit = null, $offset = null)
$this->usesJSON();

$endpoint = self::ENDPOINT_NOTIFICATIONS;

if(!$app_id) {
$app_id = $this->appId;
}
Expand Down Expand Up @@ -531,4 +531,19 @@ public function delete($endPoint) {
}
return $this->client->delete(self::API_URL . $endPoint, $this->headers);
}

/**
* Transformed user_id as array string.
*
* @param mixed $userId
* @return array
*/
private function transformUserId($userId)
{
$array = is_array($userId) ? $userId : array($userId);

return array_map(function ($item) {
return (string)$item;
}, $array);
}
}