X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2FReportTemplate.php;h=b52cefa15fe461d2c70c576992cfa097aa6e9533;hb=2f99f83c74220c235812465bc06792a9a0f98901;hp=86d748ccb3f77f6c9836f50582342b31f992cab1;hpb=968f346b48b512426bbbc41759ce409fae5af238;p=civicrm-core.git diff --git a/api/v3/ReportTemplate.php b/api/v3/ReportTemplate.php index 86d748ccb3..b52cefa15f 100644 --- a/api/v3/ReportTemplate.php +++ b/api/v3/ReportTemplate.php @@ -38,6 +38,10 @@ function civicrm_api3_report_template_create($params) { $params['option_group_id'] = CRM_Core_DAO::getFieldValue( 'CRM_Core_DAO_OptionGroup', 'report_template', 'id', 'name' ); + if (!empty($params['component_id']) && !is_numeric($params['component_id'])) { + $components = CRM_Core_PseudoConstant::get('CRM_Core_DAO_OptionValue', 'component_id', array('onlyActive' => FALSE, 'labelColumn' => 'name')); + $params['component_id'] = array_search($params['component_id'], $components); + } return civicrm_api3_option_value_create($params); } @@ -50,9 +54,11 @@ function civicrm_api3_report_template_create($params) { function _civicrm_api3_report_template_create_spec(&$params) { require_once 'api/v3/OptionValue.php'; _civicrm_api3_option_value_create_spec($params); - $params['weight']['api.default'] = 'next'; $params['value']['api.aliases'] = array('report_url'); $params['name']['api.aliases'] = array('class_name'); + $params['option_group_id']['api.default'] = CRM_Core_DAO::getFieldValue( + 'CRM_Core_DAO_OptionGroup', 'report_template', 'id', 'name' + ); // $params['component']['api.required'] = TRUE; } @@ -72,6 +78,66 @@ function civicrm_api3_report_template_delete($params) { return civicrm_api3_option_value_delete($params); } +/** + * Retrieve rows from a report template + * + * @param array $params input parameters + * + * @return array details of found instances + * @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'); +} + +function _civicrm_api3_report_template_getrows($params) { + $class = civicrm_api3('option_value', 'getvalue', array( + 'option_group_id' => 'report_template', + 'return' => 'name', + 'value' => $params['report_id'], + ) + ); + + $reportInstance = new $class(); + if(!empty($params['instance_id'])) { + $reportInstance->setID($params['instance_id']); + } + $reportInstance->setParams($params); + $reportInstance->noController = TRUE; + $reportInstance->preProcess(); + $reportInstance->setDefaultValues(FALSE); + $reportInstance->setParams(array_merge($reportInstance->getDefaultValues(), $params)); + $options = _civicrm_api3_get_options_from_params($params, TRUE,'report_template','get'); + $reportInstance->setLimitValue($options['limit']); + $reportInstance->setOffsetValue($options['offset']); + $reportInstance->beginPostProcessCommon(); + $sql = $reportInstance->buildQuery(); + $rows = array(); + $reportInstance->buildRows($sql, $rows); + return array($rows, $reportInstance); +} + +function civicrm_api3_report_template_getstatistics($params) { + list($rows, $reportInstance) = _civicrm_api3_report_template_getrows($params); + $stats = $reportInstance->statistics($rows); + return civicrm_api3_create_success($stats, $params, 'report_template'); +} +/** + * Retrieve rows from a report template + * + * @param array $params input parameters + * + * @return array details of found instances + * @access public + */ +function _civicrm_api3_report_template_getrows_spec(&$params) { + $params['report_id'] = array( + 'api.required' => TRUE, + 'title' => 'Report ID - eg. member/lapse', + ); +} + /* function civicrm_api3_report_template_getfields($params) { return civicrm_api3_create_success(array(