public function price($data) { $cp = new ParseQuery("CarWashPackages"); $results = $cp->get($data["objectId"]); $results->set("isRemoved", true); $results->save(); $newPackage = new ParseObject("CarWashPackages"); $newPackage->set("detail", $data["detail"]); $newPackage->set("isRemoved", false); $newPackage->set("title", $data["title"]); $newPackage->set("priceNum", (double) $data["priceNum"]); $newPackage->set("price", "\$" . $data["priceNum"]); $newPackage->set("estTime", (int) $data["estTime"]); try { $newPackage->save(); $response = array("Status" => "SUCCESS", "objectId" => $newPackage->getObjectId(), "title" => $newPackage->get("title"), "detail" => $newPackage->get("detail"), "priceNum" => $newPackage->get("priceNum"), "estTime" => $newPackage->get("estTime"), "createdAt" => $newPackage->getCreatedAt()); return $response; } catch (ParseException $ex) { $ex_array = array("Status" => "FAILED", "Message" => $ex->getMessage(), "Code" => $ex->getCode()); return $ex_array; } }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update() { try { ParseClient::initialize(env('PARSE_ID', 'f**k'), env('PARSE_REST', 'f**k'), env('PARSE_MASTER', 'f**k')); $local = Input::get('local'); $condicoesJSON = Input::get('condicoes'); $condicoes = json_decode($condicoesJSON); $encaminhamentoId = Input::get('id'); $encaminhamentoQuery = new ParseQuery("Encaminhamento"); $encaminhamento = $encaminhamentoQuery->get($encaminhamentoId); $encaminhamento->set('local', $local); $encaminhamento->save(); $condQuery = new ParseQuery("Condicao"); $condQuery->equalTo('encaminhamento', $encaminhamento); $condicoesFromServer = $condQuery->find(); $condicoesArray = []; $destaqueArray = []; for ($serverIndex = 0; $serverIndex < count($condicoesFromServer); $serverIndex++) { $present = false; if (array_key_exists($serverIndex, $condicoesFromServer)) { $keysArray = array_keys($condicoes); for ($localIndex = 0; $localIndex < count($keysArray); $localIndex++) { if (array_key_exists($keysArray[$localIndex], $condicoes)) { if ($condicoes[$keysArray[$localIndex]]->id == $condicoesFromServer[$serverIndex]->getObjectId()) { $present = true; $condicoesFromServer[$serverIndex]->set('ordem', $condicoes[$keysArray[$localIndex]]->ordem); $condicoesFromServer[$serverIndex]->set('destaque', $condicoes[$keysArray[$localIndex]]->destaque); $condicoesFromServer[$serverIndex]->save(); $condicoesArray[$condicoes[$keysArray[$localIndex]]->ordem] = $condicoesFromServer[$serverIndex]->getObjectId(); $destaqueArray[$condicoes[$keysArray[$localIndex]]->ordem] = $condicoesFromServer[$serverIndex]->get('destaque'); unset($condicoes[$keysArray[$localIndex]]); } } } if ($present == false) { $condicoesFromServer[$serverIndex]->destroy(); } } } $keysArray = array_keys($condicoes); for ($index = 0; $index < count($keysArray); $index++) { $condicao = new ParseObject("Condicao"); $condicao->set('frase', $condicoes[$keysArray[$index]]->frase); $condicao->set('ordem', $condicoes[$keysArray[$index]]->ordem); $condicao->set('destaque', $condicoes[$keysArray[$index]]->destaque); $condicao->set('encaminhamento', $encaminhamento); $condicao->save(); $condicoesArray[$condicoes[$keysArray[$index]]->ordem] = $condicao->getObjectId(); $destaqueArray[$condicoes[$keysArray[$index]]->ordem] = $condicao->get('destaque'); } Log::info($condicoesArray); Log::info($destaqueArray); return json_encode(['condicoesArray' => $condicoesArray, 'destaqueArray' => $destaqueArray]); } catch (ParseException $error) { dd($error); return $error; } }
public function testEach() { Helper::clearClass("Object"); $total = 50; $count = 25; $this->saveObjects($total, function ($i) { $obj = new ParseObject("Object"); $obj->set("x", $i + 1); return $obj; }); $query = new ParseQuery("Object"); $query->lessThanOrEqualTo("x", $count); $values = []; $query->each(function ($obj) use(&$values) { $values[] = $obj->get("x"); }, 10); $valuesLength = count($values); $this->assertEquals($count, $valuesLength, 'Did not return correct number of objects.'); sort($values); for ($i = 0; $i < $valuesLength; $i++) { $this->assertEquals($i + 1, $values[$i], 'Did not return the correct object.'); } }
function getABeacon(ParseObject $object) { $beacon = new stdClass(); $beacon->objectId = $object->getObjectId(); $beacon->uuid = $object->get('UUID'); $beacon->beaconColor = $object->get('beaconColor'); if (count($object->getRelation("brand")->getQuery()->find()) != 0) { $beaconBrand = $object->getRelation("brand")->getQuery()->find(); $beacon->brand = getABrand($beaconBrand[0]); } else { $beacon->brand = null; } $beacon->major = $object->get('major'); $beacon->minor = $object->get('minor'); $beacon->name = $object->get('name'); if ($object->get('region') != null) { $beaconRegion = $object->get('region')->fetch(); $beacon->region = getARegion($beaconRegion); } else { $beacon->region = null; } $beacon->type = $object->get('type'); $beacon->createdAt = $object->getCreatedAt(); $beacon->upadtedAt = $object->getUpdatedAt(); return $beacon; }
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'); } }