Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
1f4ea726 | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
c28e1768 | 29 | * This api exposes CiviCRM note. |
6a488035 TO |
30 | * |
31 | * @package CiviCRM_APIv3 | |
6a488035 TO |
32 | */ |
33 | ||
6a488035 | 34 | /** |
61fe4988 | 35 | * Create Note. |
6a488035 TO |
36 | * |
37 | * This API is used for creating a note. | |
38 | * Required parameters : entity_id AND note | |
39 | * | |
cf470720 TO |
40 | * @param array $params |
41 | * An associative array of name/value property values of civicrm_note. | |
6a488035 | 42 | * |
a6c01b45 | 43 | * @return array |
72b3a70c | 44 | * API result array |
6a488035 TO |
45 | */ |
46 | function civicrm_api3_note_create($params) { | |
5554f6f3 | 47 | return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
6a488035 | 48 | } |
11e09c59 TO |
49 | |
50 | /** | |
0aa0303c EM |
51 | * Adjust Metadata for Create action. |
52 | * | |
53 | * The metadata is used for setting defaults, documentation & validation. | |
1c88e578 | 54 | * |
cf470720 | 55 | * @param array $params |
b081365f | 56 | * Array of parameters determined by getfields. |
6a488035 TO |
57 | */ |
58 | function _civicrm_api3_note_create_spec(&$params) { | |
59 | $params['entity_table']['api.default'] = "civicrm_contact"; | |
60 | $params['modified_date']['api.default'] = "now"; | |
61 | $params['note']['api.required'] = 1; | |
62 | $params['entity_id']['api.required'] = 1; | |
63 | } | |
64 | ||
65 | /** | |
22242c87 | 66 | * Deletes an existing note. |
6a488035 TO |
67 | * |
68 | * This API is used for deleting a note | |
69 | * | |
cf470720 TO |
70 | * @param array $params |
71 | * Including id of the note to be deleted. | |
6a488035 | 72 | * |
22242c87 | 73 | * @return array |
6a488035 TO |
74 | */ |
75 | function civicrm_api3_note_delete($params) { | |
6a488035 TO |
76 | $result = new CRM_Core_BAO_Note(); |
77 | return $result->del($params['id']) ? civicrm_api3_create_success() : civicrm_api3_create_error('Error while deleting Note'); | |
78 | } | |
79 | ||
80 | /** | |
9d32e6f7 | 81 | * Retrieve a specific note or notes, given a set of input params. |
6a488035 | 82 | * |
cf470720 TO |
83 | * @param array $params |
84 | * Input parameters. | |
6a488035 | 85 | * |
a6c01b45 | 86 | * @return array |
72b3a70c | 87 | * array of properties, |
16b10e64 | 88 | * if error an array with an error id and error message |
6a488035 TO |
89 | */ |
90 | function civicrm_api3_note_get($params) { | |
6a488035 TO |
91 | return _civicrm_api3_basic_get('CRM_Core_BAO_Note', $params); |
92 | } | |
11e09c59 TO |
93 | |
94 | /** | |
22242c87 | 95 | * Adjust Metadata for Get action. |
1c88e578 | 96 | * |
0aa0303c EM |
97 | * The metadata is used for setting defaults, documentation & validation. |
98 | * | |
cf470720 | 99 | * @param array $params |
b081365f | 100 | * Array of parameters determined by getfields. |
6a488035 TO |
101 | */ |
102 | function _civicrm_api3_note_get_spec(&$params) { | |
103 | $params['entity_table']['api.default'] = "civicrm_contact"; | |
104 | } | |
105 | ||
106 | /** | |
22242c87 | 107 | * Get all descendants of given note. |
6a488035 | 108 | * |
cf470720 | 109 | * @param array $params |
22242c87 | 110 | * array; only required 'id' parameter is used. |
6a488035 | 111 | * |
a6c01b45 | 112 | * @return array |
72b3a70c | 113 | * Nested associative array beginning with direct children of given note. |
6a488035 | 114 | */ |
446e1c54 | 115 | function civicrm_api3_note_tree_get($params) { |
6a488035 TO |
116 | civicrm_api3_verify_mandatory($params, NULL, array('id')); |
117 | ||
118 | if (!is_numeric($params['id'])) { | |
119 | return civicrm_api3_create_error(ts("Invalid note ID")); | |
120 | } | |
121 | if (!isset($params['max_depth'])) { | |
122 | $params['max_depth'] = 0; | |
123 | } | |
124 | if (!isset($params['snippet'])) { | |
125 | $params['snippet'] = FALSE; | |
126 | } | |
127 | $noteTree = CRM_Core_BAO_Note::getNoteTree($params['id'], $params['max_depth'], $params['snippet']); | |
128 | return civicrm_api3_create_success($noteTree, $params); | |
129 | } |