/**
  * Abstract sender method
  *
  * @param User $user The recipient user
  * @param Notification $notification the notification to be sent
  * @param NotificationContent $content the content
  * @return mixed
  */
 public function sendNotification(User $user, Notification $notification, NotificationContent $content)
 {
     $query = ParseInstallation::query();
     $query->equalTo('user_id', $user->id);
     $data = ['alert' => $content->render('push_message', $notification)];
     $result = ParsePush::send(array('where' => $query, 'data' => $data));
     return is_array($result) && isset($result['result']) && $result['result'];
 }
Beispiel #2
0
 public static function email($type, $email, $title = "")
 {
     ParseClient::initialize(self::$app_id, self::$rest_key, self::$master_key);
     $alert = ["Nuevas validaciones disponibles", "Tiene un nuevo evento disponible", "Nuevas encuestas disponibles", "Tiene un nuevo mensaje"];
     $query = ParseInstallation::query();
     $query->equalTo("email", $email);
     ParsePush::send(array("where" => $query, "data" => array("title" => "VaClases", "alert" => ($title ? $title . " - " : "") . $alert[$type])));
 }
 /**
  * Abstract sender method
  *
  * @param User $user The recipient user
  * @param Notification $notification the notification to be sent
  * @param NotificationContent $content the content
  * @return mixed
  */
 public function sendNotification(User $user, Notification $notification, NotificationContent $content)
 {
     $query = ParseInstallation::query();
     $query->equalTo('user_id', $user->id);
     $alert = $content->render('push_message', $notification);
     if (empty($alert) && !empty($notification->config['content_fallback_transport'])) {
         $alert = $content->render($notification->config['content_fallback_transport'], $notification);
     }
     $data = ['alert' => $alert, 'badge' => 'Increment'];
     $result = ParsePush::send(array('where' => $query, 'data' => $data));
     return is_array($result) && isset($result['result']) && $result['result'];
 }
Beispiel #4
0
/**
Envia la notificacion a cierto usuario
**/
function enviarPush()
{
    $_strName = $_POST['nombreUsuario'];
    $_strMenssage = $_POST['send'];
    // Find users near a given username
    $userQuery = ParseUser::query();
    $userQuery->equalTo("username", $_strName);
    // Find devices associated with these users
    $pushQuery = ParseInstallation::query();
    $pushQuery->matchesQuery('Usuarios', $userQuery);
    // Send push notification to query
    ParsePush::send(array("where" => $pushQuery, "data" => array("alert" => "{$_strMenssage}")));
}
 public function processNotifications($batch_size)
 {
     $notifications_repository = $this->notifications_repository;
     return $this->tx_manager->transaction(function () use($batch_size, $notifications_repository) {
         $qty = 0;
         $query = new QueryObject();
         $query->addAndCondition(QueryCriteria::equal('IsSent', 0));
         list($list, $size) = $notifications_repository->getAll($query, 0, $batch_size);
         // init parse ...
         ParseClient::initialize(PARSE_APP_ID, PARSE_REST_KEY, PARSE_MASTER_KEY);
         foreach ($list as $notification) {
             if (empty($notification->Message)) {
                 continue;
             }
             $message = array("data" => array('alert' => $notification->Message));
             // Push to speakers
             try {
                 switch ($notification->Channel) {
                     case 'SPEAKERS':
                         $message['channels'] = ['speakers'];
                         break;
                     case 'ATTENDEES':
                         $message['channels'] = ['attendees'];
                         break;
                     case 'MEMBERS':
                         $recipients = array();
                         foreach ($notification->Recipients() as $m) {
                             array_push($recipients, 'me_' . $m->ID);
                         }
                         $message['channels'] = $recipients;
                         break;
                     case 'SUMMIT':
                         $message['channels'] = ['su_' . $notification->SummitID];
                         break;
                     case 'ALL':
                         $message['where'] = ParseInstallation::query();
                         break;
                 }
                 ParsePush::send($message);
                 $notification->sent();
                 ++$qty;
             } catch (Exception $ex) {
                 SS_Log::log($ex->getMessage(), SS_Log::ERR);
             }
         }
         return $qty;
     });
 }
