3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 * This api exposes CiviCRM note.
15 * @package CiviCRM_APIv3
21 * This API is used for creating a note.
22 * Required parameters : entity_id AND note
24 * @param array $params
25 * An associative array of name/value property values of civicrm_note.
30 function civicrm_api3_note_create($params) {
31 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params, 'Note');
35 * Adjust Metadata for Create action.
37 * The metadata is used for setting defaults, documentation & validation.
39 * @param array $params
40 * Array of parameters determined by getfields.
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;
50 * Deletes an existing note.
52 * This API is used for deleting a note
54 * @param array $params
55 * Including id of the note to be deleted.
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');
65 * Retrieve a specific note or notes, given a set of input params.
67 * @param array $params
71 * array of properties,
72 * if error an array with an error id and error message
74 function civicrm_api3_note_get($params) {
75 return _civicrm_api3_basic_get('CRM_Core_BAO_Note', $params);
79 * Adjust Metadata for Get action.
81 * The metadata is used for setting defaults, documentation & validation.
83 * @param array $params
84 * Array of parameters determined by getfields.
86 function _civicrm_api3_note_get_spec(&$params) {
87 $params['entity_table']['api.default'] = "civicrm_contact";
91 * Get all descendants of given note.
93 * @param array $params
94 * array; only required 'id' parameter is used.
97 * Nested associative array beginning with direct children of given note.
99 function civicrm_api3_note_tree_get($params) {
100 civicrm_api3_verify_mandatory($params, NULL, ['id']);
102 if (!is_numeric($params['id'])) {
103 return civicrm_api3_create_error(ts("Invalid note ID"));
105 if (!isset($params['max_depth'])) {
106 $params['max_depth'] = 0;
108 if (!isset($params['snippet'])) {
109 $params['snippet'] = FALSE;
111 $noteTree = CRM_Core_BAO_Note
::getNoteTree($params['id'], $params['max_depth'], $params['snippet']);
112 return civicrm_api3_create_success($noteTree, $params);