return $parsedString;
}
+ /**
+ * Preview export output.
+ *
+ * @param int $limit
+ * @return array
+ */
+ public function getPreview($limit) {
+ $rows = [];
+ list($outputColumns, $metadata) = $this->getExportStructureArrays();
+ $query = $this->runQuery([], '');
+ CRM_Core_DAO::disableFullGroupByMode();
+ $result = CRM_Core_DAO::executeQuery($query[1] . ' LIMIT ' . (int) $limit);
+ CRM_Core_DAO::reenableFullGroupByMode();
+ while ($result->fetch()) {
+ $rows[] = $this->buildRow($query[0], $result, $outputColumns, $metadata, [], []);
+ }
+ return $rows;
+ }
+
}
}
}
+ /**
+ * Test get preview function on export processor.
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testExportGetPreview() {
+ $this->setUpContactExportData();
+ $fields = [
+ ['Individual', 'first_name'],
+ ['Individual', 'last_name'],
+ ['Individual', 'street_address', 1],
+ ['Individual', 'city', 1],
+ ['Individual', 'country', 1],
+ ['Individual', 'email', 1],
+ ];
+ $mappedFields = [];
+ foreach ($fields as $field) {
+ $mappedFields[] = CRM_Core_BAO_Mapping::getMappingParams([], $field);
+ }
+ $processor = new CRM_Export_BAO_ExportProcessor(FALSE, $mappedFields,
+ 'AND');
+ $processor->setComponentClause('contact_a.id IN (' . implode(',', $this->contactIDs) . ')');
+ $result = $processor->getPreview(2);
+ $this->assertEquals([
+ [
+ 'first_name' => 'Anthony',
+ 'last_name' => 'Anderson',
+ 'Home-street_address' => 'Ambachtstraat 23',
+ 'Home-city' => 'Brummen',
+ 'Home-country' => 'Netherlands',
+ 'Home-email' => 'home@example.com',
+ ],
+ [
+ 'first_name' => 'Anthony',
+ 'last_name' => 'Anderson',
+ 'Home-street_address' => '',
+ 'Home-city' => '',
+ 'Home-country' => '',
+ 'Home-email' => 'anthony_anderson@civicrm.org',
+ ],
+ ], $result);
+ }
+
}