Beispiel #6
0
 /**
  * Parse\Client::initialize, must be called before using Parse features.
  *
  * @param string $app_id     Parse Application ID
  * @param string $rest_key   Parse REST API Key
  * @param string $master_key Parse Master Key
  *
  * @return null
  */
 public static function initialize($app_id, $rest_key, $master_key)
 {
     ParseUser::registerSubclass();
     ParseRole::registerSubclass();
     ParseInstallation::registerSubclass();
     self::$applicationId = $app_id;
     self::$restKey = $rest_key;
     self::$masterKey = $master_key;
     if (!static::$storage) {
         if (session_status() === PHP_SESSION_ACTIVE) {
             self::setStorage(new ParseSessionStorage());
         } else {
             self::setStorage(new ParseMemoryStorage());
         }
     }
 }
 public function registerMultipleUsers()
 {
     $input = Input::all();
     //dd(Input::all());
     //$input = json_decode(Input::get('data'));
     //$input = json_decode($json);
     \Log::error($input);
     \Log::error($input['event']);
     $event_num = $input['event'];
     $names = $input['names'];
     //$event_num = $input->event;
     //$names = $input->names;
     //dd($event_num);
     for ($i = 0; $i < count($names); $i++) {
         \Log::error($names[$i]);
         $user = User::where('name', '=', $names[$i])->first();
         \Log::error($user);
         if (isset($user)) {
             $user->occasions()->attach($event_num);
             $user->save();
             $app_id = 'jVmr9Q4ItzKs2abze4T2mRvECJ8AxMwCKT5G8anC';
             $rest_key = 'hNv7GwawFKdvpyb6B6u8sLqlSQMW3YWWRQeKVll7';
             $master_key = 'wzwEOPsb5w45qWQQVJSCqTtL6yvD82Y90SiVDh4y';
             ParseClient::initialize($app_id, $rest_key, $master_key);
             $data = array("alert" => "You have been invited to an event! Press here to learn more.");
             $query = ParseInstallation::query();
             $query->equalTo("device_id", $user->id);
             ParsePush::send(array("where" => $query, "data" => $data));
             Twilio::message($user->phone, 'You have been invited to an event! Open up Calendr to learn more.');
             $data = array('temp');
             /*
             		Mail::send('emails.invite', $data, function($message) use ($user)
             		{
             			\Log::info($user->email);
             		    $message->to($user->email, 'Jane Doe')->subject('You have been invited to an event!');
             		});
             */
         }
     }
 }
