Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | // $Id$ | |
3 | ||
4 | /* | |
5 | +--------------------------------------------------------------------+ | |
6 | | CiviCRM version 4.3 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
9 | +--------------------------------------------------------------------+ | |
10 | | This file is a part of CiviCRM. | | |
11 | | | | |
12 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
13 | | under the terms of the GNU Affero General Public License | | |
14 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
15 | | | | |
16 | | CiviCRM is distributed in the hope that it will be useful, but | | |
17 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
19 | | See the GNU Affero General Public License for more details. | | |
20 | | | | |
21 | | You should have received a copy of the GNU Affero General Public | | |
22 | | License and the CiviCRM Licensing Exception along | | |
23 | | with this program; if not, contact CiviCRM LLC | | |
24 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
25 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
26 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
27 | +--------------------------------------------------------------------+ | |
28 | */ | |
29 | ||
30 | /** | |
31 | * File for the CiviCRM APIv3 custom group functions | |
32 | * | |
33 | * @package CiviCRM_APIv3 | |
34 | * @subpackage API_CustomGroup | |
35 | * | |
36 | * @copyright CiviCRM LLC (c) 2004-2013 | |
37 | * @version $Id: CustomGroup.php 30879 2010-11-22 15:45:55Z shot $ | |
38 | */ | |
39 | ||
40 | /** | |
41 | * Most API functions take in associative arrays ( name => value pairs | |
42 | * as parameters. Some of the most commonly used parameters are | |
43 | * described below | |
44 | * | |
45 | * @param array $params an associative array used in construction | |
46 | * retrieval of the object | |
47 | * @todo missing get function | |
48 | * | |
49 | * | |
50 | */ | |
51 | ||
52 | /** | |
53 | * Use this API to create a new group. The 'extends' value accepts an array or a comma separated string. | |
54 | * e.g array( | |
55 | 'Individual','Contact') or 'Individual,Contact' | |
56 | * See the CRM Data Model for custom_group property definitions | |
57 | * $params['class_name'] is a required field, class being extended. | |
58 | * | |
59 | * @param $params array Associative array of property name/value pairs to insert in group. | |
60 | * {@getfields CustomGroup_create} | |
61 | * | |
62 | * @return Newly create custom_group object | |
63 | * @todo $params['extends'] is array format - is that std compatible | |
64 | * @access public | |
65 | */ | |
66 | function civicrm_api3_custom_group_create($params) { | |
67 | if (is_string($params['extends'])) { | |
68 | $extends = explode(",", $params['extends']); | |
69 | unset($params['extends']); | |
70 | $params['extends'] = $extends; | |
71 | } | |
72 | if (!isset($params['extends'][0]) || !trim($params['extends'][0])) { | |
73 | return civicrm_api3_create_error("First item in params['extends'] must be a class name (e.g. 'Contact')."); | |
74 | } | |
75 | if (isset($params['extends_entity_column_value']) && !is_array($params['extends_entity_column_value'])) { | |
76 | // BAO fails if this is a string, but API getFields says this must be a string, so we'll do a double backflip | |
77 | $params['extends_entity_column_value'] = CRM_Utils_Array::explodePadded($params['extends_entity_column_value']); | |
78 | } | |
79 | ||
80 | ||
81 | $customGroup = CRM_Core_BAO_CustomGroup::create($params); | |
82 | ||
83 | _civicrm_api3_object_to_array($customGroup, $values[$customGroup->id]); | |
84 | return civicrm_api3_create_success($values, $params, 'custom_group', $customGroup); | |
85 | } | |
86 | ||
87 | /* | |
88 | * Adjust Metadata for Create action | |
89 | * | |
90 | * @param array $params array or parameters determined by getfields | |
91 | */ | |
92 | function _civicrm_api3_custom_group_create_spec(&$params) { | |
93 | $params['extends']['api.required'] = 1; | |
94 | $params['title']['api.required'] = 1; | |
95 | $params['style']['api.default'] = 'Inline'; | |
96 | } | |
97 | ||
98 | /** | |
99 | * Use this API to delete an existing group. | |
100 | * | |
101 | * @param array id of the group to be deleted | |
102 | * | |
103 | * @return Null if success | |
104 | * @access public | |
105 | * {@getfields CustomGroup_delete} | |
106 | * @example CustomGroupDelete.php | |
107 | **/ | |
108 | function civicrm_api3_custom_group_delete($params) { | |
109 | ||
110 | $values = new CRM_Core_DAO_CustomGroup(); | |
111 | $values->id = $params['id']; | |
112 | $values->find(TRUE); | |
113 | ||
114 | require_once 'CRM/Core/BAO/CustomGroup.php'; | |
115 | $result = CRM_Core_BAO_CustomGroup::deleteGroup($values, TRUE); | |
116 | return $result ? civicrm_api3_create_success() : civicrm_api3_create_error('Error while deleting custom group'); | |
117 | } | |
118 | ||
119 | /** | |
120 | * Use this API to get existing custom fields. | |
121 | * | |
122 | * @param array $params Array to search on | |
123 | * | |
124 | * @access public | |
125 | * {@getfields CustomGroup_get} | |
126 | * @example CustomGroupGet.php | |
127 | **/ | |
128 | function civicrm_api3_custom_group_get($params) { | |
129 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
130 | } | |
131 |