loadModule(); require_once(dirname(dirname(__FILE__)) . '/classes/CasBrowser.class.php'); $outputFormat = 'json'; // Hard-coded for now // Get client handle $cb = new CasBrowser(); $client = $cb->getClient(); $results = array('results'=>array()); // Get all products and their types $allProducts = array(); foreach($client->getProductTypes() as $type){ foreach($client->getProductsByProductType($type) as $product){ array_push($allProducts, array('product'=>$product, 'typeName'=>$type->getName())); } } // Narrow down the given products to the requested page (if page info is given) $requestedProducts = array(); if(isset($_POST['PageNum']) && isset($_POST['PageSize'])){ $pageNum = intval($_POST['PageNum']); $pageSize = intval($_POST['PageSize']); try{ $requestedProducts = Utils::paginate($allProducts, $pageNum, $pageSize); }catch(Exception $e){ Utils::reportError($e->getMessage(), $outputFormat); } $results['totalPages'] = ceil(count($allProducts) / $pageSize); }else{ $requestedProducts = $allProducts; } // Get metadata and format requested products try{ $results['results'] = Utils::formatResults($requestedProducts); }catch(Exception $e){ Utils::reportError($e->getMessage(), $outputFormat); } $results['totalProducts'] = count($allProducts); echo json_encode($results); ?>