/** * @param ReadByQuery $query * @param int $maxTotalCount * @param array $params Overriding params * * @return ArrayIterator * @throws ResultException */ public function executeQuery(ReadByQuery $query, $maxTotalCount = self::DEFAULT_MAX_TOTAL_COUNT, array $params = []) { $this->setMaxTotalCount($maxTotalCount); $content = new Content([$query]); $response = parent::execute($content, false, null, false, $params); $result = $response->getOperation()->getResult(); if ($result->getStatus() !== 'success') { throw new ResultException('An error occurred trying to get query records', $result->getErrors()); } if ($result->getTotalCount() > $this->getMaxTotalCount()) { throw new ResultException('Query result totalcount of ' . $result->getTotalCount() . ' exceeds max totalcount parameter of ' . $this->getMaxTotalCount()); } $records = new ArrayIterator(); foreach ($result->getDataArray() as $record) { $records->append($record); } while ($result->getNumRemaining() > 0) { // Do readMore's with the resultId until number remaining is zero $readMore = new ReadMore(); $readMore->setResultId($result->getResultId()); $content = new Content([$readMore]); $response = parent::execute($content, false, null, false, $params); $result = $response->getOperation()->getResult(); if ($result->getStatus() !== 'success') { throw new ResultException('An error occurred trying to query subsequent records', $result->getErrors()); } foreach ($result->getDataArray() as $record) { $records->append($record); } } $records->rewind(); return $records; }
/** * @covers Intacct\Functions\Common\ReadMore::writeXml */ public function testParamOverrides() { $expected = <<<EOF <?xml version="1.0" encoding="UTF-8"?> <function controlid="unittest"> <readMore> <resultId>6465763031VyprCMCoHYQAAGr@aRsAAAAU4</resultId> </readMore> </function> EOF; $xml = new XMLWriter(); $xml->openMemory(); $xml->setIndent(true); $xml->setIndentString(' '); $xml->startDocument(); $readMore = new ReadMore('unittest'); $readMore->setResultId('6465763031VyprCMCoHYQAAGr@aRsAAAAU4'); $readMore->writeXml($xml); $this->assertXmlStringEqualsXmlString($expected, $xml->flush()); }