/** * @param array $data * @param ParseObject $parseObject * * @return mixed */ protected function setValues(array $data, $parseObject) { foreach ($data as $key => $value) { // If it's an array, we need to use different setter methods if (is_array($value)) { // Associative array if (count(array_filter(array_keys($value), 'is_string'))) { $parseObject->setAssociativeArray($key, $value); } else { $parseObject->setArray($key, $value); } } else { $parseObject->set($key, $value); } } return $parseObject->save($this->useMasterKey); }
public function testContainsAllStringArrayQueries() { Helper::clearClass("StringSet"); $stringSet1 = new ParseObject("StringSet"); $stringSet1->setArray("strings", ["a", "b", "c", "d", "e"]); $stringSet1->save(); $stringSet2 = new ParseObject("StringSet"); $stringSet2->setArray("strings", ["a", "c", "d", "e"]); $stringSet2->save(); $query = new ParseQuery("StringSet"); $query->containsAll("strings", ["a", "b", "c"]); $results = $query->find(); $this->assertEquals(1, count($results), 'Did not return correct number of objects.'); }
$results = $query->find(); $result = $results[0]; //get garden sensors list $sensors = $result->get("pName"); echo "<br>We are expecting these sensors: " . $sensors; /* assign sensor values based on above sensor list for ($i = 0; $i < count($sensors); $i++) { $object = $sensors[$i]; echo $object; } */ //assemble sensor array function arrayize($input) { return array_map('intval', array_filter(explode(",", $input), 'is_numeric')); } //$currentReadings = preg_split("\"", $reading = new ParseObject("Reading"); $reading->set("gardenID", $result); $reading->setArray("readings", [arrayize($airTemp), arrayize($hum), arrayize($waterTemp), arrayize($sun), arrayize($wet), arrayize($waterPH)]); try { $reading->save(); echo '<br>New reading created with objectId: ' . $reading->getObjectId() . '<br>'; } 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 create new object, with error message: ' . $ex->getMessage(); }
public function do_create(array $params = []) { $mark = array(); for ($x = 0; $x < count($_POST['title']); $x++) { $tag = new ParseObject("BrandTag"); $tag->set("xCoordinate", (double) $_POST['x'][$x]); $tag->set("yCoordinate", (double) $_POST['y'][$x]); $tag->set("tagName", $_POST['title'][$x]); $tag->save(); $query = new ParseQuery("BrandTag"); $query->descending("createdAt"); $object = $query->first(); $id = $object->getObjectId(); $mark[] = array('__type' => 'Pointer', 'className' => 'BrandTag', 'objectId' => '' . $id . ''); } $gameScore = new ParseObject("BrandPost"); $gameScore->setArray("tagArray", $mark); $gameScore->set("brandName", $_POST['brandName']); $gameScore->set("content", $_POST['content']); if (isset($_POST['items'])) { $it = array(); foreach ($_POST['items'] as $item) { $it[] = array('__type' => 'Pointer', 'className' => 'BrandItem', 'objectId' => '' . $item . ''); $gameScore->setArray("brandItems", $it); } } $gameScore->setAssociativeArray("Brand", array('__type' => 'Pointer', 'className' => 'Brand', 'objectId' => $_POST['brand'])); if (isset($_FILES['image']) && !empty($_FILES['image'])) { if (($_FILES["image"]["type"] == "image/png" || $_FILES["image"]["type"] == "image/gif" || $_FILES["image"]["type"] == "image/jpg" || $_FILES["image"]["type"] == "image/jpeg") && $_FILES["image"]["size"] < 10000000) { $file = ParseFile::createFromData(file_get_contents($_FILES['image']['tmp_name']), $_FILES['image']['name']); $file->save(); $gameScore->set("postImage", $file); } } $query = new ParseQuery("Brand"); $query->equalTo("objectId", $_POST['brand']); $question = $query->first(); $n_of_p = $question->numberOfPosts + 1; $question->set("numberOfPosts", $n_of_p); $question->save(); $gameScore->save(); @($this->template = false); redirect(ADMIN_URL . 'brand_post'); }
} $response->success = true; $response->type = 1; $response->data = $msgArray; $response->chat = $chat->getObjectId(); $response->user = $user->getObjectId(); $response->speakers = $spkArray; $response->avatar = $imgArray; $response->date = $dateArray; echo json_encode($response); } else { $chat = new ParseObject("Chat"); $users = array(); array_push($users, $host->getObjectId()); array_push($users, $user->getObjectId()); $chat->setArray('users', $users); try { $chat->save(); $response = new Response(); $response->success = true; $response->type = 2; $response->chat = $chat->getObjectId(); $response->user = $user->getObjectId(); echo json_encode($response); } catch (ParseException $ex) { $response->success = false; $response->message = 'Error: Failed to chat: ' . $ex; echo json_encode($response); } } }
public function testContainsAllStringArrayQueries() { Helper::clearClass('StringSet'); $stringSet1 = new ParseObject('StringSet'); $stringSet1->setArray('strings', ['a', 'b', 'c', 'd', 'e']); $stringSet1->save(); $stringSet2 = new ParseObject('StringSet'); $stringSet2->setArray('strings', ['a', 'c', 'd', 'e']); $stringSet2->save(); $query = new ParseQuery('StringSet'); $query->containsAll('strings', ['a', 'b', 'c']); $results = $query->find(); $this->assertEquals(1, count($results), 'Did not return correct number of objects.'); }
/////////// //connecting with database // Create connection $conn = new mysqli($servername, $username, $password, $dbname); $chatData = new ParseObject("ChatData"); if ($user_id_1 !== NULL && $user_id_2 !== NULL) { //insert $like_insert_sql = "INSERT INTO likes (user_id_1,user_id_2) VALUES ('{$user_id_1}','{$user_id_2}');"; if ($conn->query($like_insert_sql) == true) { $json_response["success"] = true; //checking for a new match $sql = "SELECT * FROM likes WHERE user_id_1 = '{$user_id_2}' AND user_id_2 = '{$user_id_1}';"; $result = $conn->query($sql); if ($result->num_rows > 0) { try { $chatData->setArray("messages", array()); $chatData->save(); $chat_id = $chatData->getObjectId(); $match_sql_1 = "INSERT INTO matches (user_id_1,user_id_2,chat_id) VALUES ('{$user_id_1}','{$user_id_2}','{$chat_id}');"; $match_sql_2 = "INSERT INTO matches (user_id_1,user_id_2,chat_id) VALUES ('{$user_id_2}','{$user_id_1}','{$chat_id}');"; $conn->query($match_sql_1); $conn->query($match_sql_2); } 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 create new object, with error message: ' . $ex->getMessage(); } } } } else { $json_response["success"] = false;
$results = $users->find(); $user = ParseUser::logIn($results['results'][0]['username'], $results['results'][0]['passwordNew']); $userObject = new ParseObject("_User", $_GET['objectId']); $userObject->set("refemployerid", $dataObject['refemployerid']); $userObject->save(); $returnData = json_encode(array("code" => 1)); break; case "addEmployee": $dataObject = json_decode(file_get_contents("php://input"), true); $addEmployee = new ParseObject('Employers'); $addEmployee->set("name", $dataObject['name']); $addEmployee->set("primaryColor", $dataObject['primaryColor']); $addEmployee->set("secondaryColor", $dataObject['secondaryColor']); $addEmployee->set("agencyId", $dataObject['agencyId']); $addEmployee->set("loginCode", $dataObject['loginCode']); $addEmployee->setArray("logo", $dataObject['logo']); $addEmployee->setArray("html_content", $dataObject['html_content']); $dataSuccess = $addEmployee->save(); $returnData = '{"code":1}'; break; case "push": $dataObject = json_decode(file_get_contents("php://input"), true); ParsePush::send($dataObject); $returnData = '{"code":1}'; break; case "tynidata": $returnData['data'] = file_get_contents($_REQUEST['stringurl']); $returnData = json_encode($returnData['data']); break; } echo $returnData;
public function newEvent($gid, Request $request) { $current_user = ParseUser::getCurrentUser(); if (!$current_user) { return redirect()->route('login'); } Html\Assets::addLink(Html\Link::Css('/vendor/pickadate.js-3.5.6/lib/themes/default.css')); Html\Assets::addLink(Html\Link::Css('/vendor/pickadate.js-3.5.6/lib/themes/default.date.css')); Html\Assets::addLink(Html\Link::Css(elixir('css/default.css'))); Html\Assets::addLink(Html\Link::Script('/vendor/pickadate.js-3.5.6/lib/picker.js')); Html\Assets::addLink(Html\Link::Script('/vendor/pickadate.js-3.5.6/lib/picker.date.js')); Html\Assets::addLink(Html\Link::Script(elixir('scripts/newevent.js'))); Html\Assets::addMetaTag(Html\Meta::Tag('description', '')); $st = $request->input("st"); $query = new ParseQuery("Groups"); try { $group = $query->get($gid); //--save start if ($request->getMethod() == "POST") { $eventName = $request->input('name'); $eventDate = $request->input('eventDate'); $invites = $request->input('invites'); $update = false; $id = $request->input('id'); if (!empty($id)) { $qry = new ParseQuery('Events'); $eventObj = $qry->get($id); $update = true; } else { $eventObj = new ParseObject('Events'); } $eventObj->set('name', $eventName); if (!empty($eventDate)) { $eventDate = new \DateTime($eventDate); $eventObj->set('date', $eventDate); } if (empty($eventObj->get('inviteCode'))) { $eventObj->set('inviteCode', $this->generate_random_letters(6)); } if (empty($invites)) { $invites = []; } $eventObj->setArray('invites', $invites); $eventObj->set('user', $current_user); $eventObj->set('group', $group); try { $eventObj->save(); if ($update == false) { $relation = $eventObj->getRelation('members'); $relation->add($current_user); $eventObj->save(); $grelation = $group->getRelation('events'); $grelation->add($eventObj); $group->save(); //-- create chat room --// $chatObj = new ParseObject('ChatRoom'); $chatObj->set('name', $eventObj->get('name')); $chatObj->set('event', $eventObj); $chatObj->save(); $relation = $chatObj->getRelation('members'); $relation->add($current_user); $chatObj->save(); $eventObj->set('chatRoom', $chatObj); $eventObj->save(); } return redirect('/groups'); } 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 create new object, with error message: ' . $ex->getMessage(); } } //--save end $renderData = $this->getRenderData($request); $renderData['user'] = $current_user; $renderData['navTitle'] = $group->get('name'); $renderData['st'] = !empty($st) ? $st : ''; return view('newevent', $renderData); } catch (ParseException $ex) { // The object was not retrieved successfully. // error is a ParseException with an error code and message. echo $ex->getMessage(); } }
public function processGroup(Request $request) { //if logged process otherwise go to login form $current_user = ParseUser::getCurrentUser(); if (!empty($current_user)) { //process form $lastAction = $request->session()->get('lastAction'); $groupName = $request->input('groupname') ?: $request->session()->get('newgroup:groupName'); $invites = $request->input('invites') ?: $request->session()->get('newgroup:invites'); $public = $request->input('public') ?: $request->session()->get('newgroup:public'); $reroute = $request->input('reroute'); $st = $request->input('st'); $groupId = $request->input('id'); if (!empty($groupId)) { //does this user have permission to edit group $qry = new ParseQuery('Groups'); $groupObj = $qry->get($groupId); if ($groupObj->get('public') !== true) { if ($current_user->getObjectId() != $groupObj->get('user')->getObjectId()) { throw new HttpException(401, 'Sorry you don\'t have permission to edit group'); } } } else { $groupObj = new ParseObject('Groups'); } $groupObj->set('name', $groupName); $groupObj->set('user', $current_user); if ($public == 'y') { $groupObj->set('public', true); } else { $groupObj->set('public', false); } if (empty($invites)) { $invites = []; } $invites = array_keys(array_flip($invites)); $prevInvites = $groupObj->get('invites') ?: array(); $diffInvites = array_diff($invites, $prevInvites); $groupObj->setArray('invites', $invites); if (empty($groupObj->get('inviteCode'))) { $groupObj->set('inviteCode', $this->generate_random_letters(6)); } try { $groupObj->save(); $relation = $groupObj->getRelation('members'); $relation->add($current_user); $groupObj->save(); //send email if (!empty($diffInvites)) { $send = new Mail\Send(); $send->sendInviteEmail($diffInvites, $current_user, $groupObj->get('inviteCode'), $groupObj->get('name')); } if ($reroute == 'newevents') { $url = route('newEvent', ['gid' => $groupObj->getObjectId()]) . '?st=' . $st; return redirect($url); } else { return redirect('/groups'); } } 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 create new object, with error message: ' . $ex->getMessage(); } } else { //save form show login $request->session()->set('lastAction', 'newgroup'); $request->session()->set('newgroup:groupName', $request->input('groupname')); $request->session()->set('newgroup:invites', $request->input('invites')); $request->session()->set('newgroup:public', $request->input('public')); return redirect()->route('register'); } }