Merge pull request #16545 from eileenmcnaughton/part_pend
[civicrm-core.git] / api / v3 / User.php
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 the user framework user account.
14 *
15 * @package CiviCRM_APIv3
16 */
17
18 /**
19 * Get details about the CMS User entity.
20 *
21 * @param array $params
22 *
23 * @return array
24 */
25 function civicrm_api3_user_get($params) {
26 if (empty($params['contact_id'])) {
27 $params['contact_id'] = civicrm_api3('UFMatch', 'getvalue', [
28 'uf_id' => $params['id'],
29 'domain_id' => CRM_Core_Config::domainID(),
30 'return' => 'contact_id',
31 ]);
32 }
33 $result = CRM_Core_Config::singleton()->userSystem->getUser($params['contact_id']);
34 $result['contact_id'] = $params['contact_id'];
35 return civicrm_api3_create_success(
36 [$result['id'] => $result],
37 $params,
38 'user',
39 'get'
40 );
41
42 }
43
44 /**
45 * Adjust Metadata for Get action.
46 *
47 * The metadata is used for setting defaults, documentation & validation.
48 *
49 * @param array $params
50 * Array of parameters determined by getfields.
51 */
52 function _civicrm_api3_user_get_spec(&$params) {
53 // At this stage contact-id is required - we may be able to loosen this.
54 $params['contact_id'] = [
55 'title' => 'Contact ID',
56 'type' => CRM_Utils_Type::T_INT,
57 'api.required' => 1,
58 ];
59 $params['id'] = [
60 'title' => 'CMS User ID',
61 'type' => CRM_Utils_Type::T_INT,
62 ];
63 $params['name'] = [
64 'title' => 'Username',
65 'type' => CRM_Utils_Type::T_STRING,
66 ];
67 }