/** * This function takes a simpleXML object, and, based on a configuration array, * extracts the required bits of data, in order to populate an array. */ function getArrayFromXml($results, $searchParams) { $id = 0; #echo '

We have results:

'.print_r($results,1).'
'; if(!empty($results->searchResult->item)) { foreach($results->searchResult->item as $result) { foreach($searchParams as $param => $parampath) { #echo "

$id $param $parampath

"; /** * getChild is a function which takes a path to a sub-object and returns the value found there, * for example, for the path 'results->shippingInfo-> $adjusted_result[$id][$param] = (string) Utilities\Utilities::getChild($parampath,$result); if(isset(Utilities\Configuration::$transformFields[$param])) { $function = Utilities\Configuration::$transformFields[$param]; /** * This section is eBay specific, but will not cause an * issue for non-ebay searches. * * Todo: work this into a generic process that is configured * by the extending class. */ if((isset($this->multicall) || $this->webservice == TRUE) && $param == 'timeLeft') { $adjusted_result[$id][$param.'_seconds'] = \Utilities\Time::getSecondsLeftFromEbayTime($adjusted_result[$id][$param]); } $adjusted_result[$id][$param] = call_user_func($function, $adjusted_result[$id][$param]); } } $id++; } } $adjusted_result['totalItems'] = (int) $results->paginationOutput->totalEntries; $adjusted_result['pageNumber'] = (int) $results->paginationOutput->pageNumber; $adjusted_result['totalPages'] = (int) $results->paginationOutput->totalPages; #echo "

Adjusted Result:

".print_r($adjusted_result,1).''; return $adjusted_result; }