CRM-12133 - api/v3/CustomSearch - Fix option_group_id error
[civicrm-core.git] / api / v3 / CustomSearch.php
1 <?php
2
3 /**
4 * Retrieve a CustomSearches
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_custom_search_get($params) {
18 require_once 'api/v3/OptionValue.php';
19 $params['option_group_id'] = CRM_Core_DAO::getFieldValue(
20 'CRM_Core_DAO_OptionGroup', 'custom_search', 'id', 'name'
21 );
22 return civicrm_api3_option_value_get($params);
23 }
24
25 /**
26 * Add a CustomSearch
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_custom_search_create($params) {
37 require_once 'api/v3/OptionValue.php';
38 $params['option_group_id'] = CRM_Core_DAO::getFieldValue(
39 'CRM_Core_DAO_OptionGroup', 'custom_search', 'id', 'name'
40 );
41 // empirically, class name goes to both 'name' and 'label'
42 if (array_key_exists('name', $params)) {
43 $params['label'] = $params['name'];
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_custom_search_create_spec(&$params) {
55 require_once 'api/v3/OptionValue.php';
56 _civicrm_api3_option_value_create_spec($params);
57 $params['option_group_id']['api.default'] = CRM_Core_DAO::getFieldValue(
58 'CRM_Core_DAO_OptionGroup', 'custom_search', 'id', 'name'
59 );
60 $params['name']['api.aliases'] = array('class_name');
61 }
62
63 /**
64 * Deletes an existing ReportTemplate
65 *
66 * @param array $params
67 *
68 * {@example ReportTemplateDelete.php 0}
69 *
70 * @return array Api result
71 * {@getfields ReportTemplate_create}
72 * @access public
73 */
74 function civicrm_api3_custom_search_delete($params) {
75 require_once 'api/v3/OptionValue.php';
76 return civicrm_api3_option_value_delete($params);
77 }