| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 6 | | This work is published under the GNU AGPLv3 license with some | |
| 7 | | permitted exceptions and without any warranty. For full license | |
| 8 | | and copyright information, see https://civicrm.org/licensing | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * This api exposes CiviCRM contact types and sub-types. |
| 14 | * |
| 15 | * CiviCRM comes with 3 primary contact types - Individual, Organization & Household. |
| 16 | * Changing these is not advised, but sub_types can be created with this api. |
| 17 | * Pass 'parent_id' param to specify which base type a new sub_type extends. |
| 18 | * |
| 19 | * @package CiviCRM_APIv3 |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * Create/update ContactType. |
| 24 | * |
| 25 | * This API is used to create new ContactType or update any of the existing |
| 26 | * In case of updating existing ContactType, id of that particular ContactType must |
| 27 | * be in $params array. |
| 28 | * |
| 29 | * @param array $params |
| 30 | * Array per getfields metadata. |
| 31 | * |
| 32 | * @return array |
| 33 | * ContactType array |
| 34 | */ |
| 35 | function civicrm_api3_contact_type_create($params) { |
| 36 | civicrm_api3_verify_mandatory($params, _civicrm_api3_get_DAO(__FUNCTION__), ['name', 'parent_id']); |
| 37 | |
| 38 | if (empty($params['id'])) { |
| 39 | if (!array_key_exists('label', $params)) { |
| 40 | $params['label'] = $params['name']; |
| 41 | } |
| 42 | if (!array_key_exists('is_active', $params)) { |
| 43 | $params['is_active'] = TRUE; |
| 44 | } |
| 45 | $params['name'] = CRM_Utils_String::munge($params['name']); |
| 46 | } |
| 47 | |
| 48 | return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'ContactType'); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Returns array of contact_types matching a set of one or more properties. |
| 53 | * |
| 54 | * @param array $params |
| 55 | * One or more valid property_name=>value pairs. |
| 56 | * If $params is set as null, all contact_types will be returned |
| 57 | * |
| 58 | * @return array |
| 59 | * Array of matching contact_types |
| 60 | */ |
| 61 | function civicrm_api3_contact_type_get($params) { |
| 62 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Delete an existing ContactType. |
| 67 | * |
| 68 | * This method is used to delete any existing ContactType given its id. |
| 69 | * |
| 70 | * @param array $params |
| 71 | * [id] |
| 72 | * |
| 73 | * @return array |
| 74 | * API Result Array |
| 75 | */ |
| 76 | function civicrm_api3_contact_type_delete($params) { |
| 77 | return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
| 78 | } |