} try { $matchingPTs = searchTypeMetadata($queryTypes, $criteriaTree); } catch (Exception $e) { Utils::reportError("An exception occurred while searching type metadata: " . $e->getMessage(), $outputFormat); } foreach ($matchingPTs as $matchingType) { array_splice($queryTypes, array_search($matchingType, $queryTypes), 1); // Remove types that match from query foreach ($client->getProductsByProductType($matchingType) as $p) { // Add all products of matching types array_push($allMatchingProducts, array('product' => $p, 'typeName' => $matchingType->getName())); } } // Add criteria to query object $query = new CAS_Filemgr_Query(); $query->addCriterion($criteriaTree); // Perform the query and collect results try { foreach ($queryTypes as $type) { $queryResultsOfType = $client->query($query, $type); if (count($queryResultsOfType) > 0) { foreach ($queryResultsOfType as $matchingProduct) { array_push($allMatchingProducts, array('product' => $matchingProduct, 'typeName' => $type->getName())); } } } } catch (Exception $e) { Utils::reportError($e->getMessage(), $outputFormat); } // Narrow down the given products to the requested page (if page info is given)
} // Create the tree of criteria objects that define the query if (!isset($_POST['Criteria'])) { Utils::reportError("POST does not contain 'Criteria' sub-array", $outputFormat); } if (!count($_POST['Criteria'])) { Utils::reportError("POST sub-array 'Criteria' contains no criteria", $outputFormat); } $rootIndex = isset($_POST['RootIndex']) ? intval($_POST['RootIndex']) : 0; try { $criteriaTree = Utils::createCriteriaTree($rootIndex, $queryTypes, null); } catch (Exception $e) { Utils::reportError($e->getMessage(), $outputFormat); } // Add criteria to query object $query = new CAS_Filemgr_Query(); $query->addCriterion($criteriaTree); // Perform the query and collect results $results = array(); try { if ($pagedResults) { $resultPage = $client->pagedQuery($query, $queryTypes[0], $pageNum); foreach ($resultPage->getPageProducts() as $p) { array_push($results, array('product' => $p)); } } else { foreach ($queryTypes as $type) { foreach ($client->query($query, $type) as $p) { array_push($results, array('product' => $p)); } }