Merge pull request #2236 from eileenmcnaughton/CRM-14008
[civicrm-core.git] / api / v3 / ReportTemplate.php
1 <?php
2
3 /**
4 * Retrieve a report template
5 *
6 * FIXME This is a bare-minimum placeholder
7 *
8 * @param array $ params input parameters
9 *
10 * {@example OptionValueGet.php 0}
11 * @example OptionValueGet.php
12 *
13 * @return array details of found Option Values
14 * {@getfields OptionValue_get}
15 * @access public
16 */
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'
21 );
22 return civicrm_api3_option_value_get($params);
23 }
24
25 /**
26 * Add a OptionValue. OptionValues are used to classify CRM entities (including Contacts, Groups and Actions).
27 *
28 * Allowed @params array keys are:
29 *
30 * {@example OptionValueCreate.php}
31 *
32 * @return array of newly created option_value property values.
33 * {@getfields OptionValue_create}
34 * @access public
35 */
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'
40 );
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);
44 }
45 return civicrm_api3_option_value_create($params);
46 }
47
48 /**
49 * Adjust Metadata for Create action
50 *
51 * The metadata is used for setting defaults, documentation & validation
52 * @param array $params array or parameters determined by getfields
53 */
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'
61 );
62 // $params['component']['api.required'] = TRUE;
63 }
64
65 /**
66 * Deletes an existing ReportTemplate
67 *
68 * @param array $params
69 *
70 * {@example ReportTemplateDelete.php 0}
71 *
72 * @return array Api result
73 * {@getfields ReportTemplate_create}
74 * @access public
75 */
76 function civicrm_api3_report_template_delete($params) {
77 require_once 'api/v3/OptionValue.php';
78 return civicrm_api3_option_value_delete($params);
79 }
80
81 /**
82 * Retrieve rows from a report template
83 *
84 * @param array $params input parameters
85 *
86 * @return array details of found instances
87 * @access public
88 */
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');
92 }
93
94 function _civicrm_api3_report_template_getrows($params) {
95 $class = civicrm_api3('option_value', 'getvalue', array(
96 'option_group_id' => 'report_template',
97 'return' => 'name',
98 'value' => $params['report_id'],
99 )
100 );
101
102 $reportInstance = new $class();
103 if(!empty($params['instance_id'])) {
104 $reportInstance->setID($params['instance_id']);
105 }
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();
113 $rows = array();
114 $reportInstance->buildRows($sql, $rows);
115 return array($rows, $reportInstance);
116 }
117
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');
122 }
123 /**
124 * Retrieve rows from a report template
125 *
126 * @param array $params input parameters
127 *
128 * @return array details of found instances
129 * @access public
130 */
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',
135 );
136 }
137
138 /*
139 function civicrm_api3_report_template_getfields($params) {
140 return civicrm_api3_create_success(array(
141 'id' => array(
142 'name' => 'id',
143 'type' => 1,
144 'required' => 1,
145 ),
146 'option_group_id' => array(
147 'name' => 'option_group_id',
148 'type' => 1,
149 'required' => 1,
150 'FKClassName' => 'CRM_Core_DAO_OptionGroup',
151 ),
152 'label' => array(
153 'name' => 'label',
154 'type' => 2,
155 'title' => 'Option Label',
156 'required' => 1,
157 'maxlength' => 255,
158 'size' => 45,
159 ),
160 'value' => array(
161 'name' => 'value',
162 'type' => 2,
163 'title' => 'Option Value',
164 'required' => 1,
165 'maxlength' => 512,
166 'size' => 45,
167 ),
168 'name' => array(
169 'name' => 'name',
170 'type' => 2,
171 'title' => 'Option Name',
172 'maxlength' => 255,
173 'size' => 45,
174 'import' => 1,
175 'where' => 'civicrm_option_value.name',
176 'export' => 1,
177 ),
178 'grouping' => array(
179 'name' => 'grouping',
180 'type' => 2,
181 'title' => 'Option Grouping Name',
182 'maxlength' => 255,
183 'size' => 45,
184 ),
185 'filter' => array(
186 'name' => 'filter',
187 'type' => 1,
188 'title' => 'Filter',
189 ),
190 'is_default' => array(
191 'name' => 'is_default',
192 'type' => 16,
193 ),
194 'weight' => array(
195 'name' => 'weight',
196 'type' => 1,
197 'title' => 'Weight',
198 'required' => 1,
199 ),
200 'description' => array(
201 'name' => 'description',
202 'type' => 32,
203 'title' => 'Description',
204 'rows' => 8,
205 'cols' => 60,
206 ),
207 'is_optgroup' => array(
208 'name' => 'is_optgroup',
209 'type' => 16,
210 ),
211 'is_reserved' => array(
212 'name' => 'is_reserved',
213 'type' => 16,
214 ),
215 'is_active' => array(
216 'name' => 'is_active',
217 'type' => 16,
218 ),
219 'component_id' => array(
220 'name' => 'component_id',
221 'type' => 1,
222 'FKClassName' => 'CRM_Core_DAO_Component',
223 ),
224 'domain_id' => array(
225 'name' => 'domain_id',
226 'type' => 1,
227 'FKClassName' => 'CRM_Core_DAO_Domain',
228 ),
229 'visibility_id' => array(
230 'name' => 'visibility_id',
231 'type' => 1,
232 'default' => 'UL',
233 ),
234 ));
235 }*/