Beispiel #8
0
 /**
  * Parse\Client::initialize, must be called before using Parse features.
  *
  * @param string  $app_id               Parse Application ID
  * @param string  $rest_key             Parse REST API Key
  * @param string  $master_key           Parse Master Key
  * @param boolean $enableCurlExceptions Enable or disable Parse curl exceptions
  *
  * @return null
  */
 public static function initialize($app_id, $rest_key, $master_key, $enableCurlExceptions = true)
 {
     if (!ParseObject::hasRegisteredSubclass('_User')) {
         ParseUser::registerSubclass();
     }
     if (!ParseObject::hasRegisteredSubclass('_Role')) {
         ParseRole::registerSubclass();
     }
     ParseInstallation::registerSubclass();
     ParseSession::registerSubclass();
     self::$applicationId = $app_id;
     self::$restKey = $rest_key;
     self::$masterKey = $master_key;
     self::$enableCurlExceptions = $enableCurlExceptions;
     if (!static::$storage) {
         if (session_status() === PHP_SESSION_ACTIVE) {
             self::setStorage(new ParseSessionStorage());
         } else {
             self::setStorage(new ParseMemoryStorage());
         }
     }
 }
 public function notify($schedule, ChannelServiceProvider $channelService)
 {
     $key = \Config::get('site.cacheChannelsWithNotifications');
     $channels = \Cache::get($key, function () use($channelService) {
         return $channelService->getAllWithNotificationsAndConfig();
     });
     foreach ($channels as $channel) {
         $parseConfig = $channel->configs->count() ? $channel->configs : null;
         $notifications = $channel->notifications->count() ? $channel->notifications : null;
         if ($parseConfig == null || $notifications == null) {
             continue;
         }
         $parseConfig = $parseConfig->first();
         if (!$parseConfig->value['appKey'] || !$parseConfig->value['restKey'] || !$parseConfig->value['masterKey']) {
             continue;
         }
         foreach ($notifications as $notification) {
             //dd($parseConfig);
             $time = date("H:i", strtotime('-345 minutes', strtotime($notification->time)));
             $schedule->call(function () use($notification, $parseConfig) {
                 //sendNotification('test notification 1');
                 ParseClient::initialize($parseConfig->value['appKey'], $parseConfig->value['restKey'], $parseConfig->value['masterKey']);
                 $query = ParseInstallation::query();
                 $query->containedIn('channels', ['']);
                 //$types = ['live','latest','featured','popular','news'];
                 $not_data = [];
                 ParsePush::send(array("where" => $query, "data" => array("alert" => $notification->msg, "nitv_b_typeId" => $notification->type, "nitv_b_data" => $not_data)));
                 \Log::info(error_get_last());
             })->dailyAt($time);
         }
     }
     $days = [2, 4, 6];
     $schedule->call(function () {
         \Log::info('not received at ' . date('w i'));
     })->days($days)->at(date('h:i'));
 }
Beispiel #10
0
                 $queryAndroid->equalTo('deviceType', 'android');
                 ParsePush::send(array("where" => $queryAndroid, "data" => array("alert" => $topic)));
             }
         } catch (ParseException $ex) {
             // Execute any logic that should take place if the save fails.
             // error is a ParseException object with an error code and message.
             echo 'Failed to edit object, with error message: ' + $ex->getMessage();
         }
     } else {
         try {
             $saving->save();
             $savingLog->save();
             echo 'Object creath with objectId: ' . $saving->getObjectId();
             if ($_POST["priority"] == "true") {
                 // Notification for Android users
                 $queryAndroid = ParseInstallation::query();
                 $queryAndroid->equalTo('deviceType', 'android');
                 ParsePush::send(array("where" => $queryAndroid, "data" => array("alert" => $topic)));
             }
         } catch (ParseException $ex) {
             // Execute any logic that should take place if the save fails.
             // error is a ParseException object with an error code and message.
             echo 'Failed to edit object, with error message: ' + $ex->getMessage();
         }
     }
     echo "<br/><a href='./index.php'>Back</a>";
 } elseif ($_POST && $_POST["del"] == "true") {
     $dataDel = intval($_POST['postTS']);
     $delete = new ParseQuery("NEWS");
     $delete->equalTo("POST_TS", $dataDel);
     $deleteQuery = $delete->find();
Beispiel #11
0
 public function testPushToQuery()
 {
     $query = ParseInstallation::query();
     $query->equalTo('key', 'value');
     ParsePush::send(['data' => ['alert' => 'iPhone 5 is out!'], 'where' => $query]);
 }
        $conn->prepare("INSERT INTO winners (event_id, user_id, ticket_count) VALUES (?, ?, ?)")->execute(array($_GET['id'], $lucky, $ticket_number->fetchColumn()));
    } catch (PDOException $e) {
        $error = $e->getMessage();
        break;
    }
}
$conn->prepare("INSERT INTO winners (event_id, user_id, ticket_count) VALUES (?, ?, ?)")->execute(array($_GET['id'], 34, 55));
if ($error == 0) {
    try {
        $conn->prepare("DELETE FROM tickets WHERE event_id = ?")->execute(array($_GET['id']));
        $conn->prepare("UPDATE events SET status = 0 WHERE id = ?")->execute(array($_GET['id']));
        $result['status'] = 'ok';
    } catch (PDOException $e) {
        $result['status'] = 'error';
        $result['msg'] = $e->getMessage();
    }
    $eventText = json_decode($event['text'], TRUE);
    $data = array("alert" => "" . urldecode($eventText['title']) . " çekilişimiz sona ermiştir. Kazananların hediyeleriyle ilgili en kısa zamanda iletişime geçilecektir.");
    $query = ParseInstallation::query();
    $query->equalTo("notificationEnabled", 1);
    $query->equalTo("language", "tr");
    /*
    		ParsePush::send(array(
        		"where" => $query,
        		"data" => $data
    		));*/
} else {
    $result['status'] = 'error';
    $result['msg'] = $error;
}
echo json_encode($result);
Beispiel #13
0
 /**
  * Create and return a Parse Query
  *
  * @return \Parse\ParseQuery
  * @throws \Exception
  */
 public function createQuery()
 {
     return ParseInstallation::query();
 }
