Merge pull request #15475 from mecachisenros/externUrl
[civicrm-core.git] / api / v3 / DashboardContact.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 dashboard contacts.
14 *
15 * @package CiviCRM_APIv3
16 */
17
18 /**
19 * Creates/Updates a new Dashboard Contact Entry.
20 *
21 * @param array $params
22 *
23 * @return array
24 */
25 function civicrm_api3_dashboard_contact_create($params) {
26 if (empty($params['id'])) {
27 civicrm_api3_verify_one_mandatory($params,
28 NULL,
29 [
30 'dashboard_id',
31 ]
32 );
33 }
34 $errors = _civicrm_api3_dashboard_contact_check_params($params);
35 if ($errors !== NULL) {
36 return $errors;
37 }
38 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'DashboardContact');
39 }
40
41 /**
42 * Gets a CiviCRM Dashlets of Contacts according to parameters.
43 *
44 * @param array $params
45 * Array per getfields metadata.
46 *
47 * @return array
48 */
49 function civicrm_api3_dashboard_contact_get($params) {
50 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
51 }
52
53 /**
54 * Adjust Metadata for Create action.
55 *
56 * The metadata is used for setting defaults, documentation & validation.
57 *
58 * @param array $params
59 * Array of parameters determined by getfields.
60 */
61 function _civicrm_api3_dashboard_contact_create_spec(&$params) {
62 unset($params['version']);
63 }
64
65 /**
66 * Check permissions on contact dashboard retrieval.
67 *
68 * @param array $params
69 * Array per getfields metadata.
70 *
71 * @return array|null
72 */
73 function _civicrm_api3_dashboard_contact_check_params(&$params) {
74 $dashboard_id = CRM_Utils_Array::value('dashboard_id', $params);
75 if ($dashboard_id) {
76 $allDashlets = CRM_Core_BAO_Dashboard::getDashlets(TRUE, CRM_Utils_Array::value('check_permissions', $params, 0));
77 if (!isset($allDashlets[$dashboard_id])) {
78 return civicrm_api3_create_error('Invalid or inaccessible dashboard ID');
79 }
80 }
81 return NULL;
82 }
83
84 /**
85 * Delete an existing dashboard-contact.
86 *
87 * This method is used to delete any existing dashboard-board. the id of the dashboard-contact
88 * is required field in $params array
89 *
90 * @param array $params
91 *
92 * @return array
93 * @throws \API_Exception
94 */
95 function civicrm_api3_dashboard_contact_delete($params) {
96 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
97 }