From: Eileen McNaughton Date: Tue, 28 Jan 2014 00:18:55 +0000 (+1300) Subject: CRM-14137 report_template api - add ability to retrieve related metadata X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=7cab1323b6b90a2fbddf2546d7e7f31d65ffad7d;p=civicrm-core.git CRM-14137 report_template api - add ability to retrieve related metadata ---------------------------------------- * CRM-14137: Report_template.getrows api - allow retrieval of metadata at the top level http://issues.civicrm.org/jira/browse/CRM-14137 --- diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index aa92d7b85b..c8db44a89d 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -378,7 +378,7 @@ class CRM_Report_Form extends CRM_Core_Form { if (empty($this->_instanceValues)) { CRM_Core_Error::fatal("Report could not be loaded."); } - + $this->_title = $this->_instanceValues['title']; if (!empty($this->_instanceValues['permission']) && (!(CRM_Core_Permission::check($this->_instanceValues['permission']) || CRM_Core_Permission::check('administer Reports') @@ -812,6 +812,13 @@ class CRM_Report_Form extends CRM_Core_Form { function getDefaultValues() { return $this->_defaults; } + /** + * Getter for $_title + * @return string $_title + */ + function getTitle() { + return $this->_title; + } function addColumns() { $options = array(); diff --git a/api/v3/ReportTemplate.php b/api/v3/ReportTemplate.php index b52cefa15f..782190bd2d 100644 --- a/api/v3/ReportTemplate.php +++ b/api/v3/ReportTemplate.php @@ -87,8 +87,8 @@ function civicrm_api3_report_template_delete($params) { * @access public */ function civicrm_api3_report_template_getrows($params) { - list($rows, $instance) = _civicrm_api3_report_template_getrows($params); - return civicrm_api3_create_success($rows, $params, 'report_template'); + list($rows, $instance, $labels) = _civicrm_api3_report_template_getrows($params); + return civicrm_api3_create_success($rows, $params, 'report_template', 'getrows', CRM_Core_DAO::$_nullObject, $labels); } function _civicrm_api3_report_template_getrows($params) { @@ -113,13 +113,19 @@ function _civicrm_api3_report_template_getrows($params) { $reportInstance->setOffsetValue($options['offset']); $reportInstance->beginPostProcessCommon(); $sql = $reportInstance->buildQuery(); - $rows = array(); + $rows = $metadata = array(); $reportInstance->buildRows($sql, $rows); - return array($rows, $reportInstance); + $metadata['title'] = $reportInstance->getTitle(); + foreach ($reportInstance->_columnHeaders as $key => $header) { + //would be better just to expect reports to provide titles but reports are not consistent + //NB I think these are already translated + $metadata['labels'][$key] = !empty($header['title']) ? $header['title'] : ''; + } + return array($rows, $reportInstance, $metadata); } function civicrm_api3_report_template_getstatistics($params) { - list($rows, $reportInstance) = _civicrm_api3_report_template_getrows($params); + list($rows, $reportInstance, $labels) = _civicrm_api3_report_template_getrows($params); $stats = $reportInstance->statistics($rows); return civicrm_api3_create_success($stats, $params, 'report_template'); } diff --git a/api/v3/examples/ReportTemplate/Getrows.php b/api/v3/examples/ReportTemplate/Getrows.php index 6b29966390..9b2fe93fff 100644 --- a/api/v3/examples/ReportTemplate/Getrows.php +++ b/api/v3/examples/ReportTemplate/Getrows.php @@ -47,6 +47,14 @@ function report_template_getrows_expectedresult(){ 'civicrm_country_name' => 'United States', ), ), + 'title' => '', + 'labels' => array( + 'civicrm_contact_sort_name' => 'Contact Name', + 'civicrm_contact_id' => 'Internal Contact ID', + 'civicrm_address_street_address' => 'Street Address', + 'civicrm_address_city' => 'City', + 'civicrm_country_name' => 'Country', + ), ); return $expectedResult; diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index cc25e90dce..495edee312 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -118,6 +118,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { $result = $this->callAPIAndDocument('report_template', 'getrows', array( 'report_id' => 'contact/summary', ), __FUNCTION__, __FILE__, $description, 'Getrows', 'getrows'); + $this->assertEquals('Contact Name', $result['labels']['civicrm_contact_sort_name']); //the second part of this test has been commented out because it relied on the db being reset to // it's base state