Cleanup api3 docblocks
[civicrm-core.git] / api / v3 / CustomGroup.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
731a0992 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
c28e1768 29 * This api exposes CiviCRM custom group.
6a488035
TO
30 *
31 * @package CiviCRM_APIv3
32 * @subpackage API_CustomGroup
33 *
6a488035
TO
34 */
35
6a488035 36/**
9d32e6f7
EM
37 * Use this API to create a new group.
38 *
39 * The 'extends' value accepts an array or a comma separated string.
6a488035 40 * e.g array(
d1b0d05e 41 * 'Individual','Contact') or 'Individual,Contact'
6a488035
TO
42 * See the CRM Data Model for custom_group property definitions
43 * $params['class_name'] is a required field, class being extended.
44 *
16b10e64 45 * @param array $params
2e66abf8 46 * Array per getfields metadata.
6a488035 47 *
72b3a70c 48 * @return array
6a488035 49 * @todo $params['extends'] is array format - is that std compatible
6a488035
TO
50 */
51function civicrm_api3_custom_group_create($params) {
882e0216 52 if (isset($params['extends']) && is_string($params['extends'])) {
6a488035
TO
53 $extends = explode(",", $params['extends']);
54 unset($params['extends']);
55 $params['extends'] = $extends;
56 }
57 if (!isset($params['extends'][0]) || !trim($params['extends'][0])) {
58 return civicrm_api3_create_error("First item in params['extends'] must be a class name (e.g. 'Contact').");
59 }
60 if (isset($params['extends_entity_column_value']) && !is_array($params['extends_entity_column_value'])) {
61 // BAO fails if this is a string, but API getFields says this must be a string, so we'll do a double backflip
62 $params['extends_entity_column_value'] = CRM_Utils_Array::explodePadded($params['extends_entity_column_value']);
63 }
64
ea12ce50 65 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
6a488035
TO
66}
67
11e09c59 68/**
0aa0303c 69 * Adjust Metadata for Create action.
6a488035 70 *
cf470720
TO
71 * @param array $params
72 * Array or parameters determined by getfields.
6a488035
TO
73 */
74function _civicrm_api3_custom_group_create_spec(&$params) {
75 $params['extends']['api.required'] = 1;
76 $params['title']['api.required'] = 1;
77 $params['style']['api.default'] = 'Inline';
46b88fe1 78 $params['is_active']['api.default'] = 1;
6a488035
TO
79}
80
81/**
82 * Use this API to delete an existing group.
83 *
decce855 84 * @param array $params
6a488035 85 *
decce855 86 * @return array
c23f45d3 87 */
6a488035 88function civicrm_api3_custom_group_delete($params) {
6a488035
TO
89 $values = new CRM_Core_DAO_CustomGroup();
90 $values->id = $params['id'];
91 $values->find(TRUE);
92
6a488035
TO
93 $result = CRM_Core_BAO_CustomGroup::deleteGroup($values, TRUE);
94 return $result ? civicrm_api3_create_success() : civicrm_api3_create_error('Error while deleting custom group');
95}
96
97/**
2e66abf8 98 * API to get existing custom fields.
6a488035 99 *
cf470720 100 * @param array $params
2e66abf8 101 * Array per getfields metadata.
6a488035 102 *
77b97be7 103 * @return array
ae5ffbb7 104 */
6a488035
TO
105function civicrm_api3_custom_group_get($params) {
106 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
107}
108
5322ae12 109/**
9d32e6f7
EM
110 * CRM-15191 - Hack to ensure the cache gets cleared after updating a custom group.
111 *
d0997921 112 * @param array $params
2e66abf8 113 * Array per getfields metadata.
9d32e6f7 114 *
645ee340 115 * @return array
5322ae12
CW
116 */
117function civicrm_api3_custom_group_setvalue($params) {
118 require_once 'api/v3/Generic/Setvalue.php';
119 $result = civicrm_api3_generic_setValue(array("entity" => 'custom_group', 'params' => $params));
120 if (empty($result['is_error'])) {
121 CRM_Utils_System::flushCache();
122 }
123 return $result;
124}