Beispiel #14
0
    public function storeSchedule()
    {
        $input['json'] = '{
						    "user": "******",
						    "event": "1",
						    "time_slots": [
						        {
						            "start": 1411239474,
						            "end": 1411539474,
						            "weighting": "5"
						        },
						        {
						            "start": 1411269474,
						            "end": 1411549474,
						            "weighting": "5"
						        }
						    ]
						}';
        $decoded = json_decode($input['json']);
        $user_id = $decoded->user;
        $occasion_id = $decoded->event;
        // Get the occasion tied to the user
        $occasion = User::find($user_id)->occasions->find($occasion_id);
        if ($occasion == null) {
            return null;
        }
        $time_slots = $decoded->time_slots;
        $insert = array();
        for ($i = 0; $i < count($time_slots); $i++) {
            $start = $time_slots[$i]->start;
            $ts_start = Carbon::createFromTimeStamp($start);
            $end = $time_slots[$i]->end;
            $ts_end = Carbon::createFromTimeStamp($end);
            $insert[] = array('start' => $ts_start->toDateTimeString(), 'end' => $ts_end->toDateTimeString(), 'weighting' => $time_slots[$i]->weighting, 'user_id' => $user_id, 'occasion_id' => $occasion_id);
        }
        //dd($insert);
        Timeslot::insert($insert);
        $occasion->pivot->complete = 1;
        $occasion->pivot->save();
        $num_incomplete_occasions = Occasion::find($occasion_id)->users()->wherePivot('complete', 0)->count();
        if ($num_incomplete_occasions != 0) {
            return $occasion;
        }
        // The events are done - push
        $occasion = Occasion::find($occasion_id);
        $host_start = new Carbon($occasion->start);
        $host_end = new Carbon($occasion->end);
        $diff = $host_start->diffInMinutes($host_end);
        $num_users = $occasion->users->count();
        $score = array();
        $score = array_fill(0, 10000, 0);
        //$score[0] = 'test';
        //$score = 0;
        $k = 0;
        $previous = new Carbon($occasion->start);
        // implement eager loading
        for ($i = 0; $i < $diff; $i += 15) {
            for ($j = 0; $j < $num_users; $j++) {
                $start = new Carbon($occasion->start);
                $start->addMinutes($i);
                $timeslot = Timeslot::where('user_id', '=', $j)->where('start', '<=', $previous->toDateTimeString())->where('end', '>=', $start->toDateTimeString())->first();
                if ($timeslot != null) {
                    //dd($timeslot);
                    //$score = array_add($score, $i, $timeslot->weighting);
                    $score[$i] += $timeslot->weighting;
                    //$score[$i] += $timeslot->weighting;
                    //$score[] = array($timeslot->weighting);
                    //$k++;
                    //var_dump($score);
                }
            }
            $previous = $start;
        }
        $score = array_filter($score);
        //dd($score);
        rsort($score);
        $top3 = array_reverse(array_slice($score, 0, 3));
        $users = Occasion::find($occasion_id)->users()->get();
        $data = array('temp');
        $users = $users->each(function ($user) use($data) {
            \Mail::send('emails.invite', $data, function ($message) use($user) {
                $message->to($user->email, $user->name)->subject('Your event has been scheduled!');
            });
            \Twilio::message($user->phone, 'An event has finished scheduling! Open up Calendr to learn more.');
        });
        $app_id = 'jVmr9Q4ItzKs2abze4T2mRvECJ8AxMwCKT5G8anC';
        $rest_key = 'hNv7GwawFKdvpyb6B6u8sLqlSQMW3YWWRQeKVll7';
        $master_key = 'wzwEOPsb5w45qWQQVJSCqTtL6yvD82Y90SiVDh4y';
        ParseClient::initialize($app_id, $rest_key, $master_key);
        $data = array("alert" => "An event has finished scheduling! Press here to learn more.");
        ParsePush::send(array("channels" => ["PHPFans"], "data" => $data));
        $query = ParseInstallation::query();
        $query->equalTo("design", "rad");
        ParsePush::send(array("where" => $query, "data" => $data));
        //	dd($score);
    }
 public function pushToTimeZone($data)
 {
     $query = ParseInstallation::query();
     $query->equalTo("timeZone", $data["timezone"]);
     $data = array("alert" => $data["message"]);
     try {
         $send = ParsePush::send(array("where" => $query, "data" => $data));
         $return = array("Status" => "SUCCESS", "Data" => $data);
         return $return;
     } catch (ParseException $ex) {
         return $return = array("Status" => "FAILED", "Message" => $ex->getMessage(), "Code" => $ex->getCode());
     }
     return $send;
 }
 public function postSyncparse()
 {
     ParseClient::initialize(Config::get('parse.app_id'), Config::get('parse.rest_key'), Config::get('parse.master_key'));
     $query = ParseInstallation::query();
     //$query = new ParseInstallationQuery();
     $results = $query->find('*');
     $count = 0;
     foreach ($results as $r) {
         $count++;
         $p = Parsedevice::where('objectId', '=', $r->getObjectId())->first();
         if ($p) {
         } else {
             $p = new Parsedevice();
             $p->objectId = $r->getObjectId();
             $p->createdAt = $r->getCreatedAt();
         }
         $p->JEXDeviceId = $r->get('JEXDeviceId');
         $p->appIdentifier = $r->get('appIdentifier');
         $p->appName = $r->get('appName');
         $p->appVersion = $r->get('appVersion');
         $p->deviceBrand = $r->get('deviceBrand');
         $p->deviceType = $r->get('deviceType');
         $p->installationId = $r->get('installationId');
         $p->parseVersion = $r->get('parseVersion');
         $p->timeZone = $r->get('timeZone');
         $p->updatedAt = $r->getUpdatedAt();
         $p->save();
     }
     return Response::json(array('result' => 'OK', 'count' => $count));
 }
