Afform - Fix setting default value
[civicrm-core.git] / api / v3 / Note.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 note.
14 *
15 * @package CiviCRM_APIv3
16 */
17
18 /**
19 * Create Note.
20 *
21 * This API is used for creating a note.
22 * Required parameters : entity_id AND note
23 *
24 * @param array $params
25 * An associative array of name/value property values of civicrm_note.
26 *
27 * @return array
28 * API result array
29 */
30 function civicrm_api3_note_create($params) {
31 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Note');
32 }
33
34 /**
35 * Adjust Metadata for Create action.
36 *
37 * The metadata is used for setting defaults, documentation & validation.
38 *
39 * @param array $params
40 * Array of parameters determined by getfields.
41 */
42 function _civicrm_api3_note_create_spec(&$params) {
43 $params['entity_table']['api.default'] = "civicrm_contact";
44 $params['modified_date']['api.default'] = "now";
45 $params['note']['api.required'] = 1;
46 $params['entity_id']['api.required'] = 1;
47 }
48
49 /**
50 * Deletes an existing note.
51 *
52 * This API is used for deleting a note
53 *
54 * @param array $params
55 * Including id of the note to be deleted.
56 *
57 * @return array
58 */
59 function civicrm_api3_note_delete($params) {
60 $result = new CRM_Core_BAO_Note();
61 return $result->del($params['id']) ? civicrm_api3_create_success() : civicrm_api3_create_error('Error while deleting Note');
62 }
63
64 /**
65 * Retrieve a specific note or notes, given a set of input params.
66 *
67 * @param array $params
68 * Input parameters.
69 *
70 * @return array
71 * array of properties,
72 * if error an array with an error id and error message
73 */
74 function civicrm_api3_note_get($params) {
75 return _civicrm_api3_basic_get('CRM_Core_BAO_Note', $params);
76 }
77
78 /**
79 * Adjust Metadata for Get action.
80 *
81 * The metadata is used for setting defaults, documentation & validation.
82 *
83 * @param array $params
84 * Array of parameters determined by getfields.
85 */
86 function _civicrm_api3_note_get_spec(&$params) {
87 $params['entity_table']['api.default'] = "civicrm_contact";
88 }
89
90 /**
91 * Get all descendants of given note.
92 *
93 * @param array $params
94 * array; only required 'id' parameter is used.
95 *
96 * @return array
97 * Nested associative array beginning with direct children of given note.
98 */
99 function civicrm_api3_note_tree_get($params) {
100 civicrm_api3_verify_mandatory($params, NULL, ['id']);
101
102 if (!is_numeric($params['id'])) {
103 return civicrm_api3_create_error(ts("Invalid note ID"));
104 }
105 if (!isset($params['max_depth'])) {
106 $params['max_depth'] = 0;
107 }
108 if (!isset($params['snippet'])) {
109 $params['snippet'] = FALSE;
110 }
111 $noteTree = CRM_Core_BAO_Note::getNoteTree($params['id'], $params['max_depth'], $params['snippet']);
112 return civicrm_api3_create_success($noteTree, $params);
113 }