Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
a30c801b | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 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 | | |
6a488035 TO |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
c28e1768 | 13 | * This api exposes CiviCRM note. |
6a488035 TO |
14 | * |
15 | * @package CiviCRM_APIv3 | |
6a488035 TO |
16 | */ |
17 | ||
6a488035 | 18 | /** |
61fe4988 | 19 | * Create Note. |
6a488035 TO |
20 | * |
21 | * This API is used for creating a note. | |
22 | * Required parameters : entity_id AND note | |
23 | * | |
cf470720 TO |
24 | * @param array $params |
25 | * An associative array of name/value property values of civicrm_note. | |
6a488035 | 26 | * |
a6c01b45 | 27 | * @return array |
72b3a70c | 28 | * API result array |
6a488035 TO |
29 | */ |
30 | function civicrm_api3_note_create($params) { | |
a25b46e9 | 31 | return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Note'); |
6a488035 | 32 | } |
11e09c59 TO |
33 | |
34 | /** | |
0aa0303c EM |
35 | * Adjust Metadata for Create action. |
36 | * | |
37 | * The metadata is used for setting defaults, documentation & validation. | |
1c88e578 | 38 | * |
cf470720 | 39 | * @param array $params |
b081365f | 40 | * Array of parameters determined by getfields. |
6a488035 TO |
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 | /** | |
22242c87 | 50 | * Deletes an existing note. |
6a488035 TO |
51 | * |
52 | * This API is used for deleting a note | |
53 | * | |
cf470720 TO |
54 | * @param array $params |
55 | * Including id of the note to be deleted. | |
6a488035 | 56 | * |
22242c87 | 57 | * @return array |
6a488035 TO |
58 | */ |
59 | function civicrm_api3_note_delete($params) { | |
6a488035 TO |
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 | /** | |
9d32e6f7 | 65 | * Retrieve a specific note or notes, given a set of input params. |
6a488035 | 66 | * |
cf470720 TO |
67 | * @param array $params |
68 | * Input parameters. | |
6a488035 | 69 | * |
a6c01b45 | 70 | * @return array |
72b3a70c | 71 | * array of properties, |
16b10e64 | 72 | * if error an array with an error id and error message |
6a488035 TO |
73 | */ |
74 | function civicrm_api3_note_get($params) { | |
6a488035 TO |
75 | return _civicrm_api3_basic_get('CRM_Core_BAO_Note', $params); |
76 | } | |
11e09c59 TO |
77 | |
78 | /** | |
22242c87 | 79 | * Adjust Metadata for Get action. |
1c88e578 | 80 | * |
0aa0303c EM |
81 | * The metadata is used for setting defaults, documentation & validation. |
82 | * | |
cf470720 | 83 | * @param array $params |
b081365f | 84 | * Array of parameters determined by getfields. |
6a488035 TO |
85 | */ |
86 | function _civicrm_api3_note_get_spec(&$params) { | |
87 | $params['entity_table']['api.default'] = "civicrm_contact"; | |
88 | } | |
89 | ||
90 | /** | |
22242c87 | 91 | * Get all descendants of given note. |
6a488035 | 92 | * |
cf470720 | 93 | * @param array $params |
22242c87 | 94 | * array; only required 'id' parameter is used. |
6a488035 | 95 | * |
a6c01b45 | 96 | * @return array |
72b3a70c | 97 | * Nested associative array beginning with direct children of given note. |
6a488035 | 98 | */ |
446e1c54 | 99 | function civicrm_api3_note_tree_get($params) { |
cf8f0fff | 100 | civicrm_api3_verify_mandatory($params, NULL, ['id']); |
6a488035 TO |
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 | } |