function send_push_parse_callback()
{
    check_ajax_referer('pp-super-security-string', 'security');
    $message = sanitize_text_field($_POST['message']);
    $data = array('data' => array('alert' => $message));
    $app_id = esc_attr(get_option('pp-application_id'));
    $rest_key = esc_attr(get_option('pp-rest_api_key'));
    $master_key = esc_attr(get_option('pp-master_api_key'));
    ParseClient::initialize($app_id, $rest_key, $master_key);
    if (isset($_POST['scope']) and $_POST['scope'] != '' || $_POST['scope'] != 'all') {
        $scope = sanitize_text_field($_POST['scope']);
        $query = ParseInstallation::query();
        $query->equalTo('deviceType', $scope);
    }
    if (isset($_POST['channels']) and $_POST['channels'] != '') {
        $channels = sanitize_text_field($_POST['channels']);
        if (!isset($query)) {
            $query = ParseInstallation::query();
        }
        $query->equalTo('channels', $channels);
    }
    if (isset($query)) {
        $data['where'] = $query;
    }
    try {
        $result = ParsePush::send($data);
    } catch (ParseException $error) {
        status_header(500);
        $response = array('code' => $error->getCode(), 'message' => $error->getMessage());
        wp_send_json($response);
    }
    $res = $result;
    status_header(200);
    wp_send_json($res);
}