<?php /* @var $app \Slim\App */ $app->get('/achievement', function ($req, $res, $args) { $userID = $args['userid']; $ach = new AchievementManager($this->get('DB'), $userID); $count = $ach->getAchievements(); echo makeResult(true, $count); })->add(new FBAuthMiddleWare($app)); $app->post('/achievement', function ($req, $res, $args) { $userID = $args['userid']; $ach = new AchievementManager($this->get('DB'), $userID); $count = $ach->addAchievements(); echo makeResult(true, $count); })->add(new FBAuthMiddleWare($app));
case 92: case 93: case 94: case 95: case 96: case 97: case 98: case 99: case 100: return "A"; break; default: return "F"; } } echo makeResult(60); # num divided by 7 $res = []; for ($i = 1; $i <= 20000; $i++) { if ($i % 7 == 0) { array_push($res, $i); } } print_r($res); #half_piramid function makePiramid($col) { $rows = $col * 2 - 1; for ($i = 1; $i <= $rows; $i++) { if ($i <= $col) { for ($m = 1; $m <= $i; $m++) {
$app->get('/search/{term}', function ($req, $res, $args) { $yelp = $this->get('yelp'); $options = array('term' => $args['term'], 'location' => 'Boston, MA', 'category_filter' => 'food'); $results = $yelp->search($options); $trimmed_results = array(); foreach ($results->businesses as $business) { $trimmed_results[] = array('id' => $business->id, 'name' => $business->name); } if (isset($_GET['callback'])) { echo $_GET['callback'] . "(" . json_encode($trimmed_results) . ")"; } else { echo json_encode($trimmed_results); } }); $app->get('/search/id/{id}', function ($req, $res, $args) { //Get yelp API Object $yelp = $this->get('yelp'); //Get json data of business with specified id try { $results = $yelp->getBusiness(urldecode($args['id'])); } catch (Exection $e) { echo makeResult(false, "Business doesn't exist"); } //Return json/jsonp content if (isset($_GET['callback'])) { echo $_GET['callback'] . "(" . json_encode($results) . ")"; } else { echo json_encode($results); } });
$stmt->execute(); //Send result if ($db->error) { echo makeResult(false, "MySQL error: " . $db->errno); } else { echo makeResult(true, "Deleted bucket successfully"); } })->add(new FBAuthMiddleWare($app)); //Delete item in bucket $app->delete('/bucket/{id}/{businessid}', function ($req, $res, $args) { $userID = $args['userid']; $bucketID = $args['id']; $businessID = $args['businessid']; /* @var $db mysqli */ $db = $this->get('DB'); //Check if user owns bucket or that the bucket exists or not if (!isOwnerofBucket($db, $userID, $bucketID)) { echo makeResult(false, "Bucket doesn't exist of not owner of bucket"); return; } //Delete item in bucket $stmt = $db->prepare("DELETE FROM `bucketlist` WHERE `bucket_id` = ? AND `business_id` = ?"); $stmt->bind_param('ss', $bucketID, $businessID); $stmt->execute(); //Send result if ($db->error) { echo makeResult(false, "MySQL error: " . $db->errno); } else { echo makeResult(true, "Deleted from bucket successfully"); } })->add(new FBAuthMiddleWare($app));
<?php $app->get('/friends', function ($req, $res, $args) { $userID = $args['userid']; $fb = $this - get('FB'); /* @var $db mysqli */ $db = $this->get('DB'); /* @var $stmt mysqli_stmt */ $stmt = $db->prepare("SELECT `id`, `name`, `description` FROM `bucket` WHERE `user_id` = ?"); $stmt->bind_param('s', $userID); $stmt->execute(); $stmt->bind_result($id, $name, $description); $buckets = array(); while ($stmt->fetch()) { $bucket['id'] = $id; $bucket['name'] = $name; $bucket['description'] = $description; array_push($buckets, $bucket); } echo makeResult(true, $buckets); })->add(new FBAuthMiddleWare($app));