Created
June 28, 2018 08:00
-
-
Save themodernpk/d789734f4a9f96f6985f74b51ffd79bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Modules\Core\Libraries; | |
use Modules\Core\Entities\Notifications; | |
class CoreOneSignal { | |
//------------------------------------------------\ | |
//------------------------------------------------ | |
function __construct() { | |
} | |
//------------------------------------------------ | |
public static function sendNotificationUsers($user_ids, $heading, $message, $url) | |
{ | |
if($message == "") | |
{ | |
return false; | |
} | |
if($user_ids) | |
{ | |
$i = 0; | |
foreach ($user_ids as $id) | |
{ | |
$condition = [array("key" => env('APP_SHORT_NAME')."-user-id", | |
"relation" => "=", "value" => $id)]; | |
$data = []; | |
$response = \OneSignal::sendNotificationUsingTags($heading, $message, $condition, $url, $data, $buttons=null, $schedule = null); | |
$i++; | |
} | |
} | |
return true; | |
} | |
//------------------------------------------------ | |
public static function sendNotificationUsingTag($inputs) | |
{ | |
$rules = array( | |
'tag_name' => 'required', | |
'tag_value' => 'required', | |
'message' => 'required', | |
'url' => 'required', | |
); | |
$validator = \Validator::make( $inputs, $rules); | |
if ( $validator->fails() ) { | |
$errors = errorsToArray($validator->errors()); | |
$response['status'] = 'failed'; | |
$response['errors'] = $errors; | |
return $response; | |
} | |
$condition[] = array("key" => "team-user-id", "relation" => "!=", "value" => \Auth::user()->id); | |
\OneSignal::sendNotificationUsingTags($inputs['message'], $condition, $inputs['url'], $data=null, $buttons=null, $schedule = null); | |
$response['status'] = 'success'; | |
return $response; | |
} | |
//------------------------------------------------ | |
//------------------------------------------------ | |
}// end of class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment