Merge pull request #17656 from civicrm/5.27
[civicrm-core.git] / api / v3 / ContactType.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
a30c801b 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
a30c801b
TO
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 |
6a488035
TO
9 +--------------------------------------------------------------------+
10 */
11
12/**
b081365f
CW
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.
6a488035
TO
18 *
19 * @package CiviCRM_APIv3
6a488035
TO
20 */
21
6a488035 22/**
244bbdd8 23 * Create/update ContactType.
6a488035 24 *
244bbdd8
CW
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
6a488035
TO
27 * be in $params array.
28 *
cf470720 29 * @param array $params
2e66abf8 30 * Array per getfields metadata.
6a488035 31 *
a6c01b45 32 * @return array
244bbdd8 33 * ContactType array
6a488035
TO
34 */
35function civicrm_api3_contact_type_create($params) {
cf8f0fff 36 civicrm_api3_verify_mandatory($params, _civicrm_api3_get_DAO(__FUNCTION__), ['name', 'parent_id']);
0f77a625 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']);
6a488035
TO
46 }
47
ddaf2161 48 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'ContactType');
6a488035
TO
49}
50
51/**
c28e1768 52 * Returns array of contact_types matching a set of one or more properties.
6a488035 53 *
cf470720 54 * @param array $params
c28e1768
CW
55 * One or more valid property_name=>value pairs.
56 * If $params is set as null, all contact_types will be returned
6a488035 57 *
a6c01b45 58 * @return array
72b3a70c 59 * Array of matching contact_types
6a488035
TO
60 */
61function civicrm_api3_contact_type_get($params) {
6a488035
TO
62 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
63}
64
65/**
244bbdd8 66 * Delete an existing ContactType.
6a488035 67 *
244bbdd8 68 * This method is used to delete any existing ContactType given its id.
6a488035 69 *
cf470720 70 * @param array $params
c28e1768 71 * [id]
6a488035 72 *
a6c01b45 73 * @return array
72b3a70c 74 * API Result Array
6a488035
TO
75 */
76function civicrm_api3_contact_type_delete($params) {
77 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
78}