Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
1f4ea726 | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
c28e1768 | 29 | * This api exposes CiviCRM profile field. |
6a488035 TO |
30 | * |
31 | * @package CiviCRM_APIv3 | |
6a488035 TO |
32 | */ |
33 | ||
6a488035 TO |
34 | /** |
35 | * Defines 'uf field' within a group. | |
36 | * | |
16b10e64 | 37 | * @param array $params |
2e66abf8 | 38 | * Array per getfields metadata. |
6a488035 | 39 | * |
7e42d294 | 40 | * @throws API_Exception |
7e42d294 | 41 | * |
a6c01b45 | 42 | * @return array |
72b3a70c | 43 | * Newly created $ufFieldArray |
6a488035 TO |
44 | */ |
45 | function civicrm_api3_uf_field_create($params) { | |
c8ec6bbf | 46 | return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
6a488035 TO |
47 | } |
48 | ||
49 | /** | |
9d32e6f7 | 50 | * Adjust metadata for civicrm_uf_field create. |
6a488035 | 51 | * |
c490a46a | 52 | * @param array $params |
6a488035 TO |
53 | */ |
54 | function _civicrm_api3_uf_field_create_spec(&$params) { | |
8114c378 SB |
55 | $params['field_name']['api.required'] = TRUE; |
56 | $params['uf_group_id']['api.required'] = TRUE; | |
57 | ||
6a488035 | 58 | $params['option.autoweight'] = array( |
b2ed8e73 CW |
59 | 'title' => "Auto Weight", |
60 | 'description' => "Automatically adjust weights in UFGroup to align with UFField", | |
7e42d294 | 61 | 'type' => CRM_Utils_Type::T_BOOLEAN, |
62 | 'api.default' => TRUE, | |
6a488035 | 63 | ); |
6616c349 | 64 | $params['is_active']['api.default'] = TRUE; |
6a488035 TO |
65 | } |
66 | ||
67 | /** | |
22242c87 | 68 | * Returns array of uf groups (profiles) matching a set of one or more group properties. |
6a488035 | 69 | * |
cf470720 | 70 | * @param array $params |
9d32e6f7 | 71 | * Array per getfields metadata. |
6a488035 | 72 | * |
a6c01b45 | 73 | * @return array |
6a488035 TO |
74 | */ |
75 | function civicrm_api3_uf_field_get($params) { | |
76 | return _civicrm_api3_basic_get('CRM_Core_BAO_UFField', $params); | |
77 | } | |
78 | ||
79 | /** | |
9d32e6f7 | 80 | * Delete uf field. |
6a488035 | 81 | * |
c490a46a | 82 | * @param array $params |
7e42d294 | 83 | * |
84 | * @throws API_Exception | |
6a488035 | 85 | * |
72b3a70c | 86 | * @return array |
6a488035 TO |
87 | */ |
88 | function civicrm_api3_uf_field_delete($params) { | |
89 | $fieldId = $params['id']; | |
90 | ||
91 | $ufGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFField', $fieldId, 'uf_group_id'); | |
92 | if (!$ufGroupId) { | |
3f1a97cd | 93 | throw new API_Exception('Invalid value for field_id.'); |
6a488035 TO |
94 | } |
95 | ||
96 | $result = CRM_Core_BAO_UFField::del($fieldId); | |
97 | ||
98 | $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($ufGroupId, TRUE); | |
99 | CRM_Core_BAO_UFGroup::updateGroupTypes($ufGroupId, $fieldsType); | |
100 | ||
101 | return civicrm_api3_create_success($result, $params); | |
102 | } | |
645ee340 | 103 | |
7e42d294 | 104 | /** |
22242c87 EM |
105 | * Field id accepted for backward compatibility - unset required on id. |
106 | * | |
d0997921 | 107 | * @param array $params |
6a488035 TO |
108 | */ |
109 | function _civicrm_api3_uf_field_delete_spec(&$params) { | |
110 | // legacy support for field_id | |
111 | $params['id']['api.aliases'] = array('field_id'); | |
112 | } |