4 * Retrieve a report template
6 * FIXME This is a bare-minimum placeholder
10 * @internal param $array $ params input parameters
12 * {@example OptionValueGet.php 0}
13 * @example OptionValueGet.php
15 * @return array details of found Option Values
16 * {@getfields OptionValue_get}
19 function civicrm_api3_report_template_get($params) {
20 require_once 'api/v3/OptionValue.php';
21 $params['option_group_id'] = CRM_Core_DAO
::getFieldValue(
22 'CRM_Core_DAO_OptionGroup', 'report_template', 'id', 'name'
24 return civicrm_api3_option_value_get($params);
28 * Add a OptionValue. OptionValues are used to classify CRM entities (including Contacts, Groups and Actions).
30 * Allowed @params array keys are:
32 * {@example OptionValueCreate.php}
36 * @return array of newly created option_value property values.
37 * {@getfields OptionValue_create}
40 function civicrm_api3_report_template_create($params) {
41 require_once 'api/v3/OptionValue.php';
42 $params['option_group_id'] = CRM_Core_DAO
::getFieldValue(
43 'CRM_Core_DAO_OptionGroup', 'report_template', 'id', 'name'
45 if (!empty($params['component_id']) && !is_numeric($params['component_id'])) {
46 $components = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_OptionValue', 'component_id', array('onlyActive' => FALSE, 'labelColumn' => 'name'));
47 $params['component_id'] = array_search($params['component_id'], $components);
49 return civicrm_api3_option_value_create($params);
53 * Adjust Metadata for Create action
55 * The metadata is used for setting defaults, documentation & validation
56 * @param array $params array or parameters determined by getfields
58 function _civicrm_api3_report_template_create_spec(&$params) {
59 require_once 'api/v3/OptionValue.php';
60 _civicrm_api3_option_value_create_spec($params);
61 $params['value']['api.aliases'] = array('report_url');
62 $params['name']['api.aliases'] = array('class_name');
63 $params['option_group_id']['api.default'] = CRM_Core_DAO
::getFieldValue(
64 'CRM_Core_DAO_OptionGroup', 'report_template', 'id', 'name'
66 // $params['component']['api.required'] = TRUE;
70 * Deletes an existing ReportTemplate
72 * @param array $params
74 * {@example ReportTemplateDelete.php 0}
76 * @return array Api result
77 * {@getfields ReportTemplate_create}
80 function civicrm_api3_report_template_delete($params) {
81 require_once 'api/v3/OptionValue.php';
82 return civicrm_api3_option_value_delete($params);
86 * Retrieve rows from a report template
88 * @param array $params input parameters
90 * @return array details of found instances
93 function civicrm_api3_report_template_getrows($params) {
94 civicrm_api3_verify_one_mandatory($params, NULL, array('report_id', 'instance_id'));
95 list($rows, $instance, $metadata) = _civicrm_api3_report_template_getrows($params);
96 return civicrm_api3_create_success($rows, $params, 'report_template', 'getrows', CRM_Core_DAO
::$_nullObject, $metadata);
99 function _civicrm_api3_report_template_getrows($params) {
100 if(empty($params['report_id'])) {
101 $params['report_id'] = civicrm_api3('report_instance', 'getvalue', array('id' => $params['instance_id'], 'return' => 'report_id'));
104 $class = civicrm_api3('option_value', 'getvalue', array(
105 'option_group_id' => 'report_template',
107 'value' => $params['report_id'],
111 $reportInstance = new $class();
112 if(!empty($params['instance_id'])) {
113 $reportInstance->setID($params['instance_id']);
115 $reportInstance->setParams($params);
116 $reportInstance->noController
= TRUE;
117 $reportInstance->preProcess();
118 $reportInstance->setDefaultValues(FALSE);
119 $reportInstance->setParams(array_merge($reportInstance->getDefaultValues(), $params));
120 $options = _civicrm_api3_get_options_from_params($params, TRUE,'report_template','get');
121 $reportInstance->setLimitValue($options['limit']);
122 $reportInstance->setOffsetValue($options['offset']);
123 $reportInstance->beginPostProcessCommon();
124 $sql = $reportInstance->buildQuery();
125 $rows = $metadata = $requiredMetadata = array();
126 $reportInstance->buildRows($sql, $rows);
127 $requiredMetadata = array();
128 if(isset($params['options']) && !empty($params['options']['metadata'])) {
129 $requiredMetadata = $params['options']['metadata'];
130 if(in_array('title', $requiredMetadata)) {
131 $metadata['metadata']['title'] = $reportInstance->getTitle();
133 if(in_array('labels', $requiredMetadata)) {
134 foreach ($reportInstance->_columnHeaders
as $key => $header) {
135 //would be better just to expect reports to provide titles but reports are not consistent so we anticipate empty
136 //NB I think these are already translated
137 $metadata['metadata']['labels'][$key] = !empty($header['title']) ?
$header['title'] : '';
141 return array($rows, $reportInstance, $metadata);
144 function civicrm_api3_report_template_getstatistics($params) {
145 list($rows, $reportInstance, $metadata) = _civicrm_api3_report_template_getrows($params);
146 $stats = $reportInstance->statistics($rows);
147 return civicrm_api3_create_success($stats, $params, 'report_template', 'getstatistics', CRM_Core_DAO
::$_nullObject, $metadata);
150 * Retrieve rows from a report template
152 * @param array $params input parameters
154 * @return array details of found instances
157 function _civicrm_api3_report_template_getrows_spec(&$params) {
158 $params['report_id'] = array(
159 'title' => 'Report ID - eg. member/lapse',
164 function civicrm_api3_report_template_getfields($params) {
165 return civicrm_api3_create_success(array(
171 'option_group_id' => array(
172 'name' => 'option_group_id',
175 'FKClassName' => 'CRM_Core_DAO_OptionGroup',
180 'title' => 'Option Label',
188 'title' => 'Option Value',
196 'title' => 'Option Name',
200 'where' => 'civicrm_option_value.name',
204 'name' => 'grouping',
206 'title' => 'Option Grouping Name',
215 'is_default' => array(
216 'name' => 'is_default',
225 'description' => array(
226 'name' => 'description',
228 'title' => 'Description',
232 'is_optgroup' => array(
233 'name' => 'is_optgroup',
236 'is_reserved' => array(
237 'name' => 'is_reserved',
240 'is_active' => array(
241 'name' => 'is_active',
244 'component_id' => array(
245 'name' => 'component_id',
247 'FKClassName' => 'CRM_Core_DAO_Component',
249 'domain_id' => array(
250 'name' => 'domain_id',
252 'FKClassName' => 'CRM_Core_DAO_Domain',
254 'visibility_id' => array(
255 'name' => 'visibility_id',