Commit | Line | Data |
---|---|---|
15d9b3ae | 1 | <?php |
15d9b3ae N |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
a30c801b | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
15d9b3ae | 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 | | |
15d9b3ae | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
15d9b3ae N |
11 | |
12 | /** | |
c28e1768 | 13 | * This api exposes CiviCRM dashboard contacts. |
15d9b3ae N |
14 | * |
15 | * @package CiviCRM_APIv3 | |
15d9b3ae N |
16 | */ |
17 | ||
18 | /** | |
61fe4988 | 19 | * Creates/Updates a new Dashboard Contact Entry. |
15d9b3ae N |
20 | * |
21 | * @param array $params | |
22 | * | |
23 | * @return array | |
15d9b3ae N |
24 | */ |
25 | function civicrm_api3_dashboard_contact_create($params) { | |
dcf56200 TO |
26 | if (empty($params['id'])) { |
27 | civicrm_api3_verify_one_mandatory($params, | |
28 | NULL, | |
cf8f0fff | 29 | [ |
dcf56200 | 30 | 'dashboard_id', |
cf8f0fff | 31 | ] |
dcf56200 TO |
32 | ); |
33 | } | |
15d9b3ae | 34 | $errors = _civicrm_api3_dashboard_contact_check_params($params); |
dcf56200 TO |
35 | if ($errors !== NULL) { |
36 | return $errors; | |
37 | } | |
a25b46e9 | 38 | return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'DashboardContact'); |
15d9b3ae N |
39 | } |
40 | ||
41 | /** | |
2e66abf8 | 42 | * Gets a CiviCRM Dashlets of Contacts according to parameters. |
15d9b3ae | 43 | * |
cf470720 | 44 | * @param array $params |
2e66abf8 | 45 | * Array per getfields metadata. |
15d9b3ae N |
46 | * |
47 | * @return array | |
15d9b3ae N |
48 | */ |
49 | function civicrm_api3_dashboard_contact_get($params) { | |
dcf56200 | 50 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
15d9b3ae N |
51 | } |
52 | ||
53 | /** | |
0aa0303c EM |
54 | * Adjust Metadata for Create action. |
55 | * | |
56 | * The metadata is used for setting defaults, documentation & validation. | |
15d9b3ae | 57 | * |
cf470720 | 58 | * @param array $params |
b081365f | 59 | * Array of parameters determined by getfields. |
15d9b3ae N |
60 | */ |
61 | function _civicrm_api3_dashboard_contact_create_spec(&$params) { | |
62 | unset($params['version']); | |
63 | } | |
64 | ||
aa1b1481 | 65 | /** |
2e66abf8 EM |
66 | * Check permissions on contact dashboard retrieval. |
67 | * | |
c490a46a | 68 | * @param array $params |
2e66abf8 | 69 | * Array per getfields metadata. |
aa1b1481 EM |
70 | * |
71 | * @return array|null | |
72 | */ | |
15d9b3ae N |
73 | function _civicrm_api3_dashboard_contact_check_params(&$params) { |
74 | $dashboard_id = CRM_Utils_Array::value('dashboard_id', $params); | |
dcf56200 | 75 | if ($dashboard_id) { |
ee117e9c | 76 | $allDashlets = CRM_Core_BAO_Dashboard::getDashlets(TRUE, CRM_Utils_Array::value('check_permissions', $params, 0)); |
dcf56200 | 77 | if (!isset($allDashlets[$dashboard_id])) { |
ee117e9c | 78 | return civicrm_api3_create_error('Invalid or inaccessible dashboard ID'); |
dcf56200 | 79 | } |
15d9b3ae | 80 | } |
151da6c3 | 81 | return NULL; |
510513d8 TO |
82 | } |
83 | ||
84 | /** | |
dc64d047 | 85 | * Delete an existing dashboard-contact. |
510513d8 TO |
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 | * | |
d0997921 | 90 | * @param array $params |
dc64d047 | 91 | * |
645ee340 EM |
92 | * @return array |
93 | * @throws \API_Exception | |
510513d8 TO |
94 | */ |
95 | function civicrm_api3_dashboard_contact_delete($params) { | |
96 | return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
97 | } |