static function push($notifyMsg)
 {
     $args = array('data' => array('alert' => $notifyMsg->alert, 'badge' => 'Increment'));
     $args['channels'] = array('');
     if (isset($notifyMsg->type) && !is_null($notifyMsg->type) && strlen($notifyMsg->type) > 0) {
         $args['type'] = $notifyMsg->type;
         if ($args['type'] === NotificationsManager::DEVICE_ISO) {
             //$args['channels']= array(NotificationsManager::CHANNEL_ISO);
         }
         if ($args['type'] === NotificationsManager::DEVICE_ANDROID) {
             //	$args['channels'] =array(NotificationsManager::CHANNEL_ANDROID);
         }
     } else {
         // $args['channels']= array(NotificationsManager::CHANNEL_ISO,NotificationsManager::CHANNEL_ANDROID);
     }
     if (isset($notifyMsg->channels) && is_array($notifyMsg->channels) && count($notifyMsg->channels) > 0) {
         $args['channels'] = $notifyMsg->channels;
     }
     //		   $args['channels']= array(NotificationsManager::CHANNEL_ISO,NotificationsManager::CHANNEL_ANDROID);
     //		   var_dump($args);
     if (isset($notifyMsg->push_time) && !is_null($notifyMsg->push_time)) {
         $args['push_time'] = $notifyMsg->push_time;
     }
     if (isset($notifyMsg->expiration_time) && !is_null($notifyMsg->expiration_time)) {
         $args['expiration_time'] = $notifyMsg->expiration_time;
     }
     if (isset($notifyMsg->expiration_interval) && !is_null($notifyMsg->expiration_interval)) {
         $args['expiration_interval'] = $notifyMsg->expiration_interval;
     }
     if (isset($notifyMsg->badge) && !is_null($notifyMsg->badge)) {
         $args['data']['badge'] = $notifyMsg->badge;
     }
     if (isset($notifyMsg->sound) && !is_null($notifyMsg->sound)) {
         $args['data']['sound'] = $notifyMsg->sound;
     }
     if (isset($notifyMsg->content_available) && !is_null($notifyMsg->content_available)) {
         $args['data']['content-available'] = $notifyMsg->badge;
     }
     if (isset($notifyMsg->action) && !is_null($notifyMsg->action)) {
         $args['data']['action'] = $notifyMsg->action;
     }
     if (isset($notifyMsg->title) && !is_null($notifyMsg->title)) {
         $args['data']['title'] = $notifyMsg->title;
     }
     if (isset($notifyMsg->prod_id) && !is_null($notifyMsg->prod_id)) {
         $args['data']['prod_id'] = $notifyMsg->prod_id;
     }
     if (isset($notifyMsg->prod_type) && !is_null($notifyMsg->prod_type)) {
         $args['data']['prod_type'] = $notifyMsg->prod_type;
     }
     if (isset($notifyMsg->push_type) && !is_null($notifyMsg->push_type)) {
         $args['data']['push_type'] = $notifyMsg->push_type;
     }
     // var_dump(json_encode( var_dump($args)));
     $result = ParseClient::getInstance()->push($args, $notifyMsg->appid, $notifyMsg->restkey);
     //		$list = obj2arr ( $result->results );
     //echo ($result['code']);
     //var_dump($result);
     return $result;
 }
Ejemplo n.º 2
0
 static function getInstance()
 {
     if (is_null(self::$myParse)) {
         self::$myParse = new ParseClient();
     }
     return self::$myParse;
 }
 static function deleteInstallation($InstallationID)
 {
     $args = array('className' => '_Installation', 'objectId' => $InstallationID, 'object' => array('pushFlag' => 'Y'));
     if (ParseClient::getInstance()->update($args)) {
         return true;
     }
     return false;
 }
Ejemplo n.º 4
0
 /**
  * Makes a call to a Cloud function
  *
  * @param string $name Cloud function name
  * @param array  $data Parameters to pass
  * @param boolean $useMasterKey Whether to use the Master Key
  *
  * @return mixed
  */
 public static function run($name, $data = array(), $useMasterKey = false)
 {
     $sessionToken = null;
     if (ParseUser::getCurrentUser()) {
         $sessionToken = ParseUser::getCurrentUser()->getSessionToken();
     }
     $response = ParseClient::_request('POST', '/1/functions/' . $name, $sessionToken, json_encode(ParseClient::_encode($data, null, false)), $useMasterKey);
     return ParseClient::_decode($response['result']);
 }
Ejemplo n.º 5
0
 /**
  * Retrieves the Session object for the currently logged in user.
  *
  * @param boolean $useMasterKey If the Master Key should be used to override security.
  *
  * @return ParseSession
  */
 public static function getCurrentSession($useMasterKey = false)
 {
     $token = ParseUser::getCurrentUser()->getSessionToken();
     $response = ParseClient::_request('GET', '/1/sessions/me', $token, null, $useMasterKey);
     $session = new ParseSession();
     $session->_mergeAfterFetch($response);
     $session->handleSaveResult();
     return $session;
 }
Ejemplo n.º 6
0
 /**
  * Returns an associative array encoding of the current operation.
  *
  * @return mixed
  */
 public function _encode()
 {
     if ($this->isAssociativeArray) {
         $object = new \stdClass();
         foreach ($this->value as $key => $value) {
             $object->{$key} = $value;
         }
         return ParseClient::_encode($object, true);
     }
     return ParseClient::_encode($this->value, true);
 }
Ejemplo n.º 7
0
 /**
  * Tracks the occurrence of a custom event with additional dimensions.
  * Parse will store a data point at the time of invocation with the given
  * event name.
  *
  * Dimensions will allow segmentation of the occurrences of this custom
  * event. Keys and values should be strings, and will throw
  * otherwise.
  *
  * To track a user signup along with additional metadata, consider the
  * following:
  * <pre>
  * $dimensions = array(
  *  'gender' => 'm',
  *  'source' => 'web',
  *  'dayType' => 'weekend'
  * );
  * ParseAnalytics::track('signup', $dimensions);
  * </pre>
  *
  * There is a default limit of 4 dimensions per event tracked.
  *
  * @param string $name       The name of the custom event
  * @param array  $dimensions The dictionary of segment information
  *
  * @throws \Exception
  * @return mixed
  */
 public static function track($name, $dimensions = array())
 {
     $name = trim($name);
     if (strlen($name) === 0) {
         throw new Exception('A name for the custom event must be provided.');
     }
     foreach ($dimensions as $key => $value) {
         if (!is_string($key) || !is_string($value)) {
             throw new Exception('Dimensions expected string keys and values.');
         }
     }
     return ParseClient::_request('POST', '/1/events/' . $name, null, static::_toSaveJSON($dimensions));
 }
Ejemplo n.º 8
0
 /**
  * Sends a push notification.
  *
  * @param array $data The data of the push notification.  Valid fields
  *   are:
  *     channels - An Array of channels to push to.
  *     push_time - A Date object for when to send the push.
  *     expiration_time -  A Date object for when to expire
  *         the push.
  *     expiration_interval - The seconds from now to expire the push.
  *     where - A ParseQuery over ParseInstallation that is used to match
  *         a set of installations to push to.
  *     data - The data to send as part of the push
  * @param boolean $useMasterKey Whether to use the Master Key for the request
  *
  * @throws \Exception, ParseException
  * @return mixed
  */
 public static function send($data, $useMasterKey = false)
 {
     if (isset($data['expiration_time']) && isset($data['expiration_interval'])) {
         throw new \Exception('Both expiration_time and expiration_interval can\'t be set.');
     }
     if (isset($data['where'])) {
         if ($data['where'] instanceof ParseQuery) {
             $data['where'] = $data['where']->_getOptions()['where'];
         } else {
             throw new \Exception('Where parameter for Parse Push must be of type ParseQuery');
         }
     }
     if (isset($data['push_time'])) {
         $data['push_time'] = ParseClient::_encode($data['push_time'], false)['iso'];
     }
     if (isset($data['expiration_time'])) {
         $data['expiration_time'] = ParseClient::_encode($data['expiration_time'], false)['iso'];
     }
     return ParseClient::_request('POST', '/1/push', null, json_encode($data), $useMasterKey);
 }
Ejemplo n.º 9
0
 /**
  * Sends a push notification.
  *
  * @param array   $data         The data of the push notification.    Valid fields
  *                              are:
  *                              channels - An Array of channels to push to.
  *                              push_time - A Date object for when to send the push.
  *                              expiration_time -    A Date object for when to expire
  *                              the push.
  *                              expiration_interval - The seconds from now to expire the push.
  *                              where - A ParseQuery over ParseInstallation that is used to match
  *                              a set of installations to push to.
  *                              data - The data to send as part of the push
  * @param boolean $useMasterKey Whether to use the Master Key for the request
  *
  * @throws \Exception, ParseException
  *
  * @return mixed
  */
 public static function send($data, $useMasterKey = false)
 {
     if (isset($data['expiration_time']) && isset($data['expiration_interval'])) {
         throw new \Exception('Both expiration_time and expiration_interval can\'t be set.');
     }
     if (isset($data['where'])) {
         if ($data['where'] instanceof ParseQuery) {
             $data['where'] = $data['where']->_getOptions()['where'];
         } else {
             throw new \Exception('Where parameter for Parse Push must be of type ParseQuery');
         }
     }
     if (isset($data['push_time'])) {
         //Local push date format is different from iso format generally used in Parse
         //Schedule does not work if date format not correct
         $data['push_time'] = ParseClient::getLocalPushDateFormat($data['push_time']);
     }
     if (isset($data['expiration_time'])) {
         $data['expiration_time'] = ParseClient::_encode($data['expiration_time'], false)['iso'];
     }
     return ParseClient::_request('POST', '/1/push', null, json_encode($data), $useMasterKey);
 }
Ejemplo n.º 10
0
 /**
  * You can change your app's name, as well as change your app's settings.
  *
  * @param string $application_id
  * @param array  $data
  *
  * @throws ParseException
  *
  * @return array
  */
 public static function updateApp($application_id, array $data)
 {
     $result = ParseClient::_request('PUT', 'apps/' . $application_id, null, json_encode($data), false, true);
     return $result;
 }
Ejemplo n.º 11
0
 private function upload()
 {
     $fileParts = explode('.', $this->getName());
     $extension = array_pop($fileParts);
     $mimeType = $this->mimeType ?: $this->getMimeTypeForExtension($extension);
     $headers = ParseClient::_getRequestHeaders(null, false);
     $url = ParseClient::HOST_NAME . '/1/files/' . $this->getName();
     $rest = curl_init();
     curl_setopt($rest, CURLOPT_URL, $url);
     curl_setopt($rest, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($rest, CURLOPT_BINARYTRANSFER, 1);
     $headers[] = 'Content-Type: ' . $mimeType;
     curl_setopt($rest, CURLOPT_POST, 1);
     curl_setopt($rest, CURLOPT_POSTFIELDS, $this->getData());
     curl_setopt($rest, CURLOPT_HTTPHEADER, $headers);
     $response = curl_exec($rest);
     $contentType = curl_getinfo($rest, CURLINFO_CONTENT_TYPE);
     if (curl_errno($rest)) {
         throw new ParseException(curl_error($rest), curl_errno($rest));
     }
     curl_close($rest);
     if (strpos($contentType, 'text/html') !== false) {
         throw new ParseException('Bad Request', -1);
     }
     $decoded = json_decode($response, true);
     if (isset($decoded['error'])) {
         throw new ParseException($decoded['error'], isset($decoded['code']) ? $decoded['code'] : 0);
     }
     return $decoded;
 }
Ejemplo n.º 12
0
 /**
  * Creates
  */
 public function __construct()
 {
     $result = ParseClient::_request("GET", "/1/config");
     $this->setConfig($result['params']);
 }
Ejemplo n.º 13
0
 /**
  * Makes a call to a Cloud function
  *
  * @param string $name Cloud function name
  * @param array  $data Parameters to pass
  * @param boolean $useMasterKey Whether to use the Master Key
  *
  * @return mixed
  */
 public static function run($name, $data = array(), $useMasterKey = false)
 {
     $response = ParseClient::_request('POST', '/1/functions/' . $name, null, json_encode(ParseClient::_encode($data, null, false)), $useMasterKey);
     return ParseClient::_decode($response['result']);
 }
 /**
  * ParseClient::_unsetStorage, will null the storage object.
  *
  * Without some ability to clear the storage objects, all test cases would
  *   use the first assigned storage object.
  *
  * @return null
  * @ignore
  */
 public static function _unsetStorage()
 {
     self::$storage = null;
 }
Ejemplo n.º 15
0
 function sendNotification($msg)
 {
     ParseClient::initialize('fPSUGZ0H5wm7UPgcEYQ3EImEgv3HuidGeFXFDDJw', '6VIhRzVVQN8oBsYjbZ2SYCmBzEqK4C499o4Q25KD', 'c6akmuK1fHz8RcYuwn6bh5EhaXvqeeZdezc6xbpj');
     ParsePush::send(['channel' => ['broadcast'], 'data' => ['alert' => $msg]]);
     \Log::info(error_get_last());
 }
Ejemplo n.º 16
0
 /**
  * Returns an associative array encoding of the current operation.
  *
  * @return mixed
  *
  * @throws \Exception
  */
 public function _encode()
 {
     $addRelation = array();
     $removeRelation = array();
     if (!empty($this->relationsToAdd)) {
         $addRelation = array('__op' => 'AddRelation', 'objects' => ParseClient::_encode(self::convertToOneDimensionalArray($this->relationsToAdd), true));
     }
     if (!empty($this->relationsToRemove)) {
         $removeRelation = array('__op' => 'RemoveRelation', 'objects' => ParseClient::_encode(self::convertToOneDimensionalArray($this->relationsToRemove), true));
     }
     if (!empty($addRelation) && !empty($removeRelation)) {
         return array('__op' => 'Batch', 'ops' => [$addRelation, $removeRelation]);
     }
     return empty($addRelation) ? $removeRelation : $addRelation;
 }
Ejemplo n.º 17
0
        if ($member) {
        } else {
            $member = new Member();
        }
        foreach ($m as $k => $v) {
            $member->{$k} = $v;
        }
        $member->status = 'inactive';
        $member->url = '';
        $member->legacyId = new MongoInt32($m['id']);
        $member->roleId = Prefs::getRoleId('Merchant');
        $member->save();
    }
});
Route::get('parsetest', function () {
    ParseClient::initialize('lNz2h3vr3eJK9QMAKOLSaIvETaQWsbFJ8Em32TIw', '8QQoPiTZTkqSMkYLQQxHiaKBXO6Jq7iD2dCJjGUz', '2bKlPqYIKMpW1rJOdpBXQ8pf7cMXxGaFKrCXMr19');
    $query = ParseInstallation::query();
    //$query = new ParseInstallationQuery();
    $results = $query->find('*');
    foreach ($results as $r) {
        $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');
Ejemplo n.º 18
0
function updateRecordByClass($className, $objectId, $data)
{
    $args = array('className' => $className, 'objectId' => $objectId, 'object' => $data);
    if (ParseClient::getInstance()->update($args)) {
        S('List_' . $className . '_Refresh', true);
        return true;
    }
    return false;
}
Ejemplo n.º 19
0
 /**
  * Creates.
  */
 public function __construct()
 {
     $result = ParseClient::_request('GET', 'config');
     $this->setConfig($result['params']);
 }
Ejemplo n.º 20
0
 /**
  * Execute a find query and return the results.
  *
  * @param boolean $useMasterKey
  *
  * @return array
  */
 public function find($useMasterKey = false)
 {
     $sessionToken = null;
     if (ParseUser::getCurrentUser()) {
         $sessionToken = ParseUser::getCurrentUser()->getSessionToken();
     }
     $queryString = $this->buildQueryString($this->_getOptions());
     $result = ParseClient::_request('GET', '/1/classes/' . $this->className . '?' . $queryString, $sessionToken, null, $useMasterKey);
     $output = array();
     foreach ($result['results'] as $row) {
         $obj = ParseObject::create($this->className, $row['objectId']);
         $obj->_mergeAfterFetchWithSelectedKeys($row, $this->selectedKeys);
         $output[] = $obj;
     }
     return $result;
 }
Ejemplo n.º 21
0
 /**
  * Returns an associative array encoding of this operation.
  *
  * @return array
  */
 public function _encode()
 {
     return array('__op' => 'AddUnique', 'objects' => ParseClient::_encode($this->objects, true));
 }
Ejemplo n.º 22
0
 /**
  * Save Object and unsaved children within.
  *
  * @param $target
  * @param bool   $useMasterKey Whether to use the Master Key.
  *
  * @return null
  *
  * @throws ParseException
  */
 private static function deepSave($target, $useMasterKey = false)
 {
     $unsavedChildren = array();
     $unsavedFiles = array();
     static::findUnsavedChildren($target, $unsavedChildren, $unsavedFiles);
     $sessionToken = null;
     if (ParseUser::getCurrentUser()) {
         $sessionToken = ParseUser::getCurrentUser()->getSessionToken();
     }
     foreach ($unsavedFiles as &$file) {
         $file->save();
     }
     $objects = array();
     // Get the set of unique objects among the children.
     foreach ($unsavedChildren as &$obj) {
         if (!in_array($obj, $objects, true)) {
             $objects[] = $obj;
         }
     }
     $remaining = $objects;
     while (count($remaining) > 0) {
         $batch = array();
         $newRemaining = array();
         foreach ($remaining as $key => &$object) {
             if (count($batch) > 40) {
                 $newRemaining[] = $object;
                 continue;
             }
             if ($object->canBeSerialized()) {
                 $batch[] = $object;
             } else {
                 $newRemaining[] = $object;
             }
         }
         $remaining = $newRemaining;
         if (count($batch) === 0) {
             throw new Exception("Tried to save a batch with a cycle.");
         }
         $requests = array();
         foreach ($batch as $obj) {
             $json = $obj->getSaveJSON();
             $method = 'POST';
             $path = '/1/classes/' . $obj->getClassName();
             if ($obj->getObjectId()) {
                 $path .= '/' . $obj->getObjectId();
                 $method = 'PUT';
             }
             $requests[] = array('method' => $method, 'path' => $path, 'body' => $json);
         }
         if (count($requests) === 1) {
             $req = $requests[0];
             $result = ParseClient::_request($req['method'], $req['path'], $sessionToken, json_encode($req['body']), $useMasterKey);
             $batch[0]->mergeAfterSave($result);
         } else {
             $result = ParseClient::_request('POST', '/1/batch', $sessionToken, json_encode(array("requests" => $requests)), $useMasterKey);
             $errorCollection = array();
             foreach ($batch as $key => &$obj) {
                 if (isset($result[$key]['success'])) {
                     $obj->mergeAfterSave($result[$key]['success']);
                 } else {
                     if (isset($result[$key]['error'])) {
                         $response = $result[$key];
                         $error = $response['error']['error'];
                         $code = isset($response['error']['code']) ? $response['error']['code'] : -1;
                         $errorCollection[] = array('error' => $error, 'code' => $code, 'object' => $obj);
                     } else {
                         $errorCollection[] = array('error' => 'Unknown error in batch save.', 'code' => -1, 'object' => $obj);
                     }
                 }
             }
             if (count($errorCollection)) {
                 throw new ParseAggregateException("Errors during batch save.", $errorCollection);
             }
         }
     }
 }
Ejemplo n.º 23
0
 /**
  * Requests a password reset email to be sent to the specified email
  * address associated with the user account.    This email allows the user
  * to securely reset their password on the Parse site.
  *
  * @param string $email
  *
  * @return null
  */
 public static function requestPasswordReset($email)
 {
     $json = json_encode(['email' => $email]);
     ParseClient::_request('POST', '/1/requestPasswordReset', null, $json);
 }
Ejemplo n.º 24
0
 /**
  * Delete a trigger webhook.
  *
  * @param string $className
  * @param string $triggerName
  *
  * @return array
  */
 public function deleteTrigger($className, $triggerName)
 {
     $result = ParseClient::_request('PUT', 'hooks/triggers/' . $className . '/' . $triggerName, null, json_encode(['__op' => 'Delete']), true);
     return $result;
 }