Skip to content

Commit

Permalink
Merge pull request #2419 from eileenmcnaughton/CRM-14137
Browse files Browse the repository at this point in the history
CRM-14137 , CRM-14138 , report_template.getrows api tidy up
  • Loading branch information
deepak-srivastava committed Feb 4, 2014
2 parents bcf4d0d + f68306a commit edbed2a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ function preProcessCommon() {
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')
Expand Down
2 changes: 1 addition & 1 deletion api/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function civicrm_api($entity, $action, $params, $extra = NULL) {
$result = isset($extra) ? $function($apiRequest['params'], $extra) : $function($apiRequest['params']);
}
else {
return civicrm_api3_create_error("API (" . $apiRequest['entity'] . "," . $apiRequest['action'] . ") does not exist (join the API team and implement it!)");
return civicrm_api3_create_error("API (" . $apiRequest['entity'] . ", " . $apiRequest['action'] . ") does not exist (join the API team and implement it!)");
}

// For output filtering, process $apiWrappers in reverse order
Expand Down
22 changes: 16 additions & 6 deletions api/v3/ReportTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@ 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');
civicrm_api3_verify_one_mandatory($params, NULL, array('report_id', 'instance_id'));
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) {
if(empty($params['report_id'])) {
$params['report_id'] = civicrm_api3('report_instance', 'getvalue', array('id' => $params['instance_id'], 'return' => 'report_id'));
}

$class = civicrm_api3('option_value', 'getvalue', array(
'option_group_id' => 'report_template',
'return' => 'name',
Expand All @@ -113,13 +118,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');
}
Expand All @@ -133,7 +144,6 @@ function civicrm_api3_report_template_getstatistics($params) {
*/
function _civicrm_api3_report_template_getrows_spec(&$params) {
$params['report_id'] = array(
'api.required' => TRUE,
'title' => 'Report ID - eg. member/lapse',
);
}
Expand Down
8 changes: 8 additions & 0 deletions api/v3/examples/ReportTemplate/Getrows.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion api/v3/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ function _civicrm_api3_api_check_permission($entity, $action, &$params, $throw =
*/
function _civicrm_api3_basic_get($bao_name, &$params, $returnAsSuccess = TRUE, $entity = "") {
$bao = new $bao_name();
_civicrm_api3_dao_set_filter($bao, $params, TRUE,$entity);
_civicrm_api3_dao_set_filter($bao, $params, TRUE, $entity);
if ($returnAsSuccess) {
return civicrm_api3_create_success(_civicrm_api3_dao_to_array($bao, $params, FALSE, $entity), $params, $entity);
}
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/api/v3/ReportTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ function testReportTemplateGetRowsContactSummary() {
$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
Expand Down

0 comments on commit edbed2a

Please sign in to comment.