<?php require_once "ApiLibrary.php"; //Checks if this is running from a request if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'GET') { //This checks to see if anything was passed into the parameter userName if (!isset($_GET['itemId']) && !isset($_GET['catId'])) { //handle error } else { if (isset($_GET['itemId'])) { $_itemId = $_GET['itemId']; echo getCategoryByItem($_itemId); } else { if (isset($_GET['catId'])) { $_catId = $_GET['catId']; echo getItemsByCategory($_catId); } } } }
function getItemsByCategoryAndPhrase($category, $phrase) { $categoryResults = json_decode(getItemsByCategory($category)); $keywordResults = json_decode(getItemsByKeywords($phrase)); $nameResults = json_decode(getItemsByName($phrase)); $results = array(); for ($i = 0; $i < count($categoryResults); $i++) { $iid = $categoryResults[$i]->iid; if (isInObjectArray("iid", $iid, $keywordResults) || isInObjectArray("iid", $iid, $keywordResults)) { array_push($results, $categoryResults[$i]); } } return json_encode($results); }