|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NotificationChannels\OneSignal; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Notifications\Notification; |
|
6
|
|
|
|
|
7
|
|
|
class OneSignalPayloadFactory |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Make a one signal notification payload. |
|
11
|
|
|
* |
|
12
|
|
|
* @param mixed $notifiable |
|
13
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
|
14
|
|
|
* @param mixed $targeting |
|
15
|
|
|
* |
|
16
|
|
|
* @return array |
|
17
|
|
|
*/ |
|
18
|
8 |
|
public static function make($notifiable, Notification $notification, $targeting): array |
|
19
|
|
|
{ |
|
20
|
8 |
|
$payload = $notification->toOneSignal($notifiable)->toArray(); |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
8 |
|
if (static::isTargetingEmail($targeting)) { |
|
23
|
1 |
|
$payload['filters'] = collect([['field' => 'email', 'value' => $targeting['email']]]); |
|
24
|
7 |
|
} elseif (static::isTargetingTags($targeting)) { |
|
25
|
2 |
|
$array = $targeting['tags']; |
|
26
|
2 |
|
$res = count($array) == count($array, COUNT_RECURSIVE); |
|
27
|
2 |
|
if ($res) { |
|
28
|
1 |
|
$payload['tags'] = collect([$targeting['tags']]); |
|
29
|
|
|
} else { |
|
30
|
2 |
|
$payload['tags'] = collect($targeting['tags']); |
|
31
|
|
|
} |
|
32
|
5 |
|
} elseif (static::isTargetingIncludedSegments($targeting)) { |
|
33
|
1 |
|
$payload['included_segments'] = collect($targeting['included_segments']); |
|
34
|
4 |
|
} elseif (static::isTargetingExcludedSegments($targeting)) { |
|
35
|
1 |
|
$payload['excluded_segments'] = collect($targeting['excluded_segments']); |
|
36
|
|
|
} else { |
|
37
|
3 |
|
$payload['include_player_ids'] = collect($targeting); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
8 |
|
return $payload; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param mixed $targeting |
|
45
|
|
|
* |
|
46
|
|
|
* @return bool |
|
47
|
|
|
*/ |
|
48
|
5 |
|
protected static function isTargetingIncludedSegments($targeting) |
|
49
|
|
|
{ |
|
50
|
5 |
|
return is_array($targeting) && array_key_exists('included_segments', $targeting); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param mixed $targeting |
|
55
|
|
|
* |
|
56
|
|
|
* @return bool |
|
57
|
|
|
*/ |
|
58
|
4 |
|
protected static function isTargetingExcludedSegments($targeting) |
|
59
|
|
|
{ |
|
60
|
4 |
|
return is_array($targeting) && array_key_exists('excluded_segments', $targeting); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param mixed $targeting |
|
65
|
|
|
* |
|
66
|
|
|
* @return bool |
|
67
|
|
|
*/ |
|
68
|
8 |
|
protected static function isTargetingEmail($targeting) |
|
69
|
|
|
{ |
|
70
|
8 |
|
return is_array($targeting) && array_key_exists('email', $targeting); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param mixed $targeting |
|
75
|
|
|
* |
|
76
|
|
|
* @return bool |
|
77
|
|
|
*/ |
|
78
|
7 |
|
protected static function isTargetingTags($targeting) |
|
79
|
|
|
{ |
|
80
|
7 |
|
return is_array($targeting) && array_key_exists('tags', $targeting); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.