/** * @inheritdoc */ public function process(array $settings = []) { $this->processOrders($settings); $this->processFilters($settings); $this->source->limit($settings['limit']); $this->source->skip(($settings['page'] - 1) * $settings['limit']); // run queries $gridData = new Grid\Data($this->source->find()); // get all records to set grid total // @todo: cache result of total query for few minutes $this->source = new ParseQuery($this->collectionName); $this->processOrders($settings); $this->processFilters($settings); $gridData->setTotal(sizeof($this->source->limit(1000)->find())); return $gridData; }
public function find($className, $equalToArray = array(), $ascending = null, $desceding = null, $limit = null, $skip = null, $includeArray = array()) { $query = new ParseQuery($className); if ($equalToArray) { foreach ($equalToArray as $key => $value) { $query->equalTo($key, $value); } } if ($ascending) { $query->ascending($ascending); } if ($desceding) { $query->descending($descending); } if ($limit) { $query->limit($limit); } if ($skip) { $query->skip($skip); } if ($includeArray) { foreach ($includeArray as $include) { $query->includeKey($include); } } return $query->find(); }
/** * Lists all ProjectsAdmin entities. * * @Route("/index/{page}", name="admin_projects", defaults={ "page" = 1 }) * @Method("GET") * @Template() */ public function indexAction($page) { $query = new ParseQuery('Project'); $query->ascending("label"); $query->limit(12); $query->skip(12 * ($page - 1)); $entities = $query->find(); return array('entities' => $entities, 'hits' => ceil($query->count() / 12), 'page' => $page, 'csrf' => $this->get('form.csrf_provider')); }
/** * @param $column * @param $latitude * @param $longitude * @param $limit * @param array $keyToInclude * * @return Collection|ParseObject[] */ public function near($column, $latitude, $longitude, $limit = 10, $keyToInclude = []) { $location = new ParseGeoPoint($latitude, $longitude); $this->query->near($column, $location); $this->query->limit($limit); for ($i = 0; $i < count($keyToInclude); $i++) { $this->query->includeKey($keyToInclude[$i]); } return Collection::make($this->query->find($this->useMasterKey)); }
function getStolenBikes() { $query = new ParseQuery("Bikes"); $query->exists("sessionStartTime"); $query->limit(1000); $results = $query->find(); $count = count($results); $listOfBikes = array(); $stolenBikes = 0; for ($i = 0; $i < $count; $i++) { $startDate = $results[$i]->get("sessionStartTime"); $startDate = $startDate->format('Y-m-d H:i:s'); $startDate = strtotime($startDate); $currentDate = new DateTime('now'); $currentDate = $currentDate->format('Y-m-d H:i:s'); $currentDate = strtotime($currentDate); $subtractedDate = $currentDate - $startDate; $expiredTime = 200 * 60; if ($subtractedDate >= $expiredTime * 60) { $stolenBikes++; $bike = $results[$i]; try { $lostBike = new ParseObject("LostBikes"); $lostBike->set("bikeId", $bike->getObjectId()); $user = $bike->get("currentUser"); $user->fetch(); $customerID = $user->get("stripeID"); $amount = 200 * 100; $charge = \Stripe\Charge::create(array('customer' => $customerID, 'amount' => $amount, 'currency' => 'usd')); $lostBike->set("currentUser", $user); $lostBike->set("lastLocation", $bike->get("lastLocation")); $lostBike->set("condition", $bike->get("condition")); $lostBike->save(); $bike->destroy(); } catch (\Parse\ParseException $ex) { return 'Failed to create LostBikes object and destroy Bikes object ' . $ex->getMessage(); } catch (\Stripe\Error\InvalidRequest $e) { return $e->getMessage(); } catch (\Stripe\Error\Authentication $e) { return $e->getMessage(); } catch (\Stripe\Error\ApiConnection $e) { return $e->getMessage(); } catch (\Stripe\Error\Base $e) { return $e->getMessage(); } catch (Exception $e) { return $e->getMessage(); } } } $rString = 0; if ($stolenBikes > 0) { $rString = "Successfully removed " . $stolenBikes . " stolen bikes."; } return $rString; }
public function showHome(Request $request) { $current_user = ParseUser::getCurrentUser(); if (!$current_user) { return redirect()->route('login'); } $query = ParseUser::query(); $current_user = $query->get($current_user->getObjectId()); Html\Assets::addLink(Html\Link::Css(elixir('css/default.css'))); Html\Assets::addMetaTag(Html\Meta::Tag('description', '')); $query = new ParseQuery("ChatRoom"); $query->equalTo('members', $current_user); try { $chatRooms = $query->find(); $query = new ParseQuery("Messages"); $query->containedIn("chatRoom", $chatRooms); $query->descending('createdAt'); $query->includeKey('chatRoom'); $query->includeKey('user'); $query->limit(20); $messages = $query->find(); $data = []; foreach ($messages as $message) { $chatRoom = $message->get('chatRoom'); $event = $chatRoom->get('event'); $evQuery = new ParseQuery('Events'); $evQuery->includeKey('group'); $event = $evQuery->get($event->getObjectId()); $group = $event->get('group'); $relation = $message->getRelation("asset"); $aqry = $relation->getQuery(); $assets = $aqry->find(); $temp = ['group' => $group, 'event' => $event, 'chatRoom' => $chatRoom, 'message' => ['msg' => $message, 'assets' => $assets], 'user' => $message->get('user')]; $data[] = $temp; } } catch (ParseException $ex) { // The object was not retrieved successfully. // error is a ParseException with an error code and message. echo $ex->getMessage(); } $renderData = $this->getRenderData($request); $renderData['user'] = $current_user; $renderData['activeBarTab'] = "dashboard"; $renderData['data'] = $data; return view('home', $renderData); }
public function testQueryDataUnt() { $department = "ACCT"; $course = "2010"; $section = "001"; $obj = ParseObject::create('TestObject'); $obj->set('department', $department); $obj->set('course', $course); $obj->set('section', $section); $obj->save(); $query = new ParseQuery('TestObject'); $query->startsWith('department', $department); $query->equalTo('course', $course); $query->startsWith('section', $section); $query->limit(1); $response = $query->find(); $this->assertTrue(count($response) == 1); }
function queryDataUnt($department, $course, $section = "001") { $query = new ParseQuery("Book"); $query->startsWith("department", $department); $query->equalTo("course", $course); //$query->startsWith("section", $section); $query->limit(1); try { $result = $query->find(); if (isset($result[0])) { $object = $result[0]; $GLOBALS['isbn'] = $object->get("isbn"); $GLOBALS['name'] = $object->get("name"); $GLOBALS['priceNewUnt'] = $object->get("priceNew"); } } catch (ParseException $ex) { echo "Book not found in database."; } }
public function toExcel() { $con = new Connect(); $var = $con->connect_to_db(); //iniciamos una consulta para recibir todos los usuarios ausentes de la sede del mentor logueado $query = new ParseQuery("Asistencia"); $query->limit(1000); $query->includeKey('Usuario_FK'); $results = $query->find(); $listado = array(); for ($i = 0; $i < count($results); $i++) { $object = $results[$i]; $usuario = $object->get('Usuario_FK'); $sede = $object->get('Sede'); $persona = array('Nombre' => $usuario->get("Nombre"), "Apellido" => $usuario->get("Apellido"), "Presente" => $object->get("Presente")); array_push($listado, $persona); } //"Fecha" => $object->get("fecha"), //definimos una función para ordenar el array con nuestros parámetros function custom_sort($a, $b) { return $a['Nombre'] > $b['Nombre']; } //ordenamos el array usort($listado, "custom_sort"); //transformamos a json //$json = json_encode($listado); //echo $json; $filename = "asistencia.csv"; $delimiter = ";"; header('Content-Type: application/csv'); header('Content-Disposition: attachment; filename="' . $filename . '";'); // open the "output" stream // see http://www.php.net/manual/en/wrappers.php.php#refsect2-wrappers.php-unknown-unknown-unknown-descriptioq $f = fopen('php://output', 'w'); foreach ($listado as $line) { fputcsv($f, $line, $delimiter); } }
public function testEachFailsWithLimit() { $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); $query->limit(5); $this->setExpectedException('\\Exception', 'limit'); $query->each(function ($obj) { }); }
public function limitQuery() { $query = new ParseQuery("Test"); try { ParseClient::$THROW_RESPONSE = true; $query->limit(10); $results = $query->find(); } catch (\Exception $ex) { $msg = json_decode($ex->getMessage(), true); return $msg ? $msg : $ex->getMessage(); } }
/** * Display the specified resource. * * @param int $id * @return Response */ public function search() { $user = Auth::user(); if ($user) { $input = Input::all(); //get used paramater and set it to a boolean $used = $input['used'] == 'true' ? true : false; $search = $input['search']; $query = new ParseQuery("Transaction"); $query->limit(1000); //only Get results from that sponsor $query->equalTo("sponsor", $user->sponsor); $query->equalTo("deployment", env("DEPLOYMENT")); $query->equalTo("studentID", $search); $query->equalTo("used", $used); $data = $query->find(); if ($used) { return View::make('manage.used', $data)->with('data', $data); //)->with($query->find()); } elseif (condition) { return View::make('manage.unused', $data)->with('data', $data); //)->with($query->find()); } } else { return Redirect::to('login'); } }
function user_register_report($first, $last, $pass, $email, $report_id) { $response = new Response(); $name = $first . "_" . $last; $user = new ParseUser(); $user->set("username", strtolower($name)); $user->set("email", $email); $user->set("password", $pass); try { $user->signUp(); $_SESSION['user'] = $user; $_SESSION['notification'] = true; $query = new ParseQuery("_Session"); $query->equalTo("user", $user); $query->includeKey("user"); $query->descending("createdAt"); $query->limit(1); $new = $query->find(true); $_SESSION['last_date'] = date_format($new[0]->getCreatedAt(), 'Y-m-d\\TH:i:s.u\\Z'); echo add_user_report($report_id, $user); } catch (ParseException $ex) { $response->success = false; $response->message = 'Error: Failed to register: ' . $error; echo json_encode($response); } }
/** * Same code from analytics.php Should need a ajax-Php function in order to call those methods... * Copied the code for quickness */ $x = $_GET['q']; ParseClient::initialize('P60EfTUuOZoeZyD2qSLpOrc8DWwUk2YjEqU2HY1R', 's3b2cfGtQhSFYM16ZIJQ7yXioTjt35Um5mn9SyP8', '3jz6CONqt5psS4UlGu3RB28ldIw311Iv2I8eA3Mh'); $query = new ParseQuery("Reading"); if ($x < 32) { $period = date('Y-m-d\\TH:i:s.u\\Z', strtotime("-" . $x . "day")); } else { $period = date('Y-m-d\\TH:i:s.u\\Z', strtotime("-7 day")); $x = 7; } $results = array(); $query->greaterThan("createdAt", $period); $query->limit(10000); $results = $query->find(); $weeklyTraffic = array(); $currentDay = $results[0]->getCreatedAt()->format('d'); $weeklyTraffic[$currentDay] = 0; $labelsString = ""; $data = ""; for ($i = 0; $i < count($results); $i++) { if ($currentDay == $results[$i]->getCreatedAt()->format('d')) { $weeklyTraffic[$results[$i]->getCreatedAt()->format('d') . ""] = $weeklyTraffic[$results[$i]->getCreatedAt()->format('d') . ""] + 1; } else { /* * Prepare strings for x axis in javascript */ $labelsString .= $currentDay . ','; $data .= $weeklyTraffic[$currentDay] . ',';
$users->limit(1000); $users->equalTo("objectId", $_GET['objectId']); $results = $users->find(); if (count($results['results']) > 0) { //$dataObject = json_decode(file_get_contents("php://input"), true); $user = ParseUser::logIn($results['results'][0]['username'], $results['results'][0]['passwordNew']); $deleteUser = new ParseObject('_User', $_GET['objectId']); $deleteUser->destroy(); $deleteUser->save(); } $returnData = json_encode(array("code" => 1)); break; case "assignUser": $dataObject = json_decode(file_get_contents("php://input"), true); $users = new ParseQuery("_User"); $users->limit(1000); $users->equalTo("objectId", $_GET['objectId']); $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']);
$func = $_POST['check']; if ($func == 'guest') { (string) ($uniq = uniqid()); $name = "Guest-" . $uniq; $user = new ParseUser(); $user->set("username", $name); $user->set("password", $uniq); $user->setArray("connected", []); $user->set("status", 0); try { $user->signUp(); $_SESSION['user'] = $user; $_SESSION['notification'] = true; $query = new ParseQuery("_Session"); $query->equalTo("user", $user); $query->includeKey("user"); $query->descending("createdAt"); $query->limit(1); $new = $query->find(true); $_SESSION['last_date'] = date_format($new[0]->getCreatedAt(), 'Y-m-d\\TH:i:s.u\\Z'); add_user_report($_SESSION['id'], $user); } catch (ParseException $ex) { echo $ex; } } if ($func == 'login') { echo user_login_report($_POST['username'], $_POST['password'], $_SESSION['id']); } if ($func == 'register') { echo user_register_report($_POST['first'], $_POST['last'], $_POST['password'], $_POST['email'], $_SESSION['id']); }
/** * @param $uid */ function getTagUser($uid) { //initialaza Parse PHP api ParseClient::initialize('P60EfTUuOZoeZyD2qSLpOrc8DWwUk2YjEqU2HY1R', 's3b2cfGtQhSFYM16ZIJQ7yXioTjt35Um5mn9SyP8', '3jz6CONqt5psS4UlGu3RB28ldIw311Iv2I8eA3Mh'); $query = new ParseQuery("Reading"); $query->equalTo("user", $uid . ""); //retrun user with selected id $query->limit(1000); $results = $query->find(); $list = array(); for ($t = 0; $t < count($results); $t++) { //for each article I memorize the title $title = $results[$t]->title; $query2 = "SELECT name FROM taxonomy_term_data WHERE tid IN (\n SELECT field_tags_tid FROM field_data_field_tags WHERE entity_id IN (\n SELECT vid FROM node WHERE title = '" . htmlspecialchars($title, ENT_QUOTES) . "'\n )\n )"; //select all the tags from an article (not optimized because I run multiples queries even if the article is the same) /*** * * TO DO * select all the tags from an article (not optimized because I run multiples queries even if the article is the same) * And put in a method * */ $tags = db_query($query2); foreach ($tags as $record) { //for each tag i increment its counter if (empty($list[$record->name])) { $list[$record->name] = 1; } else { $list[$record->name] = $list[$record->name] + 1; } } } return $list; }
/** * Fetch an array of Parse objects from the server. * * @param array $objects The ParseObjects to fetch * @param bool $useMasterKey Whether to override ACLs * * @return array */ public static function fetchAll(array $objects, $useMasterKey = false) { $objectIds = static::toObjectIdArray($objects); if (!count($objectIds)) { return $objects; } $className = $objects[0]->getClassName(); $query = new ParseQuery($className); $query->containedIn('objectId', $objectIds); $query->limit(count($objectIds)); $results = $query->find($useMasterKey); return static::updateWithFetchedResults($objects, $results); }
function parseXML() { $brand = ""; $rakutens = simplexml_load_file('sample_rakuten.xml'); foreach ($rakutens->product as $product) { $prod = new productModel(); $prod->name = $product['name']; $prod->sku = $product['sku_number']; //Category $category = $product->category; $prod->primary = $category->primary; $prod->secondary = $category->secondary; //URL $url = $product->url; $prod->productUrl = $url->product; $prod->productImage = $url->productImage; $prod->buyLink = $url->buyLink; //description $description = $product->description; $prod->short_description = $description->short; $prod->long_description = $description->long; //price $price = $product->price; $prod->price_currency = $price['currency']; $prod->retail = $price->retail; $prod->final_price = $prod->retail; $prod->discount_amount = 0; //discount $discount = $product->discount; $prod->discount_currency = $discount['currency']; $discount_type = $discount->type; if ($discount_type == "amount") { $prod->discount_amount = $discount->amount; if ($prod->discount_amount > 0) { $prod->final_price = $prod->retail - $prod->discount_amount; } } else { } //brand $brandItem = $product->brand; //todo replaced this with brand //get brands $query = new ParseQuery("Brand"); // Get a specific object: //$object = $query->get("anObjectId"); $query->limit(100); // default 100, max 1000 //$query->equalTo("name", ""); // All results: $results = $query->find(); echo "<br />\n"; echo "Successfully retrieved " . count($results) . " objects."; for ($i = 0; $i < count($results); $i++) { $object = $results[$i]; echo $object->getObjectId() . ' - ' . $object->get('name'); echo "<br />\n"; } //Category // //************************ //Query SKU //************************ echo "<br />\n Querying product " . $prod->sku; echo "<br />\n"; $query = new ParseQuery("Rakuten_Product"); $query->equalTo("sku", (string) $prod->sku); $object = $query->first(); if (count($object) > 0) { $this->updateProduct($prod, $object); } else { $this->createProduct($prod); } } }
</div> <div id="a2"><?php $object = new ParseQuery("events"); $object->ascending("date"); $object->limit(1); $results = $object->find(); for ($i = 0; $i < count($results); $i++) { $dataObject = $results[$i]; echo $dataObject->get('name'); } ?> </div> <div id="s1"><?php $object = new ParseQuery("events"); $object->ascending("date"); $object->limit(1); $results = $object->find(); for ($i = 0; $i < count($results); $i++) { $dataObject = $results[$i]; echo $dataObject->get('message'); } ?> </div> <div id="countdown"> <script type="text/javascript"> $('#countdown').countdown('2015/12/10', function(event) { $(this).html(event.strftime('%d days %H:%M:%S')); }); </script> </div>
#use Parse\ParseUser; #use Parse\ParseInstallation; #use Parse\ParseException; #use Parse\ParseAnalytics; #use Parse\ParseFile; #use Parse\ParseCloud; use Parse\ParseClient; ParseClient::initialize($PARSE_APP_ID, $PARSE_REST_KEY, $PARSE_MASTER_KEY); /* $object = ParseObject::create("TestObject"); $objectId = $object->getObjectId(); $php = $object->get("elephant"); // Set values: $object->set("elephant", "php"); $object->set("today", new DateTime()); $object->setArray("mylist", [1, 2, 3]); $object->setAssociativeArray( "languageTypes", array("php" => "awesome", "ruby" => "wtf") ); // Save: $object->save(); */ $query = new ParseQuery("TestObject"); // Get a specific object: $object = $query->get("zD67yQOxAi"); $query->limit(10); // default 100, max 1000 // Just the first result: $first = $query->first(); var_dump($first);
function getOpenBikesWithinDistance($latitude, $longitude, $radius) { $point = new ParseGeoPoint($latitude, $longitude); $query = new ParseQuery("Bikes"); $query->includeKey("currentUser"); $query->doesNotExist("currentUser"); $query->withinMiles("lastLocation", $point, $radius); $query->limit(1000); $results = $query->find(); $count = count($results); $listOfBikes = array(); for ($i = 0; $i < $count; $i++) { $bike = $results[$i]; $ID = $bike->getObjectId(); $point = $bike->get("lastLocation"); $lat = $point->getLatitude(); $long = $point->getLongitude(); $object = new stdClass(); $object->bikeID = $ID; $object->latitude = $lat; $object->longitude = $long; array_push($listOfBikes, $object); } return $listOfBikes; }