Merge pull request #2367 from kurund/CRM-14082
[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 $options = _civicrm_api3_get_options_from_params($params, TRUE,'report_template','get');
112 $reportInstance->setLimitValue($options['limit']);
113 $reportInstance->setOffsetValue($options['offset']);
114 $reportInstance->beginPostProcessCommon();
115 $sql = $reportInstance->buildQuery();
116 $rows = array();
117 $reportInstance->buildRows($sql, $rows);
118 return array($rows, $reportInstance);
119 }
120
121 function civicrm_api3_report_template_getstatistics($params) {
122 list($rows, $reportInstance) = _civicrm_api3_report_template_getrows($params);
123 $stats = $reportInstance->statistics($rows);
124 return civicrm_api3_create_success($stats, $params, 'report_template');
125 }
126 /**
127 * Retrieve rows from a report template
128 *
129 * @param array $params input parameters
130 *
131 * @return array details of found instances
132 * @access public
133 */
134 function _civicrm_api3_report_template_getrows_spec(&$params) {
135 $params['report_id'] = array(
136 'api.required' => TRUE,
137 'title' => 'Report ID - eg. member/lapse',
138 );
139 }
140
141 /*
142 function civicrm_api3_report_template_getfields($params) {
143 return civicrm_api3_create_success(array(
144 'id' => array(
145 'name' => 'id',
146 'type' => 1,
147 'required' => 1,
148 ),
149 'option_group_id' => array(
150 'name' => 'option_group_id',
151 'type' => 1,
152 'required' => 1,
153 'FKClassName' => 'CRM_Core_DAO_OptionGroup',
154 ),
155 'label' => array(
156 'name' => 'label',
157 'type' => 2,
158 'title' => 'Option Label',
159 'required' => 1,
160 'maxlength' => 255,
161 'size' => 45,
162 ),
163 'value' => array(
164 'name' => 'value',
165 'type' => 2,
166 'title' => 'Option Value',
167 'required' => 1,
168 'maxlength' => 512,
169 'size' => 45,
170 ),
171 'name' => array(
172 'name' => 'name',
173 'type' => 2,
174 'title' => 'Option Name',
175 'maxlength' => 255,
176 'size' => 45,
177 'import' => 1,
178 'where' => 'civicrm_option_value.name',
179 'export' => 1,
180 ),
181 'grouping' => array(
182 'name' => 'grouping',
183 'type' => 2,
184 'title' => 'Option Grouping Name',
185 'maxlength' => 255,
186 'size' => 45,
187 ),
188 'filter' => array(
189 'name' => 'filter',
190 'type' => 1,
191 'title' => 'Filter',
192 ),
193 'is_default' => array(
194 'name' => 'is_default',
195 'type' => 16,
196 ),
197 'weight' => array(
198 'name' => 'weight',
199 'type' => 1,
200 'title' => 'Weight',
201 'required' => 1,
202 ),
203 'description' => array(
204 'name' => 'description',
205 'type' => 32,
206 'title' => 'Description',
207 'rows' => 8,
208 'cols' => 60,
209 ),
210 'is_optgroup' => array(
211 'name' => 'is_optgroup',
212 'type' => 16,
213 ),
214 'is_reserved' => array(
215 'name' => 'is_reserved',
216 'type' => 16,
217 ),
218 'is_active' => array(
219 'name' => 'is_active',
220 'type' => 16,
221 ),
222 'component_id' => array(
223 'name' => 'component_id',
224 'type' => 1,
225 'FKClassName' => 'CRM_Core_DAO_Component',
226 ),
227 'domain_id' => array(
228 'name' => 'domain_id',
229 'type' => 1,
230 'FKClassName' => 'CRM_Core_DAO_Domain',
231 ),
232 'visibility_id' => array(
233 'name' => 'visibility_id',
234 'type' => 1,
235 'default' => 'UL',
236 ),
237 ));
238 }*/