4 * Retrieve a report template
6 * FIXME This is a bare-minimum placeholder
8 * @param array $ params input parameters
10 * {@example OptionValueGet.php 0}
11 * @example OptionValueGet.php
13 * @return array details of found Option Values
14 * {@getfields OptionValue_get}
17 function civicrm_api3_report_template_get($params) {
18 require_once 'api/v3/OptionValue.php';
19 $params['option_group_id'] = CRM_Core_DAO
::getFieldValue(
20 'CRM_Core_DAO_OptionGroup', 'report_template', 'id', 'name'
22 return civicrm_api3_option_value_get($params);
26 * Add a OptionValue. OptionValues are used to classify CRM entities (including Contacts, Groups and Actions).
28 * Allowed @params array keys are:
30 * {@example OptionValueCreate.php}
32 * @return array of newly created option_value property values.
33 * {@getfields OptionValue_create}
36 function civicrm_api3_report_template_create($params) {
37 require_once 'api/v3/OptionValue.php';
38 $params['option_group_id'] = CRM_Core_DAO
::getFieldValue(
39 'CRM_Core_DAO_OptionGroup', 'report_template', 'id', 'name'
41 if (!empty($params['component_id']) && !is_numeric($params['component_id'])) {
42 $components = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_OptionValue', 'component_id', array('onlyActive' => FALSE, 'labelColumn' => 'name'));
43 $params['component_id'] = array_search($params['component_id'], $components);
45 return civicrm_api3_option_value_create($params);
49 * Adjust Metadata for Create action
51 * The metadata is used for setting defaults, documentation & validation
52 * @param array $params array or parameters determined by getfields
54 function _civicrm_api3_report_template_create_spec(&$params) {
55 require_once 'api/v3/OptionValue.php';
56 _civicrm_api3_option_value_create_spec($params);
57 $params['value']['api.aliases'] = array('report_url');
58 $params['name']['api.aliases'] = array('class_name');
59 $params['option_group_id']['api.default'] = CRM_Core_DAO
::getFieldValue(
60 'CRM_Core_DAO_OptionGroup', 'report_template', 'id', 'name'
62 // $params['component']['api.required'] = TRUE;
66 * Deletes an existing ReportTemplate
68 * @param array $params
70 * {@example ReportTemplateDelete.php 0}
72 * @return array Api result
73 * {@getfields ReportTemplate_create}
76 function civicrm_api3_report_template_delete($params) {
77 require_once 'api/v3/OptionValue.php';
78 return civicrm_api3_option_value_delete($params);
82 * Retrieve rows from a report template
84 * @param array $params input parameters
86 * @return array details of found instances
89 function civicrm_api3_report_template_getrows($params) {
90 list($rows, $instance) = _civicrm_api3_report_template_getrows($params);
91 return civicrm_api3_create_success($rows, $params, 'report_template');
94 function _civicrm_api3_report_template_getrows($params) {
95 $class = civicrm_api3('option_value', 'getvalue', array(
96 'option_group_id' => 'report_template',
98 'value' => $params['report_id'],
102 $reportInstance = new $class();
103 if(!empty($params['instance_id'])) {
104 $reportInstance->setID($params['instance_id']);
106 $reportInstance->setParams($params);
107 $reportInstance->noController
= TRUE;
108 $reportInstance->preProcess();
109 $reportInstance->setDefaultValues(FALSE);
110 $reportInstance->setParams(array_merge($reportInstance->getDefaultValues(), $params));
111 $reportInstance->beginPostProcessCommon();
112 $sql = $reportInstance->buildQuery();
114 $reportInstance->buildRows($sql, $rows);
115 return array($rows, $reportInstance);
118 function civicrm_api3_report_template_getstatistics($params) {
119 list($rows, $reportInstance) = _civicrm_api3_report_template_getrows($params);
120 $stats = $reportInstance->statistics($rows);
121 return civicrm_api3_create_success($stats, $params, 'report_template');
124 * Retrieve rows from a report template
126 * @param array $params input parameters
128 * @return array details of found instances
131 function _civicrm_api3_report_template_getrows_spec(&$params) {
132 $params['report_id'] = array(
133 'api.required' => TRUE,
134 'title' => 'Report ID - eg. member/lapse',
139 function civicrm_api3_report_template_getfields($params) {
140 return civicrm_api3_create_success(array(
146 'option_group_id' => array(
147 'name' => 'option_group_id',
150 'FKClassName' => 'CRM_Core_DAO_OptionGroup',
155 'title' => 'Option Label',
163 'title' => 'Option Value',
171 'title' => 'Option Name',
175 'where' => 'civicrm_option_value.name',
179 'name' => 'grouping',
181 'title' => 'Option Grouping Name',
190 'is_default' => array(
191 'name' => 'is_default',
200 'description' => array(
201 'name' => 'description',
203 'title' => 'Description',
207 'is_optgroup' => array(
208 'name' => 'is_optgroup',
211 'is_reserved' => array(
212 'name' => 'is_reserved',
215 'is_active' => array(
216 'name' => 'is_active',
219 'component_id' => array(
220 'name' => 'component_id',
222 'FKClassName' => 'CRM_Core_DAO_Component',
224 'domain_id' => array(
225 'name' => 'domain_id',
227 'FKClassName' => 'CRM_Core_DAO_Domain',
229 'visibility_id' => array(
230 'name' => 'visibility_id',