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);
103 * @throws API_Exception
104 * @throws CiviCRM_API3_Exception
106 function _civicrm_api3_report_template_getrows($params) {
107 if(empty($params['report_id'])) {
108 $params['report_id'] = civicrm_api3('report_instance', 'getvalue', array('id' => $params['instance_id'], 'return' => 'report_id'));
111 $class = civicrm_api3('option_value', 'getvalue', array(
112 'option_group_id' => 'report_template',
114 'value' => $params['report_id'],
118 $reportInstance = new $class();
119 if(!empty($params['instance_id'])) {
120 $reportInstance->setID($params['instance_id']);
122 $reportInstance->setParams($params);
123 $reportInstance->noController
= TRUE;
124 $reportInstance->preProcess();
125 $reportInstance->setDefaultValues(FALSE);
126 $reportInstance->setParams(array_merge($reportInstance->getDefaultValues(), $params));
127 $options = _civicrm_api3_get_options_from_params($params, TRUE,'report_template','get');
128 $reportInstance->setLimitValue($options['limit']);
129 $reportInstance->setOffsetValue($options['offset']);
130 $reportInstance->beginPostProcessCommon();
131 $sql = $reportInstance->buildQuery();
132 $rows = $metadata = $requiredMetadata = array();
133 $reportInstance->buildRows($sql, $rows);
134 $requiredMetadata = array();
135 if(isset($params['options']) && !empty($params['options']['metadata'])) {
136 $requiredMetadata = $params['options']['metadata'];
137 if(in_array('title', $requiredMetadata)) {
138 $metadata['metadata']['title'] = $reportInstance->getTitle();
140 if(in_array('labels', $requiredMetadata)) {
141 foreach ($reportInstance->_columnHeaders
as $key => $header) {
142 //would be better just to expect reports to provide titles but reports are not consistent so we anticipate empty
143 //NB I think these are already translated
144 $metadata['metadata']['labels'][$key] = !empty($header['title']) ?
$header['title'] : '';
148 return array($rows, $reportInstance, $metadata);
156 function civicrm_api3_report_template_getstatistics($params) {
157 list($rows, $reportInstance, $metadata) = _civicrm_api3_report_template_getrows($params);
158 $stats = $reportInstance->statistics($rows);
159 return civicrm_api3_create_success($stats, $params, 'report_template', 'getstatistics', CRM_Core_DAO
::$_nullObject, $metadata);
162 * Retrieve rows from a report template
164 * @param array $params input parameters
166 * @return array details of found instances
169 function _civicrm_api3_report_template_getrows_spec(&$params) {
170 $params['report_id'] = array(
171 'title' => 'Report ID - eg. member/lapse',
176 function civicrm_api3_report_template_getfields($params) {
177 return civicrm_api3_create_success(array(
183 'option_group_id' => array(
184 'name' => 'option_group_id',
187 'FKClassName' => 'CRM_Core_DAO_OptionGroup',
192 'title' => 'Option Label',
200 'title' => 'Option Value',
208 'title' => 'Option Name',
212 'where' => 'civicrm_option_value.name',
216 'name' => 'grouping',
218 'title' => 'Option Grouping Name',
227 'is_default' => array(
228 'name' => 'is_default',
237 'description' => array(
238 'name' => 'description',
240 'title' => 'Description',
244 'is_optgroup' => array(
245 'name' => 'is_optgroup',
248 'is_reserved' => array(
249 'name' => 'is_reserved',
252 'is_active' => array(
253 'name' => 'is_active',
256 'component_id' => array(
257 'name' => 'component_id',
259 'FKClassName' => 'CRM_Core_DAO_Component',
261 'domain_id' => array(
262 'name' => 'domain_id',
264 'FKClassName' => 'CRM_Core_DAO_Domain',
266 'visibility_id' => array(
267 'name' => 'visibility_id',